IPs & SubnetsLinux

Use a Range File to set up IP Subnets in your Linux Server

You can in some cases use a range file in Linux to set up a whole subnet inside your VPS or dedicated server. By using a range file to configure subnets in Linux you can quickly deploy large subnets but this does have some disadvantages. When you use a range file with a subnet you cannot specify a BROADCAST for each IP and on some NVMe Servers, depending on what type of router is used you will need to specify this field or you will see inconsistent results.

Using this method will work on any RedHat-based system so this is good for Fedora, CentOS, ClearOS, RockyLinux and AlmaLinux. Whereas you would usually create each eth0:X file and populate each file with individual IPs you can create the file ifcfg-eth0-range and populate that with your subnet.

Create Range File In Linux

First, create the file

nano /etc/sysconfig/network-scripts/ifcfg-eth0-range

Inside the file add the following information

IPADDR_START=START IP
IPADDR_END=END IP
CLONENUM_START=0
NETMASK=255.255.255.0
ARPCHECK=no

So, if you had a /29 subnet for example 192.168.0.0/29 you would place 192.168.0.0 in the IPADDR_START field. And 192.168.0.7 in the IPADDR_END field. Save and close the file then restart the network or reboot your server and the subnet assigned to that server should start to work.

Configuring Multiple Subnets Using Range Files

You can use this method to set up multiple subnets inside your server. But to do this you have to make sure that the CLONENUM_START field has a unique number. To set up another subnet in the same server create a new range file;

nano ifcfg-eth0-range1

In our previous example, we configured a /29 subnet. This subnet has 8 IPs so, we need to increase the CLONENUM_START= number by 8 because 8 interfaces would have been created in the first step. This time in the CLONENUM_START= field place a 9. So by doing this each IP will have a unique interface.

IPADDR_START=START IP
IPADDR_END=END IP
CLONENUM_START=9
NETMASK=255.255.255.0
ARPCHECK=no

Again, save the file and restart the network or reboot and this subnet will start to work. You can do this with as many subnets as you like but you must make sure the CLONENUM_START field is unique as each range file will be assigned to the IP alias. In our examples eth0:0 and eth0:1.

If you need to specify custom fields like a BROADCAST field then you should follow the guide here on how to create separate interfaces.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button