Debian需要修改 /etc/network/interfaces 文件来修改或添加多个IP地址的绑定
先备份interfaces文件
cp /etc/network/interfaces /root/interfaces.bak
使用VIM编辑配置文件
vim /etc/network/interfaces
示例文件:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eno1:0 iface eno1:0 inet static address 12.3.12.10 netmask 255.255.255.192 gateway 12.3.12.1 dns-nameservers 8.8.8.8 auto eno1:1 iface eno1:1 inet static address 12.3.12.11 netmask 255.255.255.192 gateway 12.3.12.1 dns-nameservers 8.8.8.8 auto eno1:2 iface eno1:2 inet static address 12.3.12.12 netmask 255.255.255.192 gateway 12.3.12.1 dns-nameservers 8.8.8.8 auto eno1:3 iface eno1:3 inet static address 12.3.12.13 netmask 255.255.255.192 gateway 12.3.12.1 dns-nameservers 8.8.8.8
重启网络
service networking restart
可用以下脚本批量添加,注意根据实际ip地址进行改动
# !/bin/bash for ((i=1;i<=64;i=i+1)) do echo "auto eth0:$i">>/etc/network/interfaces echo "iface eth0:$i inet static">>/etc/network/interfaces let j=$i+29 echo "address 1.2.3.$j">>/etc/network/interfaces echo "netmask 255.255.255.248">>/etc/network/interfaces echo "gateway 1.2.3.4">>/etc/network/interfaces echo " ">>/etc/network/interfaces done # end
同样适用于ubuntu 17.10以前的版本,ubuntu17.10以后的请看这里