i Linux networking-inteface configuration – All things in moderation

Linux networking-inteface configuration

Debian nic configuration

/etc/network/interfaces

The /etc/network/interface/ file is a core network interface card configuration file on debian

dhcp client

The screenshot below shows that our computer is configured for dhcp on eth0

[email protected]:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp  

Configuring network cards for dhcp is good practice for clients, but servers usually require a fixed ip address

fixed ip

[email protected]~# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address
10.42.189.198
broadcast 10.42.189.207
netmask
255.255.255.240
gateway
10.42.189.193

The screenshot above shows /etc/network/interfaces configured with a fixed ip address.

/sbin/ifdown

It is adviced(but not mandatory) to down an interface changing its configuration. This can be done with the ifdown commnand.

The command will not give any output when downing an interface with a fixed ip address. However ifconfig will no longer show the interface.

[email protected]:~# ifdown eth0
[email protected]:~# ifconfig
lo
Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:106 errors:0 dropped:0 overruns:0 frame:0
TX packets:106 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11162 (11.1 KB) TX bytes:11162 (11.1 KB)

/sbin/ifup/

Below a screenshot of ifup bringing the eth0 ethernet interface up using dhcp.

[email protected]:/etc/network# ifup eth0
Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/08:00:27:cd:7f:fc
Sending on
LPF/eth0/08:00:27:cd:7f:fc
Sending on
Socket/fallback
DHCPREQUEST of 192.168.1.34 on eth0 to 255.255.255.255 port 67
DHCPNAK from 192.168.33.100
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
DHCPOFFER of 192.168.33.77 from 192.168.33.100
DHCPREQUEST of 192.168.33.77 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.33.77 from 192.168.33.100
bound to 192.168.33.77 -- renewal in 95 seconds.
ssh stop/waiting
ssh start/running, process 1301
[email protected]:/etc/network#

RHEL nic configuration

/etc/sysconfig/network

The /etc/sysconfig/network file is a global (across all network cards) configuration file.
It allows us to define whether we want networking (NETWORKING=yes|no), what the
hostname should be (HOSTNAME=) and which gateway to use (GATEWAY=).

[[email protected] ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6
GATEWAY=192.168.1.1  

Note that this contains no settings at all in a default RHEL7 install(with networking enabled)

[[email protected] ~]# cat /etc/sysconfig/network
# Created by anaconda

/etc/sysconfig/network-scripts/ifcfg-

Each network card can be configured individually using the /etc/sysconfig/network-scripts/
ifcfg-
* files. When you have only one network card, then this will probably be /etc/
sysconfig/network-scripts/ifcfg-eth0.

dhcp client

Below a screenshot of /etc/sysconfig/network-scripts/ifcfg-eth0 configured for dhcp
(BOOTPROTO=”dhcp”). Note also the NM_CONTROLLED paramater to disable control
of this nic by Network Manager. This parameter is not explained (not even mentioned) in
/usr/share/doc/initscripts-*/sysconfig.txt, but many others are.

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="08:00:27:DD:0D:5C"
NM_CONTROLLED="no"
BOOTPROTO="dhcp"
ONBOOT="yes"  

fixed ip

Below a screenshot of a fixed ip configuration in /etc/sysconfig/network-scripts/ifcfg-
eth0.

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="08:00:27:DD:0D:5C"
NM_CONTROLLED="no"
BOOTPROTO="none"
IPADDR="192.168.1.99"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
ONBOOT="yes"  

/sbin/ifup and /sbin/ifdown

The ifup and ifdown commands will set an interface up or down, using the configuration
discussed above. This is identical to their behaviour in Debian and Ubuntu.

ifconfig

The use of /sbin/ifconfig with out any arguments will present you with a list of all active network interface cards, including wireless and the loopback interface. In the screenshot below ehh0 has no ip address.

[email protected]:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:26:bb:5d:2e:52
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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:43 Base address:0xe000
eth1 Link encap:Ethernet HWaddr 00:26:bb:12:7a:5e
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::226:bbff:fe12:7a5e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11141791 errors:202 dropped:0 overruns:0 frame:11580126
TX packets:6473056 errors:3860 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3476531617 (3.4 GB) TX bytes:2114919475 (2.1 GB)
Interrupt:23
lo
Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2879 errors:0 dropped:0 overruns:0 frame:0
TX packets:2879 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:486510 (486.5 KB) TX bytes:486510 (486.5 KB)

You can also use ifconfig to obtain information about just one network card.

[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:DD:0D:5C
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedd:d5c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2969 errors:0 dropped:0 overruns:0 frame:0
TX packets:1918 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000

Up and down

You can also use ifconfig to bring an interface up or down. The difference with ifup is that
ifconfig eth0 up will re-activate the nic keeping its existing (current) configuration, whereas
ifup will read the correct file that contains a (possibly new) configuration and use this config
file to bring the interface up.

Setting ip address

You can temporary set an ip address with ifconfig. This ip address is only valid until the
next ifup/ifdown cycle or until the next reboot.

[[email protected] ~]# ifconfig eth0 | grep 192
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0
[[email protected] ~]# ifconfig eth0 192.168.33.42 netmask 255.255.0.0
[[email protected] ~]# ifconfig eth0 | grep 192
inet addr:192.168.33.42 Bcast:192.168.255.255 Mask:255.255.0.0
[[email protected] ~]# ifdown eth0 && ifup eth0
[[email protected] ~]# ifconfig eth0 | grep 192
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0  

Conclusion

This post is about common commands for interface configuration in linux networking. There are many things about linux networking like iptables, dhcp, dns, etc. But, first of all these commands above is very basic for everyone want to work with linux networking.

Leave a Reply