CentOS Networking Basics

March 2014

CentOS Dedicated Server

In 5 minutes, we’ll cover the basics of configuring and diagnosing the network within CentOS using the command line. It’s highly recommended that you work from either the console or KVM so that you still have access to the interface in case of a loss of connectivity due to an incorrect configuration.

Viewing the Existing IP Configuration

ifconfig – Displays the IP configuration for all active network adapters. 
ifconfig [eth]
– Displays the IP configuration for a specific network adapter. Replace [eth] with the specific ethernet adapter name.
ifconfig -a – Displays the IP configuration for all active and inactive (installed) adapters on the system.
ethtool [eth] – Displays detailed information about the NIC, things like whether it has a link and what sort of duplex the link is connected at. Replace [eth] with the specific ethernet adapter name.

Starting/Stopping/Restarting Network Interfaces

ifdown [eth] – Disable an ethernet adapter. (Replace [eth] with the ethernet adapter ex. eth1)
ifup [eth] – Enable an ethernet adapter. (Replace [eth] with the ethernet adapter ex. eth1)
service network restart – Restart the network service, required after any network changes for the updated settings to take effect.

Configuration

Another step is to view the configuration. CentOS stores its network configuration in the /etc/sysconfig/network-scripts folder.

The files will be labeled in the following format:
ifcfg-eth#[:#] (where # is the ethernet adapter and [:#] is for additional IP configurations for the ethernet adapter).

These files can be edited with vi to modify the configuration within. Remember to restart the network service after editing a network configuration for the changes to take effect.

Adding additional IPs to an Ethernet adapter

To add an additional IP to an ethernet adapter, create a new file in the /etc/sysconfig/network-scripts named ifcfg-eth#:## (where # is the ethernet adapter and ## is incremented by 1, if no other files exist in this format, start this off with a 1, ex. ifcfg-eth1:1). Once the file has been created, add the contents in the following format:

DEVICE=eth0:1
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.1.1.2
NETMASK=255.255.255.0

Save the file and restart the network interface.

Adding a range of IPs to an ethernet adapter

Often times you will need to add an entire range of IPs instead of a single IP. To add a range of IPs to an ethernet adapter, create a new file in the /etc/sysconfig/network-scripts named ifcfg-eth#-range## (where # is the ethernet adapter and ## is incremented by 1, if no other files exist in thie format, start this off with a 1, ex. ifcfg-eth1-range1). Once the file has been created, add the contents in the following format:

PADDR_START=192.168.0.10
IPADDR_END=192.168.0.110
CLONENUM_START=0

The PADDR_START value is the first IP address in the range, this IP address should be used in any other configuration files. The IPADDR_END is the last IP address in the range. The CLONENUM_START value defines where the alias will start.  If this is the second range file, you will need to set CLONENUM_START to a value higher than the number of IP addresses assigned.  To check what you currently have used, you can run ifconfig –a | grep eth1.  This will list devices such as eth1:0, eth1:1, eth1:2, and so on.  If you are currently using upto eth1:13, you will need to set CLONENUM_START to 14 to assign the IPs correctly.

Save the file and restart the network interface.

You should now have a general understanding of how to configure the network adapters inCentOS!