3

I am trying to bind a range of IPs(2048 total) on an Ubuntu server and the only way I know of is adding one by one to the interfaces file and restarting the network service like this:

### /etc/network/interfaces ###
auto enp2s0:1
iface enp2s0:1 inet static
address 200.20.39.1
netmask 255.255.255.255

auto enp2s0:2
iface enp2s0:2 inet static
address 200.20.39.2
netmask 255.255.255.255

etc etc.

The problem with this approach is that when I restart the network to apply these changes and checking the ifconfig command is only adding 8 or 9 ips at the time, so i have to restart the service again to add 8 more and so on, so it will take me 30 hours to add those ips.

I know that on Redhat based systems you have an option to add ranges easily like this:

/etc/sysconfig/network-scripts/ifcfg-eth0-range0
IPADDR_START=192.168.0.100
IPADDR_END=192.168.0.200
CLONENUM_START=0

Is there any way to do this on Ubuntu? or any other faster way?

notforever
  • 133
  • 4

2 Answers2

1

If you don't mind not having interface aliases (i.e. the :0, :1 etc.), you can add as many IP addresses as you want on enp2s0 with the ip addr add command on the up event:

auto enp2s0
iface enp2s0 inet static
address 200.20.39.1
netmask 255.255.248.0
up ip addr add 200.20.39.1/21 dev enp2s0
up ip addr add 200.20.39.2/21 dev enp2s0
...
up ip addr add 200.20.39.254/21 dev enp2s0
...

and so on.

It should be pretty easy to generate the 2048 lines programmatically and then a simple ifdown enp2s0/ifup enp2s0 should get you ready without multiple restarts of the network service.

DISCLAIMER

Please keep in mind that you should do ifdown only if locally connected or remotely connected through another interface, as you'll lose connectivity to the server if connecting to enp2s0.

Daniele Santi
  • 2,479
  • 1
  • 25
  • 22
1

If you add a subnet to your lo interface, linux will respond to any address within that subnet.

To illustrate this, say you have an IP address of 192.168.1.99 on your ethernet interface. Now add 10.1.2.0/21 to your lo interface:

ip addr add 10.1.2.0/21 dev lo

Now it will react to any arp request for any IP address within that range, on whatever interface.

To be able to reach those IP addresses from other systems in your 192.168.1.0/24 range, you will need to set a route on those systems to that subnet via its primary address, i.e. 192.168.1.99 in this case. Alternatively add this route to the default gateway, it should send ICMP redirects when necessary to that host.

wurtel
  • 3,806
  • 12
  • 15