jump to navigation

Configuring network interface card via terminal on CentOs 5.x January 17, 2011

Posted by Tournas Dimitrios in Linux.

Under Red Hat based Linux distributions, all network configuration files are located in the well known /etc/*  directory . Even the scripts used to activate and deactivate the network interfaces are also located here . actually these scripts are symbolic links to the /sbin/ directory , but for legitimate reasons they are kept here .Probably in the future they will be removed from this directory .
During the activation / deactivation phase of the network cards , lot of interface files are involved so that the process is under control .Although the number and type of interface files can differ from system to system, there are three categories of files that exist in this directory:

  1. Interface configuration files
  2. Interface control scripts
  3. Network function files

The files in each of these categories work together to enable various network devices.This article explores the relationship between these files and how they are configured . Just for completeness , at the end of the article , I ‘ll outline two gui alternatives  for configuring the NIC’s on a Linux box .

Network Configuration Files

The primary network configuration files are as follows:

  • /etc/hosts :  The main purpose of this file is to resolve hostnames that cannot be resolved any other way. It can also be used to resolve hostnames on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device ( as localhost.localdomain. For more information, refer to the hosts man page.
  • /etc/resolv.conf : This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file. For more information about this file, refer to the resolv.conf man page.
  • /etc/sysconfig/network : This file specifies routing and host information for all network interfaces .By default, it contains the following options:
    • NETWORKING=yes :A boolean to enable (yes) or disable (no) the networking.
    • HOSTNAME=newserver.example.com
    • GATEWAY= The IP address of the network’s gateway
  • /etc/sysconfig/network-scripts/ifcfg-ethx : For each network interface, there is a corresponding interface configuration script. Each of these files provide information specific to a particular network interface .One of the most common interface files is ifcfg-eth0, which controls the first Ethernet network interface card or NIC in the system. In a system with multiple NICs, there are multiple ifcfg-eth files (where is a unique number corresponding to a specific interface). Because each device has its own configuration file, an administrator can control how each interface functions individually.
    The following is a sample ifcfg-eth0 file for a system using a fixed IP address: 

    • DEVICE=eth0
    • BOOTPROTO=none
    • ONBOOT=yes
    • NETMASK=
    • IPADDR=1920.168.1.55
    • USERCTL=no

    The values required in an interface configuration file can change based on other values. For example, the ifcfg-eth0 file for an interface using DHCP looks different because IP information is provided by the DHCP server:

    • DEVICE=eth0
    • BOOTPROTO=dhcp
    • ONBOOT=yes

Interface Control Scripts

The interface control scripts activate and deactivate system interfaces. There are two primary interface control scripts that call on control scripts located in the /etc/sysconfig/network-scripts/ directory: /sbin/ifdown and /sbin/ifup.
The ifup and ifdown interface scripts are symbolic links to scripts in the /sbin/ directory. When either of these scripts are called, they require the value of the interface to be specified, such as:  ifup eth0

Network Function Files

Linux makes use of several files that contain important common functions used to bring interfaces up and down. Rather than forcing each interface control file to contain these functions, they are grouped together in a few files that are called upon when necessary.
The /etc/sysconfig/network-scripts/network-functions file contains the most commonly used IPv4 functions, which are useful to many interface control scripts. These functions include contacting running programs that have requested information about changes in the status of an interface, setting hostnames, finding a gateway device, verifying whether or not a particular device is down, and adding a default route.
As the functions required for IPv6 interfaces are different from IPv4 interfaces, a /etc/sysconfig/network-scripts/network-functions-ipv6 file exists specifically to hold this information. The functions in this file configure and delete static IPv6 routes, create and remove tunnels, add and remove IPv6 addresses to an interface, and test for the existence of an IPv6 address on an interface.

Network configuration with the graphical interfaces (Gui) :

Two graphical interfaces are available on Redhad based distro’s , call them from the terminal :

  • system-config-network
  • system-config-network-tui

Warning !!!!

The /etc/sysconfig/networking/ directory is used by the Network Administration Tool (system-config-network) and its contents should not be edited manually. Using only one method for network configuration is strongly encouraged, due to the risk of configuration deletion.

Resources :

  • /usr/share/doc/initscripts-<version>/sysconfig.txt : A guide to available options for network configuration files .
  • /usr/share/doc/iproute-<version>/ip-cref.ps : This file contains a wealth of information about the ip command, which can be used to manipulate most of the network configuration files .


1. Alexandria - December 21, 2012

I really like it whenever people come together and share views.
Great site, stick with it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s