大网数据广告活动
服务器运维问答

How to bind a range of ips to ubuntu interfaces

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。