Ubuntu Server 16.04 上的 KVM Bridge 无法正常工作

Ubuntu Server 16.04 上的 KVM Bridge 无法正常工作

感谢收听。

我遵循了这里和其他地方的一些指导,相信我的设置正确,但我的客人就是看不到主机(即互联网),而且我无法 ping 进客人的任何端口。

除非我完全搞错了,否则我认为这就是桥接能给我带来的!希望提供所有相关信息...

libvirt 网络默认.xml...

<network>
  <name>default</name>
  <uuid>64acadc1-0c41-4cf5-850e-01bcfe5ad7ba</uuid>
  <forward mode='route'/>
  <bridge name='br0' stp='on' delay='0'/>
  <mac address='52:54:00:54:b1:e4'/>
  <ip address='192.168.0.2' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.0.3' end='192.168.0.254'/>
      <host mac='52:54:00:13:3a:69' name='node1' ip='192.168.0.201'/>
      <host mac='52:54:00:92:af:91' name='node2' ip='192.168.0.202'/>
      <host mac='52:54:00:bb:4b:6d' name='node3' ip='192.168.0.203'/>
      <host mac='52:54:00:e3:4b:4a' name='node4' ip='192.168.0.204'/>
    </dhcp>
  </ip>
</network>

来宾 xml...

<interface type='bridge'>
  <mac address='52:54:00:13:3a:69'/>
  <source bridge='br0'/>
</interface>

主机上的 ifconfig...

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.0.2  netmask 255.255.255.0  broadcast 192.168.0.255
    ether 52:54:00:54:b1:e4  txqueuelen 1000  (Ethernet)
    RX packets 552  bytes 41699 (41.6 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 240  bytes 26714 (26.7 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.13  netmask 255.255.255.0  broadcast 192.168.1.255
    inet6 fe80::2e76:8aff:fea9:7e5e  prefixlen 64  scopeid 0x20<link>
    ether 2c:76:8a:a9:7e:5e  txqueuelen 1000  (Ethernet)
    RX packets 3679  bytes 1174123 (1.1 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 4101  bytes 410899 (410.8 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

客户端上的 ifconfig...

ens3  Link encap:Ethernet  HWaddr 52:54:00:13:3a:69
      inet addr:192.168.0.201  Bcast:192.168.0.255  Mask:255.255.255.0
      inet6 addr: fe80::5054:ff:fe13:3a69/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:191 errors:0 dropped:0 overruns:0 frame:0
      TX packets:335 errors:0 dropped:0 overruns:0 carrier:0
      collisions:1605 txqueuelen:1000
      RX bytes:22402 (22.4 KB)  TX bytes:34822 (34.8 KB)

lo    Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:8530 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8530 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1
      RX bytes:1766049 (1.7 MB)  TX bytes:1766049 (1.7 MB)

brctl 显示...

bridge name     bridge id               STP enabled     interfaces
br0             8000.52540054b1e4       yes             br0-nic

网络状态监测...

Kernel IP routing table
Destination   Gateway       Genmask         Flags  MSS Window  irtt Iface
0.0.0.0       192.168.1.1   0.0.0.0         UG       0 0          0 enp3s0f0
192.168.0.0   0.0.0.0       255.255.255.0   U        0 0          0 br0
192.168.1.0   0.0.0.0       255.255.255.0   U        0 0          0 enp3s0f0
192.168.1.1   0.0.0.0       255.255.255.255 UH       0 0          0 enp3s0f0

客人可以 ping 通主人,也可以互相 ping 通。

答案1

目前,您的网桥和任务位于与主子网不同的子网上。因此,您的任务无法访问互联网,因为没有通往网关的路径。将所有内容放在同一个子网上。来自我的主要主机的示例:

主主机 ifconfig。请注意 enp3s0 甚至没有显示 IP 地址。这是因为它桥接到 br0,并且两者都具有相同的 IP 地址。忽略 lxcbr0 和 virbr0,它们不是本次讨论的一部分,我也不会使用它们(仅为完整性显示)。

doug@s15:~$ ifconfig
br0       Link encap:Ethernet  HWaddr f4:6d:04:65:2d:8e
          inet addr:192.168.111.112  Bcast:192.168.111.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4574 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2604 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:509690 (509.6 KB)  TX bytes:425082 (425.0 KB)

enp3s0    Link encap:Ethernet  HWaddr f4:6d:04:65:2d:8e
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4574 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2604 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:573726 (573.7 KB)  TX bytes:426090 (426.0 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:174 errors:0 dropped:0 overruns:0 frame:0
          TX packets:174 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12644 (12.6 KB)  TX bytes:12644 (12.6 KB)

lxcbr0    Link encap:Ethernet  HWaddr 00:16:3e:00:00:00
          inet addr:10.0.3.1  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:21:9e:43
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

这是我的主主机接口文件,其中 br0 桥接到 enp3s0:

doug@s15:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface and bridge
auto br0
iface br0 inet dhcp
#iface br0 inet static
#  address 192.168.111.112
#  network 192.168.111.0
#  netmask 255.255.255.0
#  gateway 192.168.111.1
#  broadcast 192.168.111.255
#  dns-search smythies.com
#  dns-nameservers 192.168.111.1
  bridge_ports enp3s0
  bridge_fd 9
  bridge_hello 2
  bridge_maxage 12
  bridge_stp off

这是典型访客的网络部分。我分配 MAC,因为我根据 MA​​C 从 DHCP 服务器分配 IP 地址,然后我的 DNS 内容按我想要的方式工作。

<interface type='bridge'>
  <mac address='52:54:00:14:ff:9c'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

这是路由。我的 LAN 上的所有内容都在 192.168.111.XXX 子网上,因此存在通过 br0 往返网关的路径:

doug@s15:~$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.111.1   0.0.0.0         UG        0 0          0 br0
10.0.3.0        0.0.0.0         255.255.255.0   U         0 0          0 lxcbr0
192.168.111.0   0.0.0.0         255.255.255.0   U         0 0          0 br0
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

相关内容