Configuring network interface card via terminal on CentOs 5.x January 17, 2011Posted 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:
- Interface configuration files
- Interface control scripts
- 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 (127.0.0.1) 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.
- GATEWAY=192.168.1.1 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:
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:
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 :
|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.|
- /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 .