The Linux operation system is mainly used in kinds of servers, in Internet, that allow the general users to access web pages and the administrators to administrate them in remote, for which network configuration is particularly important. Before exploring how to configure network on Linux, a great amount of fundamental knowledge of Computer Networks is required and will be introduced first in this essay. I highly recommend you the book, Computer Networking: A Top-Down Approach, which explores the computer networks far more detail and is also easy to understand.
1. Fundamental knowledge of Computer Network
For those who have already studied Computer Networks, there are several links, helping you to review, which are optional.
a. Network Topology
The bus topology, ring topology and star topology are three most common topologies applied in computer networks.
Carrier Sense Multiple Access with Collision Detection (CSMA/CD) is a media access control method used in the bus network, which ensures each host connected to the bus network to transmission correctly. Thus, a link for CSMA/CD is provided bellow.
https://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection
b. Hub, Bridge, Switch and Router
Those are key physical devices, needed in Network infrastructures, in which multiple protocols defined in several layers of OSI model are supported.
http://www.cisco1900router.com/tutorial-of-differences-between-hub-bridge-switch-and-router.html
c. MAC addr, IP addr, Port & Socket
The MAC addr, also called physical addr, is a unique identifier assigned to network interfaces which are physical devices implementing computers' networking function. The MAC addr is used in local network for transmission among hosts. However, it's not a serviceable solution for transmission among several local networks or in a large network. Because it would cause broadcast storm which could make the entire network unavailable at all. Therefore, The IP addr, also called logical addr, is created to solve this problem. Each IP addr is divided into two parts, network addr and host addr, by and operation with netmask. Port is actually the address of processes running on a operation system. Socket is the combination of an IP addr and a port number.
https://en.wikipedia.org/wiki/MAC_address
https://en.wikipedia.org/wiki/IP_address
http://www.computerhope.com/jargon/n/netmask.htm
d. Routing
Routing is the process of selecting the best paths which take the lest time for hosts to transmit between two hosts in a network, which could base on the shortest distance strategy or the idlest path strategy. It's the essential part of the Computer Network and hard to explain in a short time. A comprehensive and detailed textbook, like Computer Networking: A Top-Down Approach, can be helpful.
e. TCP & UDP
TCP and UDP are two protocols that defined in the transport layer of OSI model. TCP provides a reliable but slower connection between two hosts, in which the three-way-handshake is involved. However, UDP provides a unreliable but faster connection between two hosts.
https://en.wikibooks.org/wiki/Communication_Networks/TCP_and_UDP_Protocols
http://www.tcpipguide.com/free/t_TCPConnectionEstablishmentProcessTheThreeWayHandsh-3.htm
2. Network Configuration on Linux
What a normal host accessing to the Internet requires to configure ahead are generally IP, Netmask, Gateway, Hostname, DNS and Routing information, which can be statically assigned by administrator or automatically configured by DHCP (Dynamic Host Configuration Protocol). It's important for us to keep in mind that the network function of Linux is defined in it's kernel. Thus, the IP addr don't belong to the network interface but is owned by the kernel.
/*All configuration implemented by command is real time but temporary. Wanting a persistent change, you should edit the configuration files.*/
a. ifconfig
Print all information of all network interfaces or a specific one in your host.
# ifconfig -a
# ifconfig INTERFACE_NAME
Change the IP addr and Masknet of the network interface whose alias is eth0.
# ifconfig INTERFACE_NAME IP/MASK
Turn on or turn off the network interface whose alias is eth0.
# ifconfig INTERFACE_NAME [up|down]
b. Start, Stop, Restart the network or Check its status
# /etc/init.d/network [start|stop|restart|status]
c. route
Print all record-routes.
# route
Add a record-route which suggests that a packet heading for a specific net/host should be transmit to next hop.
# route add -net|-host DEST gw NEXTHOP
Delete a specific record-route.
# route del -net|-host DEST
Show numerical address instead of it's symbolic hostname.
# route -n
d. Network configuration file & Its interfaces configuration files
# cat /etc/sysconfig/network
# cat /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME
e. Routing configuration file
# cat /etc/sysconfig/network-scripts/route-INTERFACE_NAME
f. DNS configuration file
Configure DNS server.
# cat /etc/resolv.conf
Configure domain name resolution in local.
# cat /etc/hosts
format: IP hostname alias
g. ip
Display devices' attributes of all network interfaces or a specific one in your host.
# ip [-s] link show [INTERFACE_NAME]
Turn on or turn off the network interface whose alias is eth0.
# ip link set INTERFACE_NAME [up|down]
Add a new IP addr to a specific network interface and give it an alias.
# ip addr add IP_ADDRESS dev DEV [label ALIAS]
Delete a IP addr from a specific network interface.
# ip addr del IP_ADDRESS dev DEV
Display IP addrs, of all network interfaces or a specific one in your host, which begin with prefix PREFIX.
# ip addr show dev INTERFACE_NAME to PREFIX
Delete IP addrs, of all network interfaces or a specific one in your host, which begin with prefix PREFIX.
# ip flush dev DEV to PREFIX
Reference:
[1] Linux.die.net, (2015).ifconfig(8): configure network interface - Linux man page. [online] Available at: http://linux.die.net/man/8/ifconfig [Accessed 16 Oct. 2015].
[2] Linux.die.net, (2015).ip(8) - Linux man page. [online] Available at: http://linux.die.net/man/8/ip [Accessed 16 Oct. 2015].
[3] Linux.die.net, (2015).route(8): show/change IP routing table - Linux man page. [online] Available at: http://linux.die.net/man/8/route [Accessed 16 Oct. 2015].