jump to navigation

Add additional IPs to one NIC in Linux February 10, 2011

Posted by Tournas Dimitrios in Linux.

This article will outline how to bind multiple IP addresses to a single NIC . By using multiple IP’s you can run a service under a specific IP while having another service under a different one ( have a web server on one and FTP on another ) . One of the major benefits is that you don’t need a physical adapter for each IP but instead can create many virtual ones tied to a single physical card . This article is targeted to RedHat based distributions (Fedora , CetnOs ) .

Linux allows you to add additional network addresses using alias feature . But all additional network IP address must be in the same subnet . For example if your eth0 is using IP address then the alias must be setup using

  • The quick way :

Two commands to remember :
$ /sbin/ifconfig    eth0:0
$ /sbin/route add     -host    dev   eth0:0

This change will no longer be in effect after rebooting. Therefor you must add the two commands to the bottom of your /etc/rc.local file. Your NIC should now be listening and responding on both this and the original IP address found in /etc/sysconfig/network-scripts/ifcfg-eth0

If you want to add add more than one additional IP address, continue like this:

$ /sbin/ifconfig   eth0:0
$ /sbin/ifconfig    eth0:1
$ /sbin/ifconfig   eth0:2
$ /sbin/route add     -host     dev    eth0:0
$ /sbin/route add   -host        dev      eth0:1
$ /sbin/route add     -host       dev     eth0:2

  • An alternative way :

Duplicating the network script (ifcfg-eth0) in /etc/sysconfig/network-scripts/ directory .
Each adapter that is installed on a computer has it’s unique network script , so the second adaptor will have ifcfg-eth1  and so on for each adaptor . Let’s assume our computer has only one network card , and we want to bind three additional IP’s  ( , and ) to this interface . We need to create three alias files while ifcfg-eth0 maintains the primary IP address . This is how we set up the aliases to bind the addresses  :

Adapter IP address
eth0 Primary
eth0:0 Alias  1
eth0:1 Alias  2
eth0:2 Alias  3

The :X (where X is the interface number ) is appended to the interface file name to create the alias . For each alias we create , an incresing  number will be assigned . For this example we will create aliases for eth0 . Three aliases needs 3 copies of the network script :

  1. cd  /etc/sysconfig/network-scripts
  2. cp  ifcfg-eth0   ifcfg-eth0:0
  3. cp  ifcfg-eth0   ifcfg-eth0:1
  4. cp  ifcfg-eth0   ifcfg-eth0:2

Let’s see the example in practice :


Editing each alias network script , we are only interested for two lines  (DEVICE and IPADDR) . We’ll rename the device  and IP in each file to  it’s new values .

After restarting the network interface with : service network restart , we can confirming the changes with ifconfig

Now let’s ping all our IP’s  from a remote computer . Of course for convenience we are using fping

Looks like everything is working like a charm. With the new IP’s you can set up sites in Apache bound to a dedicated IP, anonymous FTP, and many other things.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s