我试图让一个在KVM中运行的vm看起来好像它在本地网络上具有自己的物理网络接口。我相信这被称为桥接,并且我尝试了在线遵循许多不同的指南,但是没有运气。每次我得到的VM都有一个虚拟网络适配器,无法与我的本地网络通信。
我的主机和来宾都运行Ubuntu 16.04服务器。
我开始通过添加br0
到我的/etc/network/interfaces
文件,它现在看起来是这样的:
~$ cat /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
iface enp2s0 inet manual
auto br0
iface br0 inet dhcp
bridge_ports enp2s0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
重新启动后,我的ifconfig如下所示:
~$ ifconfig
br0 Link encap:Ethernet HWaddr d0:50:99:c0:25:fb
inet addr:192.168.113.2 Bcast:192.168.113.255 Mask:255.255.255.0
...
docker0 Link encap:Ethernet HWaddr 02:42:dc:4f:96:9e
...
enp2s0 Link encap:Ethernet HWaddr d0:50:99:c0:25:fb
inet6 addr: fe80::d250:99ff:fec0:25fb/64 Scope:Link
...
lo Link encap:Local Loopback
...
veth009cb0a Link encap:Ethernet HWaddr 66:d6:6c:e7:80:cb
inet6 addr: fe80::64d6:6cff:fee7:80cb/64 Scope:Link
...
virbr0 Link encap:Ethernet HWaddr 52:54:00:1a:56:65
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
...
主机在我的DHCP服务器中有一个静态条目,因此它始终获取192.168.113.2,因此br0上的IP是正确的。据我了解,现在我需要做的就是使用br0接口启动一个新的虚拟机。所以我运行这个:
sudo virt-install --virt-type=kvm --name myvm \
--hvm --ram 4096 --vcpus=2 --graphics vnc \
--network bridge=br0 \
--os-type=linux --os-variant=ubuntu16.04 \
--cdrom=/var/lib/libvirt/boot/ubuntu-16.04.2-server-amd64.iso \
--disk path=/var/lib/libvirt/images/myvm.qcow2,size=16,bus=virtio,format=qcow2
我可以将VNC插入vm,然后逐步进行安装,直到进入“使用DHCP配置网络”阶段为止,此时它超时并且永远都不会获得IP。
如果使用默认的NAT接口,它可以正常工作,并且IP地址为192.168.112.xxx,并且可以访问本地网络和更大的Internet,这没有问题。如果我随后更改此工作vm上的virsh配置以桥接到br0,则无法与本地或其他任何网络通信。DHCP无法获取IP,设置静态IP不会产生外部流量。
如果有帮助,在安装程序运行时,我打开了另一个终端,并从主机获取了更多信息:
~$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.d05099c025fb no enp2s0
vnet0
docker0 8000.0242dc4f969e no veth009cb0a
virbr0 8000.5254001a5665 yes virbr0-nic
~$ brctl showmacs br0
port no mac addr is local? ageing timer
1 00:04:20:eb:7e:96 no 3.90
1 00:11:32:63:9c:cf no 1.86
1 30:46:9a:0f:81:cd no 3.39
1 44:8a:5b:9e:d1:90 no 0.00
1 88:de:a9:13:86:48 no 0.29
1 b8:ae:ed:73:3e:ca no 3.89
1 d0:50:99:c0:25:fb yes 0.00
1 d0:50:99:c0:25:fb yes 0.00
1 d0:50:99:e0:21:46 no 2.90
1 f0:f6:1c:e3:7f:be no 173.56
2 fe:54:00:6f:b8:64 yes 0.00
2 fe:54:00:6f:b8:64 yes 0.00
~$ ip route
default via 192.168.113.1 dev br0
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.113.0/24 dev br0 proto kernel scope link src 192.168.113.2
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
如果有人愿意,我愿意将整个dumpxml放在这里,但这只是网络部分:
<interface type='bridge'>
<mac address='52:54:00:6f:b8:64'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
更新2017-03-25:通过更改以下内容:
<interface type='network'>
<mac address='52:54:00:6f:b8:64'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
然后NAT正常工作,我获得了192.168.122.xxx IP,并且可以与外部服务进行通讯,等等。所以...我的主机br0是否出了问题?如果是这样,那么为什么主机可以在上面获得IP?是否有一些不支持桥接的以太网设备?这是主机上lspci的结果:
~$ lspci | grep Ethernet
02:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)
03:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)
我根本没有设置第二个以太网控制器,也许我会设置它并尝试桥接那个。
更新2017年3月25日b:第二个界面似乎没有改变结果。这是生成的/ etc / network / interfaces:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto enp2s0
iface enp2s0 inet dhcp
auto enp3s0
iface enp3s0 inet manual
auto br0
iface br0 inet dhcp
bridge_ports enp3s0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
当我时ip a
,结果为:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether d0:50:99:c0:25:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.113.2/24 brd 192.168.113.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::d250:99ff:fec0:25fb/64 scope link
valid_lft forever preferred_lft forever
3: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether d0:50:99:c0:25:fa brd ff:ff:ff:ff:ff:ff
inet6 fe80::d250:99ff:fec0:25fa/64 scope link
valid_lft forever preferred_lft forever
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d0:50:99:c0:25:fa brd ff:ff:ff:ff:ff:ff
inet 192.168.113.100/24 brd 192.168.113.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::d250:99ff:fec0:25fa/64 scope link
valid_lft forever preferred_lft forever
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:1a:56:65 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:1a:56:65 brd ff:ff:ff:ff:ff:ff
7: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:18:2c:73:bb brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:18ff:fe2c:73bb/64 scope link
valid_lft forever preferred_lft forever
9: vethaa3cd40@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether ae:05:f7:1b:f9:9e brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::ac05:f7ff:fe1b:f99e/64 scope link
valid_lft forever preferred_lft forever
10: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:3a:54:b3 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe3a:54b3/64 scope link
valid_lft forever preferred_lft forever
当告知使用br0时,VM仍然存在完全相同的问题。