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:
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
IPADDR_START is the address, from which your IP range is starting.
IPADDR_END is the address, by which your IP range is ending.
CLONENUM_START is the number of virtual device the first IP address will be assigned to. In the above example, applying configuration changes will make IP address 192.168.0.101 to be mapped to eth0:3 virtual device. 192.168.0.102 to eth0:4 etc.
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
- iptables does not see any virtual interfaces. So all traffic on eth0:0, eth0:1 etc will be filtered by the rules assigned by iptables to eth0 physical interface.
I didn't test this solution on a server with DHCP configured eth0. But at least you will need to set "BOOTPROTO=static" in ifcfg-eth0:0 or ifcfg-eth0-range0 files. Anyway, I am curious why using static IP addresses on DHCP configured server