Add a secondary IP to CentOS servers

How to add a secondary IP to CentOS servers is pretty easy.

First what you’re going to do, is to SSH into the server itself.

What we need to do, is to create a little file in sysconfig/network-scripts to bind the IP to the server, by doing following:

cd /etc/sysconfig/network-scripts/

Make a new file called ifcfg-eth0:1. If the :1 already exists, name it 2,3,4,5 etc.

vi ifcfg-eth0:1

Inside this file you should add following code:

DEVICE="eth0:1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.2.5"

The IPADDR should be the IP you want to add.

Once this is done, press esc, type :wq to quit vi again.

When you return to the prompt again, you need to restart the network.
You can do it by using following command:

ifup eth0:1

Edit: Thanks to Paolo Iannelli, for pointing out it’s possible to use ifup instead of restart. This will not restart the other interfaces, which means no network loss!