我做了一切这个答案,我可以通过静态 IP 连接到虚拟机,但我仍然从 DHCP 服务器获取 IP,而不是接口上的静态 IP,这是怎么回事?我该如何摆脱它?可能是因为 vnet0 吗?我在这台机器上尝试了很多不同的配置。使用 DHCP 时,网络上发生了一些非常奇怪的事情,Cisco 路由器(旧款)向具有不同 MAC 地址的虚拟机提供相同的 IP 地址,因此现在尝试使用静态。
我在虚拟机上运行的是 Ubuntu Server 18.04.1,操作系统与虚拟机相同
我的主机上的 /etc/network/interfaces:
auto br0
iface br0 inet static
address 10.101.22.10
netmask 255.255.255.0
network 10.101.22.0
broadcast 10.101.22.255
gateway 10.101.22.253
dns-nameservers 8.8.8.8
bridge_ports enp3s0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
在虚拟机上:
auto enp1s0
iface enp1s0 inet static
address 10.101.22.11
netmask 255.255.255.0
network 10.101.22.0
broadcast 10.101.22.255
gateway 10.101.22.253
dns-nameservers 8.8.8.8
我的 ifconfigs 在主机上:
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.101.22.10 netmask 255.255.255.0 broadcast 10.101.22.255
inet6 fe80::325a:3aff:fe81:71d7 prefixlen 64 scopeid 0x20<link>
ether 30:5a:3a:81:71:d7 txqueuelen 1000 (Ethernet)
RX packets 3459 bytes 388406 (388.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2126 bytes 281068 (281.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::325a:3aff:fe81:71d7 prefixlen 64 scopeid 0x20<link>
ether 30:5a:3a:81:71:d7 txqueuelen 1000 (Ethernet)
RX packets 3492 bytes 759637 (759.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1890 bytes 293653 (293.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 258 bytes 21898 (21.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 258 bytes 21898 (21.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fea0:202f prefixlen 64 scopeid 0x20<link>
ether fe:54:00:a0:20:2f txqueuelen 1000 (Ethernet)
RX packets 887 bytes 121511 (121.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1843 bytes 503003 (503.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在虚拟机上:
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.101.22.198 netmask 255.255.255.0 broadcast 10.101.22.255
inet6 fe80::5054:ff:fea0:202f prefixlen 64 scopeid 0x20<link>
ether 52:54:00:a0:20:2f txqueuelen 1000 (Ethernet)
RX packets 1843 bytes 499023 (499.0 KB)
RX errors 0 dropped 613 overruns 0 frame 0
TX packets 899 bytes 122831 (122.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 166 bytes 13132 (13.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 166 bytes 13132 (13.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
答案1
18.04 不使用 /etc/network/interface。您需要熟悉 netplan 并在/etc/netplan/*yaml