ubuntu下为单个网卡配置多个ip

参考文档

https://www.jb51.net/os/Ubuntu/418951.html

添加临时ip地址(设备重启后不生效)

sudo ip addr add 192.168.1.104/24 dev enp0s3   //给设备 enp0s3 添加 ip 地址

sudo ip address show enp0s3          //查看配置是否生效

sudo ip addr del 192.168.1.104/24 dev enp0s3    //删除设备 enp0s3 的 ip 地址

添加永久ip地址(设备重启后仍然生效)

需要修改 ubuntu 下网卡的配置文件 /etc/network/interfaces ,示例如下:

auto enp0s3          // 网卡配置最开始的这一行保持不变
iface enp0s3 inet dhcp       // dhcp 配置
iface enp0s3 inet static         // 网卡配置静态 ip 地址
address 192.168.1.104/24

注意:

  配置多个ip地址之后可通过ping的方式验证,或通过 'sudo ip address show <interface name>'命令查看。

  通过 ifconfig 只能显示一个 ip 地址。

猜你喜欢

转载自www.cnblogs.com/rivsidn/p/9474612.html