HowTo Red Hat Enterprise Linux 5 Configure The Network Card

I have installed Red Hat enterprise Linux version 5.x server. Next, I added a brand new LAN card (NIC). I can see my second network card detected while booting the IBM server. How do I configure the network card from the command line?

Red hat Enterprise Linux version 5.x and 4.x provides the following tools to make changes to network configuration such as add new card, assign/change IP address/subnet/gateway, and change DNS server and more.

[a] GUI tool – system-config-network

[b] Command line text based GUI tool (No X Windows/Gnome/KDE required) – system-config-network

[c] Edit configuration files stored in /etc/sysconfig/network-scripts/ directory. This method works with remote server over the ssh based session.

The following instructions are tested and compatible with:

  1. Cent OS Linux v3/4/5.x.
  2. Fedora Core Linux (older version).
  3. Red Hat Enterprise Linux (RHEL) v3/4/5.x based server.

Note: If you are using Debian or Ubuntu Linux, please see this configuration guide for more information.

Method # 1: GUI tool system-config-network

Open the X terminal or login using ssh over X based session command (ssh -X [email protected]). Type the following command at shell prompt:

Warning: It is important that you configure network interface cards correctly over ssh -X based session; otherwise, you will be locked out due to wrong network configuration.

$ system-config-network &
Sample outputs:

Fig.01: Configuring the RHEL/CentOS server network card using GUI tool

You will see a Window as above. Next, select your Ethernet card (such as eth0 or eth1) and click on the Edit button. You can now setup/modify IP address, netmask, default gateway and other properties. Here is an example from my personal RHEL 5.x server:

Fig.02: Setting or modifying IPv4 and IPv6 properties on RHEL/CentOS based server

You can obtain IP address using DHCP or setup manually. Once IP address assigned, click on Ok button to save the changes. You can activate card by clicking on Activate button.

Method # 2: Command line tool system-config-network-tui

If you don’t have X windows GUI (gnome/kde desktop) installed on RHEL/CentOS/Fedora based system, than type the following command at shell prompt (this method also works on remote server using ssh based session):

Warning: It is important that you configure network interface cards correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.

# system-config-network-tui &
Sample outputs:

Fig.03: RHEL/CentOS command line network config tool (click to large)

Select your Ethernet card such as eth0 or eth1 and hit [Enter] or [F12] special key to configure IP properties for selected NIC:

Fig.04: Setting up IPv4 properties on RHEL/CentOS (click to large)

You can obtain an IP address using DHCP or setup IP address manually. Once an IP address assigned, click on the Ok button to save the changes.

Method #3: Edit configuration files stored in /etc/sysconfig/network-scripts/ directory

You can configure network card by editing text files stored in /etc/sysconfig/network-scripts/ directory. Open the terminal or login using ssh. Next, change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows using a text editor such as vi:

  • /etc/sysconfig/network-scripts/ifcfg-eth0 : First Ethernet card configuration file.
  • /etc/sysconfig/network-scripts/ifcfg-eth1 : Second Ethernet card configuration file.

Examples: Edit eth0 configuration file

To edit/create first NIC file, type the following command in /etc/sysconfig/network-scripts/ directory:

Warning: It is important that you configure network interface cards correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.

# vi ifcfg-eth0
OR
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Edit or modify as follows for static ip configuration:

# eth0 - Intel Corporation 82573E Gigabit Ethernet Controller (Copper) on server1.sxi.io by SXI LLC on 10/4/2007
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes

Save and close the file.

Setting up default gateway and server (host) name

You need to define a default gateway (router IP) and hostname in /etc/sysconfig/network file. Edit /etc/sysconfig/network, enter:
# vi /etc/sysconfig/network
Append or modify configuration as follows:

NETWORKING=yes
HOSTNAME=www1.nixcraft.in
GATEWAY=10.10.29.65

Save and close the file. Finally, you need to restart the network service, run:
# /etc/init.d/network restart
OR
# /sbin/service network restart

Setting up dns server

Make sure you have correct DNS server defined in /etc/resolv.conf file:
# vi /etc/resolv.conf
Setup DNS server IP address as follows (feel free to replace 10.0.80.11, 10.0.80.12 as per your setup):
nameserver 10.0.80.11
nameserver 10.0.80.12
nameserver 202.67.222.222

Save and close the file. Now you can ping the gateway/other hosts using the ping command:
$ ping 10.0.80.12
Sample outputs:

PING 10.0.80.12 (10.0.80.12) 56(84) bytes of data.
64 bytes from 10.0.80.12: icmp_seq=1 ttl=251 time=0.972 ms
64 bytes from 10.0.80.12: icmp_seq=2 ttl=251 time=1.11 ms

You can also check for Internet connectivity with the ping, nslookup and/or host command:
$ nslookup sxi.io
Sample outputs:

Server:         10.0.80.11
Address:        10.0.80.11#53

Non-authoritative answer:
Name:   sxi.io
Address: 75.126.43.232

You can also use host dns lookup command as follows:
$ host nixcraft.in
Sample outputs:

nixcraft.in has address 75.126.43.232
nixcraft.in mail is handled by 10 mail.nixcraft.in.

How do I see or debug network configuration on RHEL/CentOS based server?

Simply use any one of the following commands:

###########################
## display ip config     ##
###########################
ifconfig
ifconfig -a | more
ifconfig eth0
ifconfig eth1
ip link 
ip addr
 
###########################
## display routing table ##
###########################
route 
route -nr
route -nr|more
ip route 
 
###########################
## display dns config    ##
###########################
cat /etc/resolv.conf
 
###########################
## display firewall config#
###########################
iptables -L -n -v | more
cat /etc/sysconfig/iptables
 
###########################
## Debug network issues   #
###########################
ping host-name-here
ping ip-addeess-here
host ip-address-here
host domain-name-here
traceroute host-name-here
mtr host-name-here
dmesg | grep eth
lspci  | grep -i eth
See also

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.