问题原文
原帖链接 · notforever · CC BY-SA 4.0
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?
已采纳解答
原帖链接 · Daniele Santi · CC BY-SA 4.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
