解决方案

在Debian/Ubuntu Linux下的/etc/network/interfaces配置文件中进行设置。

备份配置文件:

# cp /etc/network/interfaces /root/working.interfaces

编辑配置文件:

$ sudo vi /etc/network/interfaces

修改示例:

auto eth0
auto eth0:0
auto eth0:1
 
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254
 
iface eth0:0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254
 
iface eth0:1 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

Debian/Ubuntu Linux中如何配置多个IP

在Linux中如何在1块网卡上配置多个IP?
在Debian/Ubuntu Linux中如何配置浮动IP?
在Debian/Ubuntu Linux中如何配置网口别名?

如何查看IP地址设置

验证IP设置

# ifconfig -a

或者

# ip addr show eth0

ip命令

ifconfig命令正在逐步淘汰,并已由ip命令代替。

ip命令没有使用别名或虚拟接口概念,而是将其他地址视为第一类对象。

系统在一个接口上配置多个地址的新方法是调用up ip/down ip来添加和删除这些其他IP地址。

示例:将两个IP地址分配给eth0,同时分配标签:

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.1.254
    up   ip addr add 192.168.1.2/24 dev eth0 label eth0:0
    down ip addr del 192.168.1.2/24 dev eth0 label eth0:0
    up   ip addr add 192.168.1.3/24 dev eth0 label eth0:1
    down ip addr del 192.168.1.3/24 dev eth0 label eth0:1

然后在Debian/Ubuntu Linux下重新启动网络服务:

$ sudo /etc/init.d/networking restart
日期:2019-11-20 08:53:04 来源:oir作者:oir