嘟嘟社区

debian能添加一个ip段吗?


除了centos还有啥系统可以添加整个IP段的,不用一个个添加ip的那种,我现在装的cnetos7添加网卡里添加“NM_CONTROLLED=no”就重启不了
interfaces 文件 ,示例
  1. address x.x.x.x/24
  2. netmask 255.255.255.128

复制代码

眼儿媚 发表于 2022-3-12 19:02
interfaces 文件 ,示例

多个IP段怎么添加?

shuishui 发表于 2022-3-12 19:11
多个IP段怎么添加?

用脚本加

有脚本吗?

未测试,供参考

================================================================
how to add a range of IP addresses in debian
================================================================
https://serverfault.com/questions/246524/how-to-add-a-range-of-ip-addresses-in-debian

/etc/network/if-up.d/eth0

  1. #!/bin/bash
  2. if [ "$IFACE" eq "eth0" ]; then
  3.     for IP in {128..254}; do
  4.         ip addr add 192.168.1.${IP}/24 dev eth0
  5.     done
  6. fi
  7. # EOF

复制代码

/etc/network/if-down.d/eth0

  1. #!/bin/bash
  2. if [ "$IFACE" eq "eth0" ]; then
  3.     for IP in {128..254}; do
  4.         ip addr del 192.168.1.${IP}/24 dev eth0
  5.     done
  6. fi
  7. # EOF

复制代码

chmod +x /etc/network/if-up.d/eth0
chmod +x /etc/network/if-down.d/eth0

================================================================
What does $IFACE mean?
================================================================
https://askubuntu.com/questions/913070/what-does-iface-mean

IFACE is an internal variable for ifupdown (ifup and ifdown), could be used in the relevant configuration file /etc/network/interfaces (and on files from relevant directories).

The variable IFACE expands to the name of the interface being processed currently by ifup or ifdown.

IFACE 是 ifupdown(ifup 和 ifdown)的内部变量,可用于相关配置文件 /etc/network/interfaces(以及相关目录中的文件)。

变量 IFACE 扩展为 ifup 或 ifdown 当前正在处理的接口的名称。