Networking in Linux

One can’t stay forever in an isolated World, and same applies for server as well. In order to communicate with another server in same network, one need it’s Fully Qualified domain name (FQDN) or IP address. So let’s focus here on how to enable our Network Adapter (Physical or Virtual) to communicate with other machines by setting an IP over it.

Any available NIC where IP’s are not assigned can be easily viewed under below command: (here eth1)

page1

NOTE: Sometimes an environment can have bonding configured or NIC acting as fail over NIC (act as LB), so there is possibility that IP is not assigned on that NIC. So make sure the NIC you choose is free for use.

Method 1: By ifconfig command line:

# ifconfig eth1 192.168.154.23 netmask 255.255.255.0

space2

Method 2: By interface files

Above method is simple, but having drawback that IP is not configured permanently and will be wiped out on reboot. In order to make it permanent, we need to add it under configuration files with NIC names (ifcfg-ethXX) created under /etc/sysconfig/network-scripts/ directory.

space3

Line1: DEVICE=name: name is the name of the physical device

Line2: HWADDR=MAC-address: hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF

Line3: Type of NIC card

Line4: NM_CONTROLLED=answer: whether NetworkManager is permitted to configure this device

Line5: BOOTPROTO=protocol: Booting protocol, other values can be bootp & dhcp as well.

Line6: IPADDRn=address: where address is the IPv4 address and the n is expected to be consecutive positive integers starting from 0 

Line7: NETMASKn=mask: where mask is the netmask value and the n is expected to be consecutive positive integers starting from 0

Line8: Gateway used to communicate with external world

More details about these parameters can be found at https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html

Once the file is created correctly, one can activate that NIC card with below commands:

# ifup eth1

space4

Subsequently one can bring it down using # ifdown

OR 

# service network restart

NOTE: Be careful while using ‘service network restart’ as it will diconnect all active connection rather than resetting current NIC only.

Now the NIC will be up with IP address even after reboot.

Method 3: Graphical Method

(a) In RHEL /CentOS 5, 6 – setup utility

Follow below steps:

# setup > Network configuration > Device configuration > New Device > Ethernet > Add

space5

Ok > Save > Save & Quit > Quit

Though device is created here by above steps & configuration file also created, but device is not active by default. To activate it use “ifup eth1” command as used previously.

(b) In RHEL /CentOS 7 – nmtui NetworkManager utility

In RHEL 7 default naming schema of NIC card is followed as enoXXX rather than ethXX.

nmtui > Edit a connection > enoxxx > Fill details like below

space6

Ok > Quit.

This too has created configuration file : /etc/sysconfig/network-scripts/ifcfg-eno33554992

But NIC is not activated by default, to activate it,use below :

# ifup eno33554992 

OR

# systemctl status NetworkManager.service

Now ending this blog with small video at end , and small introduction of plumbing more than one IP over a network card / VIP concept.

Do share your feedback and comments on this.

Leave a comment