Add additional IP address to and existing interface

Environment: Linux 2.6.32-220.23.1.el6.x86_64 #1

It is possible to assign more than one IP address to one physical interface.

Why would you want to do this? There may be several reasons for wanting additional IP addresses on one card, in my case I want to fire up an additional instance of Jboss but to do this I need to bind to a unique IP address. In linux (in this example its centos) its simple, follow these steps:

First run an ipconfig to see what you have configured:

 bash |  copy code |? 
  1. > ifconfig
  2. eth0      Link encap:Ethernet  HWaddr 00:50:56:87:00:1E  
  3.           inet addr:  Bcast:  Mask:
  4.           inet6 addr: fe80::250:56ff:fe87:1e/64 Scope:Link
  5.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  6.           RX packets:186158343 errors:0 dropped:0 overruns:0 frame:0
  7.           TX packets:586031577 errors:0 dropped:0 overruns:0 carrier:0
  8.           collisions:0 txqueuelen:1000
  9.           RX bytes:41119255272 (38.2 GiB)  TX bytes:814282374844 (758.3 GiB)

You can this interface is assigned the IP address of, next we need to edit a file so cd to /etc/sysconfig/network-scripts (this may be slightly different depending on your flavour of linux).

 bash |  copy code |? 
  1. > cd /etc/sysconfig/network-scripts

In this folder you will find the config files for the interfaces, we are interested in the interface eth0 so we need to create a new file called ifcfg-eth0:1 (or ifcfg-eth0\:1) and add the following:

 bash |  copy code |? 
  1. DEVICE=eth0:1
  3. ONBOOT=yes
  4. HWADDR=00:50:56:87:00:1e
  5. TYPE=Ethernet
  6. BOOTPROTO=none
  7. IPADDR=
  8. PREFIX=24
  10. DNS1=
  11. DEFROUTE=yes
  13. IPV6INIT=no
  14. NAME="System eth0:1"
  15. DNS2=
  16. USERCTL=no

Notice the hardware address is the same as eth0 interface but the IP address is not, this IP address will be our new IP address but uses the same interface…

To enable the new IP address bring it up with ifup and the run an ifconfig to see the new settings, hopefully will look something like this:

 bash |  copy code |? 
  1. > ifup eth0:1
  2. > ifconfig
  3. eth0      Link encap:Ethernet  HWaddr 00:50:56:87:00:1E  
  4.           inet addr:  Bcast:  Mask:
  5.           inet6 addr: fe80::250:56ff:fe87:1e/64 Scope:Link
  6.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  7.           RX packets:186162124 errors:0 dropped:0 overruns:0 frame:0
  8.           TX packets:586035365 errors:0 dropped:0 overruns:0 carrier:0
  9.           collisions:0 txqueuelen:1000
  10.           RX bytes:41119647929 (38.2 GiB)  TX bytes:814285419799 (758.3 GiB)
  11. eth0:1    Link encap:Ethernet  HWaddr 00:50:56:87:00:1E  
  12.           inet addr:  Bcast:  Mask:
  13.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1