Knowledgebase:
Add Range of IP Addresses to Interface (RedHat-based systems)
Posted by rbTech Staff on 05 January 2012 12:36 PM
Sometimes you need to add a range of IP addresses to an interface. A good example is configuring a firewall, where you need all of your public IP addresses to be bound to one interface. One way to do this is to create separate ifcfg-eth0:x files for each IP address that you need. This works for a couple of addresses - after that, it gets tedious and messy to maintain. On RedHat-based systems, you can bind multiple IP addresses to an interface with a single file. Create (or modify) the file/etc/sysconfig/network-scripts/ifcfg-ethx-range0 (where x is the interface number). For our example let's assume we're modifying eth0. Insert (or modify) the following lines in this file (ifcfg-eth0-range0):
IPADDR_START=192.168.0.10
  IPADDR_END=192.168.0.20
  CLONENUM_START=0
  NETMASK=xxx.xxx.xxx.xxx

This will create additional IP addresses on the eth0 interface, starting with 192.168.0.10 and ending with 192.168.0.20. The aliased interfaces will be eth0:x, with x starting at the number specified by CLONENUM_START. NETMASK obviously specifies the network mask to use.

You can specify additional ranges by creating additional files with the same naming convention, but using a different number after range (i.e. ifcfg-eth0-range1). Note that you need to be careful when specifying CLONENUM_START in any additional ranges, so as not to overwrite previously specified aliases.

(2 vote(s))
Helpful
Not helpful

Comments (1)
derek
09 May 2014 06:05 PM
Anyway to modify the ifcfg-lo config that would achieve this.

ip a a 127.0.0.1 dev lo
ip a a 4.2.2.2 dev lo

Without using the wacky aliasing construct.

thanks,
derek
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).