Linux – Cent OS ifcfg configuration for ranges of IP’s with different netmask

centosconfigurationlinuxnetworking

I have 1 set of 30 public IP's with a netmask of 255.255.255.0 and another set of 30 IP's with a netmask of 255.255.255.128. Both sets of IP's also have different gateways. How can I virtually assign the IP's to the machine?

I have tried creating ifcfg-eth0:0 ifcfg-eth0:1 ifcfg-eth0:X ect for each IP. Below is my ifcfg file with. I have this for each IP with the correct gateway IP and netmask for each of my 60 IP's. If I do ip addr show it does show all of the 60 addresses with the correct broadcast IP and netmask.

However I can only use 30 of my IP's that are from the same netmask. Am I doing this correctly? If the IP's show up with ip addr show does that mean I have correctly assigned them to the machine virtually? I want to check before I blame my hosting company for not routing the IP's correctly.

DEVICE="eth0:1"
BOOTPROTO="static"
DNS1="**.**.**.**"
DNS2="**.**.**.**"
GATEWAY="2**.**.***.126"
HOSTNAME="localhost.localdomain"
HWADDR="0*:19:**:**:**:**"
IPADDR="2**.*.**.**"
IPV6INIT="no"
MTU="1500"
NETMASK="255.255.255.128"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

Also is there a better way to do this? I have used ifcfg-eth0:0-range1 before to assign a range of IP's from the same netmask. Is it possible to do this with ranges with different netmask?

Thanks!

Best Answer

Assuming each range is contiguous, you should be able to get this going with one configuration file per network range. Substitute your provided IP values, as these ranges are provided merely as an example:

/etc/sysconfig/network-scripts/ifcfg-eth0-range0:

IPADDR_START=10.10.10.10
IPADDR_END=10.10.10.39
CLONENUM_START=0
NETMASK=255.255.255.0
BROADCAST=10.10.10.255
GATEWAY=10.10.10.1

/etc/sysconfig/network-scripts/ifcfg-eth0-range1:

IPADDR_START=10.20.20.10
IPADDR_END=10.20.20.39
CLONENUM_START=30
NETMASK=255.255.255.128
BROADCAST=10.20.20.127
GATEWAY=10.20.20.1

At which point you should be able to bring the ranges up with the ifup-aliases script at /etc/sysconfig/network-scripts/ifup-aliases with the argument of the relevant network adapter, in this case eth0:

/etc/sysconfig/network-scripts/ifup-aliases eth0

Alternatively you can restart networking via the init script.

Related Topic