Adding a Public IPv4 Address to a Linux Server (CentOS 6)

To configure an additional public IPv4 address in CentOS, proceed as follows:

Prerequisites:

In the Cloud Panel you have assigned an additional public IPv4 address to your server.

You have logged in to the server.

Step 1

To configure the main IP address as static, you must change the entry for eth0 in /etc/sysconfig/network-scripts/ifcfg-eth0. To carry out this change, enter the following:

vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
BROADCAST=ABC.DEF.GHI.JKL
IPADDR= ABC.DEF.GHI.JKL
NETMASK=255.255.255.255
NETWORK= ABC.DEF.GHI.0
ONBOOT=yes
NM_CONTROLLED=no

Enter your main IP address at IPADDR and BROADCAST. Enter your main IP address and the number 0 at NETWORK.

Step 2

Open the vi editor and enter the following information in the route-eth0 file:

vi /etc/sysconfig/network-scripts/route-eth0
10.255.255.1 dev eth0
default via 10.255.255.1 dev eth0
Step 3

To restart the network, enter the following command:

/etc/init.d/network restart
Step 4

To add an additional IP address, you need an Ethernet alias. To do this, a consecutive number is simply appended to the interface name, starting with 0 for the first alias. Thus, the first alias of eth0 is eth0:0. The easiest way is to copy the configuration of eth0. Then you simply need to change to the newly-added IP address:

cp -a /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=ABC.DEF.GHI.JKL
IPADDR= ABC.DEF.GHI.JKL
NETMASK=255.255.255.255
NETWORK= ABC.DEF.GHI.0
ONBOOT=yes
NM_CONTROLLED=no