Setting up many IP addresses on one physical network interface

In some cases you may need to setup several ip addresses to be served by the same physical network interface. For example, you may want to have DNS service running on your dedicated server with only one network card. Each domain must have two nameservers with two distinct IP addresses.

This can be accomplished by using so called virtual interfaces tied to a physical network adapter.

Method 1: Few IP addresses. Manual way.

If you want to setup only a few IP addresses, you may do the following:

cp /etc/sysconfig/network-scripts/ifcfg-eth0 cp /etc/sysconfig/network-scripts/ifcfg-eth0:0
nano -w /etc/sysconfig/network-scripts/ifcfg-eth0:0

We are just copying existing interface configuration file to a new one to create virtual interface. In this example, I supplose you want to add IP address to the interface named eth0. If you want to add addresses to another interfaces, type it's name everywhere instead of "eth0" in instructions.

In the opened editor window you need to replace "eth0" with "eth0:0" and old IP address with a new one. Save the file. To apply changes immediately you need to just issue the following command:

ifup eth0:0

Some people recommend to do

service network restart

but I don't think it is really necessary. This will also make all current network connections to server to be closed.

Ok, your new IP should now be working and you may test it with "ping". Please note, that your provider need to dedicate an IP address you are adding to your server. It needs to be included into your provider's routing tables and router configuration. So, before doing any configuration changes to your server, ensure your provider did all that.

To add more IP addresses repeat instructions above just changing "eth0:0" to "eth0:1" etc.

Method 2: Many IP sequential IP addresses. Automatic.

In case you want to assign many IP addresses to the same network interface (10, 100, 1000?) you may use the following technique. Issue the following command:

nano -w /etc/sysconfig/network-scripts/ifcfg-eth0-range0

Type the following lines into the file:

IPADDR_START=192.168.0.101
IPADDR_END=192.168.0.120
NETMASK=255.255.255.255
CLONENUM_START=3
NO_ALIASROUTING=yes

You can even create several ranges (ifcfg-eth0-range1, ifcfg-eth0-range2 etc.). Just take care of CLONENUM_START value for these ranges not to overlap. To apply configuration you will need to issue

service network restart

Notes

VladislavRastrusny/OneNICManyIPs (last edited 2009-06-25 12:52:45 by VladislavRastrusny)