Mohammedz.com

For Linux and Shell scripting.

Add a range of IP addresses simultaneously

1 Comment


For a small range of IP addresses, you can manually add each of them to a file named ifcfg-eth0:x under /etc/sysconfig/network-scripts/. For example, if you want to add 4 IP addresses, you can create 4 files under /etc/sysconfig/network-scripts/ like ifcfg-eth0:0, ifcfg-eth0:1 etc. Each of them will contain something like this:

DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.252
TYPE=Ethernet

But, what if want to add 100 or 1000 IP addresses? Is it feasible to sit and add each one of them? Fortunately, RedHat flavors offer a much easier way to bind a range of IP addresses.

You can create a file named “ifcfg-eth0-range0” under /etc/sysconfig/network-scripts/. The file content should be something like this:

IPADDR_START=192.168.0.2
IPADDR_END=192.168.0.202
CLONENUM_START=0

IPADDR_START :-> The first IP address that you want to bind with your network card.
IPADDR_END :-> The last IP address that you want to bind with your network card.
CLONENUM_START :-> The number which will be assigned to the first IP alias interface. If your Internet interface is eth0 and CLONENUM_START is 0, then this config file will create 200 interfaces starting with eth0:0 and ending with eth0:199.

If you want to add a second range with 100 IPs, create a new file named “ifcfg-eth0-range1” and set the CLONENUM_START to 200. Otherwise, there will be conflicts with IP addresses and network won’t come up.

When you make changes to the network-scripts, you should restart the network.

# /etc/init.d/network restart
or
# service network restart

~mohammed

Advertisements

One thought on “Add a range of IP addresses simultaneously

  1. Hello Mohammed, googling these ifcfg ranges looking for how to deal with multiple ranges, your explanation made me understand it!
    One comment, in your example for “ifcfg-eth0-range1″, the CLONENUM_START should be set to 201 right? From 2 to 202 is 201 addresses assuming IPADDR_END is included in the range that is.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s