Pages

Saturday, July 7, 2012

Add a secondary IP address


Many of times, there will be a need for a multiple ip address on the linux machine for some experimental purpose. In this article, I have configured second IP on the same NIC card. Linux has the ability to configure multiple IPs on the same NIC card. How can we configure second IP address on the single NIC card?

So basically when I type ifconfig eth0 on my linux box, I see

eth0              Link encap:Ethernet  HWaddr 00:21:9B:F3:48:4D 
                    inet addr:183.83.15.120  Bcast:183.83.63.255  Mask:255.255.192.0
                    inet6 addr: fe80::221:9bff:fef3:484d/64 Scope:Link
                    UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                   ………
So I have an IP 183.83.15.120 already configured. So in order to configure second ip address on the same NIC card, we need to edit some configuration files which are located in /etc/sysconfig/network-scripts/

The file ifcfg-eth0 says information about the first eth0 IP information. So now edit ifcfg-eth1 available in the same location and add the following lines,

# please read /usr/share/doc/initscripts-*/sysconfig.txt
# For the documentation of these parameters.
GATEWAY=183.83.0.1
TYPE=Ethernet
DEVICE=eth0:1
HWADDR=00:21:9B:F3:48:4D
BOOTPROTO=none
NETMASK=255.255.192.0
IPADDR=183.83.15.150
ONBOOT=yes
USERCTL=no
IPV6INIT=no
PEERDNS=yes

Just add the IP address, netmask and Gateway. Make sure the Device to eth0:1.Once the configuration file is updated. Save it and restart the network using

 service network restart

Once the restart is done, check ifconfig to see 2 IP’s configured.