ip address exampleAs we know Linux allows to assign almost unlimited number of IP addresses to its interfaces. Such additional IPs applied to the same NIC are known as secondary IP addresses or just secondaries. Some time ago i faced a problem on how to apply about 500 IP addresses to one Linux box and then ensure that all of them get online after Linux reboots. There are several ways to accomplish this taks so i would like to share them all.

Shell script with ifconfig commands

This is one of the most inefficient ways to get many IP addresses applied to one network interface. Anyways it allows to create as many aliases for the interface as you like so you should create shell script and execute it every time Linux boots.

touch /path/to/script.sh
chmod +x /path/to/script.sh
vi /path/to/script.sh

Now you should add there shell lines which will apply IP addresses, e.g. the following one applies 60 IP addresses to eth0 interface:

for n in {3..63};  do ifconfig eth0:${n} 10.10.10.${n} netmask 255.255.255.0 up; done

If you type ‘ifconfig’ now you will very long output like this one:

eth0:3  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB  
          inet addr:10.10.10.3  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000 

eth0:4  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB  
          inet addr:10.10.10.4  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000

...

eth0:63  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB  
          inet addr:10.10.10.63  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000 

If you decide to delete those IPs you can run the following line as a remedy:

for n in {3..63};  do ifconfig eth0:${n} 0.0.0.0 &> /dev/null; done

Once you finished editing /path/to/script.sh script you should add it to startup, so put the line /path/to/script.sh into /etc/rc.local file that Linux executes every time it boots. Please notice that in various distributions this file may be missing so consult with distro’s docs to get where it is stored.

Redhat/Centos/Fedora network scripts

Users of these Linux distributions can apply ranges of IP addresses using ifcfg-eth0-range0 files which are read during initialization of network interfaces during boot up process. The following example will make Linux to apply 200 IP addresses to eth1 during booting:

[root ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1-range0

IPADDR_START=192.168.1.1
IPADDR_END=192.168.1.200
CLONENUM_START=10

CLONENUM_START value specifies starting identifier of alias that will be applied to eth1 interface, in above example the first 192.168.1.1 will be assigned to eth1:10 alias. The last IP of the range 192.168.1.200 will be applied to eth:210 sub-interface. This is totally easy approach.

Loopback interface

Did you know that by one line presented below you assign 1022 virtual IP addresses to your Linux system? Here it is:

ifconfig lo:0 10.0.0.1/22

Now you can make sure of this by pinging IPs from that range (10.0.0.1 – 10.0.3.254).

[root ~]#ping 10.0.0.1 -c 1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.063 ms

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms

...

[root ~]#[root@whitehorse /]# ping 10.0.3.254 -c 1
PING 10.0.0.1 (10.0.3.254) 56(84) bytes of data.
64 bytes from 10.0.3.254: icmp_seq=1 ttl=64 time=0.063 ms

--- 10.0.3.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms

If you still feel that the first suggested way meets your requirements better than the third one please read more about loopback interface at wikipedia — loopbacks are much more useful than aliases in most cases.

Hope it helps!

 

7 Comments

 

  1. January 18, 2011  7:40 am by Sale Reply

    I think it opens the website is very nice and I like to have web sites of mine, but you so beautiful I do not how good web design and people who collect my website could you help me friends

  2. May 27, 2011  10:05 pm by truculgos67 Reply

    Spot on with this write-up, I truly assume this website needs way more consideration. I’ll most likely be once more to read much more, thanks for that info.I*9v0 diet pills that work fast Kiy((

  3. March 23, 2012  12:05 am by Bank CardUSA Reply

    Hey! This is kind of off topic but I need some guidance from an established blog. Is it hard to set up your own blog? Im not very techincal but I can figure things out pretty fast. Im thinking about setting up my own but Im not sure where to start. Do you have any tips or suggestions? Thanks

  4. April 27, 2012  3:14 pm by CRO Reply

    I found your blog in Yahoo, Excellence article I must said Thank you for your information, Ive been looking for this information for a long time. Very useful

  5. May 2, 2013  10:11 am by Emilio Mautino Reply

    A number of weight-loss pills are available at your local drugstore, supermarket or health food store. Even more options are available online. Most haven't been proved effective, and some may be downright dangerous..,

    Freshest posting on our very own online site
    <http://foodsupplementcenter.com/

  6. May 31, 2013  8:05 pm by idm crack Reply

    Restore all the settings that can be stored on your phone.
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\Current - Version\Internet Settings\5. Obviously, that doesn't work for new bands, which is why a band like Avenged Sevenfold can charge $45, but any sort of heritage band that has been around for a while and they have fans ' think about Motley Crue and KISS.

  7. June 11, 2013  11:38 pm by cunnilingus Reply

    Admiring the dedication you put into your blog and in depth information you present.
    It's nice to come across a blog every once in a while that isn't the same out of date rehashed material.
    Excellent read! I've bookmarked your site and I'm including your RSS feeds to my
    Google account.

Leave a reply

 

Your email address will not be published.