ubuntu
1.获取现有网卡名称,示例是eth0
[root@iZ2ze616zb6x1rqtgc7w9qZ ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.248.80 netmask 255.255.240.0 broadcast 172.17.255.255
inet6 fe80::216:3eff:fe3a:bfa6 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:3a:bf:a6 txqueuelen 1000 (Ethernet)
RX packets 21531829 bytes 6941596461 (6.4 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17478204 bytes 15979831116 (14.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255
inet6 fe80::42:e1ff:fe2d:3e30 prefixlen 64 scopeid 0x20<link>
...
2.添加虚拟网卡信息
# 编辑网卡
vi /etc/network/interfaces
# 文档最后增加内容
auto [当前网卡名称]:1
iface [当前网卡名称]:1 inet static
address [想要添加的虚拟IP地址]
netmask 255.255.255.0
# 重启网卡
sudo /etc/init.d/networking restart
3.再次使用第一步命令验证虚拟网卡是否添加成功
centos
1.获取现有网卡名称
[root@iZ2ze616zb6x1rqtgc7w9qZ ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.248.80 netmask 255.255.240.0 broadcast 172.17.255.255
inet6 fe80::216:3eff:fe3a:bfa6 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:3a:bf:a6 txqueuelen 1000 (Ethernet)
RX packets 21531829 bytes 6941596461 (6.4 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17478204 bytes 15979831116 (14.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255
inet6 fe80::42:e1ff:fe2d:3e30 prefixlen 64 scopeid 0x20<link>
...
2.添加虚拟网卡信息
#在/root目录创建shell脚本
vi vnetwork.sh
#添加内容
ifconfig [当前网卡名称]:1 [想要添加的虚拟IP地址] netmask 255.255.255.0 up
#设置开机执行脚本
vi /etc/rc.d/rc.local
#在文档最后增加内容
/root/vnetwork.sh
#授权
chmod +x /root/vnetwork.sh
#执行脚本(系统重启也会执行这个脚本)
sh /root/vnetwork.sh
3.再次使用第一步命令验证虚拟网卡是否添加成功
windows
1.按下win+R键,输入hdwwiz执行