ABHIONLINUX
Site useful for linux administration and web hosting

2010/04/21

How to set multiple IP addresses using Linux command line

Go to /etc/sysconfig/network-scripts
Make multiple copies of ifcfg-eth0 and name them as ifcfg-eth0:0, ifcfg-eth0:1 etc.
Open each of them and at least change the IPADDR to your chosen IP address and the NETMASK to the subnet mask for that IP address.
A sample entry would look like this:

DEVICE=eth0:0
BOOTPROTO=static
IPADDR=34.123.111.21
NETMASK=255.255.255.0
ONBOOT=yes

Restart the network:
/sbin/service network restart
/etc/init.d/ipaliases restart (for cpanel servers) 

If you have more than 100's of IP, it is difficult to choose above method. For that  you can try the following method.

[root@server ~]#d /etc/sysconfig/network-scripts/ – this is where the network settings are being searched for
[root@server network-scripts]# vi ifcfg-eth0-range0 – this will be the file where we define the new IP class(considering that our main interface is called eth0)
Add this content to the file:

IPADDR_START=192.168.0.1
IPADDR_END=
192.168.0..28
CLONENUM_START=1
NETMASK=255.255.255.240


Explanation:
IPADDR_START – the first IP of the class you want to add
IPADDR_END – last IP of the class you want to add
CLONENUM_START – the number with which the virtual interface will start, this will create the virtual interfaces eth0:1 to eth0:28.
If you have more classes that you want to add on the next class CLONENUM will start at 29.
NETMASK – the mask for the IP class
After all this was added to the file and edited accordingly just save and restart the network.

.

No comments:

Post a Comment