Adding and viewing IP addresses on CentOS servers

0 82

To add newly assigned IP addresses from SSH, follow this procedure:

(Please follow the steps given below only on a Centos / Fedora.)

  • Login to your server with SSH as root.
  • Go to the /etc/sysconfig/network-scripts directory.
cd  /etc/sysconfig/network-scripts/
  • Verify which interface you will use to add IP addresses. Typically, this will be eth0 for public IP addresses.

/sbin/ifconfig

This will produce output similar to the following:

  • Make a copy of ifcfg-eth0 for each IP you wish to add and name them as ifcfg-eth0:0, ifcfg-eth0:1 etc.
cp ifcfg-eth0 ifcfg-eth0:0 
cp ifcfg-eth0 ifcfg-eth0:1 
cp ifcfg-eth0 ifcfg-eth0:2 
cp ifcfg-eth0 ifcfg-eth0:3 
cp ifcfg-eth0 ifcfg-eth0:4
  • Open each of them and change the fields DEVICE, .IPADDR and NETMASK accordingly.

A sample entry would look like this:

DEVICE=eth0:0
BOOTPROTO=static
IPADDR=34.123.111.21
NETMASK=255.255.255.0
ONBOOT=yes
  • Restart the network:
/etc/init.d/network restart

To verify what are the IP addresses assigned to your server, please use the following command:

/sbin/ifconfig

Adding multiple IP addresses at once:

Navigate to the following folder:

/etc/sysconfig/network-scripts/

In this folder, create a file named “ifcfg-ethX-range”, without the quotes, and replacing X with the ID of the physical interface. For example, if you were using eth0, you would use the following file name:

ifcfg-eth0-range

In the file, enter the following information, modifying the entries as necessary.

IPADDR_START=10.0.0.1
IPADDR_END=10.0.0.100
CLONENUM_START=0
NETMASK=255.255.255.0

A real life example might resemble this:

IPADDR_START means the start of the IP address range
IPADDR_END means the end of the IP address range
CLONENUM_START means the number assigned to the first virtual interface, for example eth0:0 or eth0:1, or eth0:8 as in the above screen capture
NETMASK is 255.255.255.255 for all secondary IP addresses to allow you to use the network and broadcast addresses on your server

After you have created the file, save and quit, and then restart the network service:

/etc/init.d/network restart

For more information on how to manage your network configuration, please feel free to consult the official RedHat documentation site.

You might also like More from author

Leave A Reply

Your email address will not be published.