October 20, 2017

How to Add a Second IP Address to an Existing Network Adapter on CentOS

CentOS Logo

In this tutorial we will show you the steps to add a second IP address on an already configured NIC. This is useful for various cases. For example we use this to split the requests to a production and development website. Proxy caching is an other scenario where you can use a second IP address.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Add a second IP address

Change to the /etc/sysconfig/network-scripts directory and search for all existing NICs with the following commands:

cd /etc/sysconfig/network-scripts
ls ifcfg-*

Open the /etc/hosts file

vi /etc/hosts

and add the new IP address like the following line.

123.123.123.123 proxy.website.com

Create the new interface by copying an existing interface. This asumes that ifcfg-eth0 is the correct interface where you want to add the second IP address.

cp ifcfg-eth0 ifcfg-eth0:0

Open the copy

vi ifcfg-eth0:0

and edit the DEVICE and IPADDR line. Use the name of the new device under DEVICE and the new IP address under IPADDR.

DEVICE=eth0:0
IPADDR=123.123.123.123

Activate the second IP address with the following command:

./ifup eth0:0

You can do the same steps to add a third IP address and so on.

Comments

  1. Marvin Bratcher says:

    Very good article! We will link to this great post on our site.
    Keep up the good writing.

Speak Your Mind