How to configure network in Red Hat Linux

In my last article I had shared the steps and instructions to configure NIC bonding and teaming in Red Hat Linux using various bonding types like MII, ARP etc

Configuring network in Red Hat Linux can be hectic and confusing if you don't know the parameter details which are used. Also from Red Hat 6 the configuration parameter has been changed for network-config. Let me show you out the steps to do the same along with some possible explanation.

The Interface device which controls the network of your Linux machine is mostly eth0 which is the default NIC interface in the system.
There can be multiple NIC in your system which might be denoted as eth1, eth2 and so on.

The configuration files used for complete network configuration in Red Hat 6 are
/etc/sysconfig/network-scripts/ifcfg-eth0 (can vary as per the NIC present)
/etc/nsswitch.conf
/etc/resolv.conf

Command Line configuration

Step 1 : 

Here below is a sample file configuration for ifcfg-eth0

# less /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=73:25:N4:2E:8C:46
TYPE=Ethernet
UUID=ca73df13-5553-4631-bfb4-9244f5e29190
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=10.10.20.55
DNS1=8.8.8.8
GATEWAY=10.10.20.100
NETMASK=255.255.255.0
BOOTPROTO=none
USERCTL=no
PEERDNS=yes

Now let me just explain theese configuration parameters
DEVICE = name
name : It is the name of the physical device
HWADDR = MAC-Address
MAC-Address : It is the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF. This directive must be used in machines containing more than one NIC to ensure that the interfaces are assigned the correct device names regardless of the configured load order for each NIC's module.
TYPE = device
device : Mention if the NIC device you are connecting is Ethernet or Wifi device
UUID = xx-xx-xx
This is used by the Network Manager and is self generated so in case you are not using Network Manager this field is not required. Do not manually edit this line
ONBOOT = answer
where answer can be one of the following

  • yes — This device should be activated at boot-time.
  • no — This device should not be activated at boot-time.

NM_CONTROLLED = answer

where answer is one of the following:

  • yes — NetworkManager is permitted to configure this device.This is the default behavior and can be omitted.
  • no — NetworkManager is not permitted to configure this device.

IPADDR = IPv4 address
 Give the IPv4 address of your system
DNS1 = nameserver
nameserver :  where address is a name server address to be placed in /etc/resolv.conf if the PEERDNS directive is set to yes
GATEWAY = address
address : Give the gateway address of your network
NETMASK = address
address : Give the netmask address of your network
BOOTPROTO = protocol
where protocol is one of the following:

  • none — No boot-time protocol should be used.
  • bootp — The BOOTP protocol should be used.
  • dhcp — The DHCP protocol should be used.
USERCTL = answer

where answer is one of the following:

  • yes — Non-root users are allowed to control this device. 
  • no — Non-root users are not allowed to control this device.
PEERDNS = answer
where answer is one of the following:

  • yes — Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default.
  • no — Do not modify /etc/resolv.conf.
Step 2:
Configure /etc/resolv.conf

In case you have used directive no for the parameter PEERDNS then you will have to manually update your resolv.conf file.

# vi /etc/resolv.conf
nameserver 8.8.8.8

Step 3:
Configure /etc/nsswitch.conf
#hosts:     db files nisplus nis dns
hosts:      files dns

Start your network services
# service network restart
or
# /etc/init.d/network restart
To check the ip details of your machine
# ifconfig
eth0    Link encap:Ethernet  HWaddr 73:25:N4:2E:8C:46
          inet addr:10.10.20.55  Bcast:10.10.20.255  Mask:255.255.255.0
          inet6 addr: fe20::7a35:c4gf:fe2e:8c46/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:642049 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28185 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:74176258 (70.7 MiB)  TX bytes:6418581 (6.1 MiB)

GUI configuration 

GUI configuration can be done either on command line as well as on the GNOME or KDE desktop.

Make sure the following package is installed
# rpm -qa | grep system-config-network
system-config-network-tui-1.6.0.el6.2-1.el6.noarch
# system-config-network
Follow the screenshots (Click on the image for clear view)

Hit Enter on "Device Configuration"

 Select the device and hit Enter

Fill up the required details as shown below and click on OK

Once you click on OK you will reach on the first page of action. Select DNS Configuration and hit enter

Fill up the required details as shown below and hit Enter

Once you have filled up all detail move the cursor to Save and Quit and Hit Enter

Restart your network to make the change affect
# service network restart
or
# /etc/init.d/network restart