Skip to main content

Linux Network Configuration


This tutorials shows how to set up network and configure network parameters from command line interface on Linux systems. Since one should not have hard time configuring it from graphical user interface (few mouse clicks once You find the right tool) this tutorial will orient on configuration from cli. Also notice that various linux systems have slightly different configuration methods. 


To determine Your Network interface card (NIC), You can use ifconfig command. Most of todays systems will mark Your NICs as devices eth0, eth1 and so on... depending on how many phisical interfaces (NICs) You have installed in your server. 

We can use ifconfig to list installed NIC-s: 


LinuxBox# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:07:C2:10:64:A2 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:11 Base address:0x1820 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:787 errors:0 dropped:0 overruns:0 frame:0 TX packets:787 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:82544 (80.6 Kb) TX bytes:82644 (80.6 Kb) LinuxBox#

Ifconfig command is also used to bring NIC up or down and to assign network parameters like ip
address and subnetmask: 

LinuxBox# ifconfig eth0 192.168.13.10 netmask 255.255.255.0 up

Route command is usually used to configure static routing and to populate routing-tables, but we can also use it to setup default gateway. Computers and devices can directly communicate with each other if they are located in the same subnet. However, if computer from one subnet tries to send a packet to device in another subnet, computer first has to send data to it's default gateway which than forwards the packets to it's destination. 

To setup a default gateway address to 192.168.1.1 for the interface eth0 on a Linux machine, we can use this command: 

LinuxBox# route add default gw 192.168.1.1 eth0

However, configuring the network with ifconfig and route commands is not permanent. Address assigned this way will not be saved if system reboots, or tcp/ip stack restarts. To assign static ip address to a interface permanently, You have to edit file /etc/network/interfaces

LinuxBox# vi /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.13.10 netmask 255.255.255.0 broadcast 255.255.255.255 network 192.168.13.0 gateway 192.168.13.1

After successfuly editing and saving /etc/network/interfaces, You have to restart tcp/ip stack so changes can take effect. 

Network can be restarted with: 

LinuxBox# /etc/init.d/networking restart * Reconfiguring network interfaces... Interface eth1 is up. [ OK ]

Another look on ifconfig shows that network is now configured properly: 

LinuxBox# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:07:C2:10:64:A2 inet addr:192.168.13.10 Bcast:192.168.13.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:11 Base address:0x1820 LinuxBox#


To setup the addresses of a DNS servers, edit the file /etc/resolv.conf.
For example to setup the DNS server address of a Google's DNS server, add the line nameserver after which folows the ip address of the DNS server: 

LinuxBox# vi /etc/resolv.conf domain ittutorials.org search ittutorials.org nameserver 4.2.2.2 nameserver 8.8.8.8 LinuxBox#
(Lines "domain" and "search" specifies local domain name, so for example if You query DNS for www, it will automaticaly match www.ittutorials.org) 

If want to setup DHCP on NIC, content of /etc/network/interfaces has to be replaced with these lines: 

LinuxBox# vi /etc/network/interfaces auto eth0 iface eth0 inet dhcp LinuxBox#

After configuring network parameters, TCP/IP stack has to be restarted: 

LinuxBox# /etc/init.d/networking restart * Reconfiguring network interfaces... Interface eth1 is up. [ OK ] LinuxBox#


Linux (Debian) network configuration (from CLI):
Red Hat / Fedora network configuration
Configuration of network on Red Hat based systems (example Fedora) is done by editing few configuration files stored in /etc/sysconfig/network-scripts/ directory. Based on the interface we want to configure, we can edit or create (if the files don't exists) interface files. 

For first network card, we can create /etc/sysconfig/network-scripts/ifcfg-eth0, for second NIC we would create /etc/sysconfig/network-scripts/ifcfg-eth1 and so on... 

LinuxBox# cd /etc/sysconfig/network-scripts/ LinuxBox# vi ifcfg-eth0 # 1st network interface DEVICE=eth0 BOOTPROTO=static DHCPCLASS= HWADDR=00:30:45:56:B6:2A IPADDR=192.168.10.15 NETMASK=255.255.255.0 ONBOOT=yes

In /etc/sysconfig/network we can setup default gateway (router IP) and hostname: 

LinuxBox# vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=LinuxBox.ittutorials.org GATEWAY=192.168.10.1

After successful saving the files, we have to restart networking: 

LinuxBox# /etc/init.d/network restart restart * Reconfiguring network interfaces... Interface eth0 is up. [ OK ]

Comments

Popular posts from this blog

Cisco three-layer hierarchical model

Because networks can be extremely complicated, with multiple protocols and diverse technologies, Cisco has developed a layered hierarchical model for designing a reliable network infrastructure. This three-layer model helps you design, implement, and maintain a scalable

Access Control Lists (extended)

Access Control List  or  ACL  is a technic of controling network traffic. It is a list of rules with which traffic flow can be manipulated - permitted or denied. By default, traffic flow from the interface with the higher security level (for example "inside" interface) to interface with the lower security level (example "outside" interface) is allowed by default, but the flow of traffic from "outside" to the "inside" interface must be explicitly permited. 

Classes of IP addresses

TCP/IP defines five classes of IP addresses: class A, B, C, D, and E. Each class has a range of valid IP addresses. The value of the first octet determines the class. IP addresses