CentOS6 – Networking Configuration
CentOS uses a number of different files for networking purposes - this post details the most widely used files for general networking operations.
Under CentOS v6 a new line is added into /etc/udev/rules.d/70-persistent-net.rules at boot-time for each new network adapter. This file contains amongst other things, the mac address and ethernet identifier of each network interface. You should check this file during debugging to ensure that an incorrect line doesn't exist. Simply removing the offending line and reboot the machine to re-write the file as necessary.
Each network interface has a file located within /etc/sysconfig/network-scripts/. It is named ifcfg-eth, followed by the identifier for the network interface (e.g. ifcfg-eth0; ifcfg-eth1). By default this file will not exist, unless networking has previously been set-up. The following examples detail the structure of the file for both DHCP and static networking types:
#DHCP Networking
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
#Static Networking
DEVICE="eth0"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.0.2"
NETMASK="255.255.255.0"
NETWORK="192.168.0.0"
BROADCAST="192.168.0.255"
GATEWAY="192.168.0.1"
If you do not require this network interface to act as the gateway, then ignore the relevant line from the example above.
Should multiple IP addresses be required upon a network adapter, then an additional file must be created for each address. This file will be named similarly to the standard configuration file for each adapter, but will extend the default properties for each adapter. The first additional address on network interface 0 will be configured within file ifcfg-eth0:0. The second additional address in ifcfg-eth0:1 and so-on. As these files extend the existing network interface's configuration, not all configuration options will be required - use only what is necessary for your configuration.
To name the machine, an edit must be performed in /etc/sysconfig/network:
NETWORKING="yes"
HOSTNAME="myserver"
To enable nameserver resolution, an edit must be performed in /etc/resolv.conf:
nameserver 192.168.0.1
nameserver 192.168.0.254
If you need to create default routes for your adapters, you need to add this content to /etc/sysconfig/network-scripts/route-[adapter_name] (e.g. route-eth0). A typical scenario might look like this, which enables communication from any machine inside 10.0.0.0 & 10.0.20.0 (netmask 255.255.240.0) through the 192.168.59.2 gateway.
ADDRESS0=10.0.0.0
NETMASK0=255.255.240.0
GATEWAY0=192.168.59.2
ADDRESS1=10.0.20.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.59.2
Each time a change is made to the networking configuration, the service must be restarted before changes will take effect. Issue a service network restart or /etc/init.d/network restart.
ifconfig can be used to examine current network settings - this will show details for each interface. Should you wish to display information only for one adapter, then add the adapter name to the end of the statement (e.g. ifconfig eth0).