如何配置虚拟机管理程序,以便 KVM/QEMU 虚拟机可以到达连接到同一中继桥的主机?

如何配置虚拟机管理程序,以便 KVM/QEMU 虚拟机可以到达连接到同一中继桥的主机?

1 问题

我的目标是让所有 LAN 流量都通过充当路由器和防火墙的虚拟机 (VM) 进行路由。同一虚拟机管理程序上的其他虚拟机也应通过防火墙虚拟机进行路由。请参阅以下内容网络草图。连接到中继桥的物理主机可以成功互相 ping 通,但尚无法访问虚拟机。

2 详细信息

虚拟机管理程序上的网络配置:

# =======
# Bridges
# =======
# ---------------------
# VLAN bridge br-vlan-3
# ---------------------
ip link add name br-vlan-3 type bridge
ip addr add 10.66.3.11/24 dev br-vlan-3
ip link set dev br-vlan-3 up

# ---------------------
# Trunk bridge Upstream
# ---------------------
ip link add name br-trunk-up type bridge vlan_filtering 1 vlan_default_pvid 0
ip link set br-trunk-up up

# ---------------
# Trunk bridge VM
# ---------------
ip link add name br-trunk-vm type bridge vlan_filtering 1 vlan_default_pvid 0
ip link set br-trunk-vm up

# =====
# Hosts
# =====

# Set physical devices up
ip link set enp5s0 up
ip link set enp9s0f0 up
ip link set enp9s0f1 up
ip link set enp9s0f2 up
ip link set enp9s0f3 up


# ----------------------
# desktop.3 br-vlan-3
# ----------------------
ip link add link enp9s0f1 name enp9s0f1.3 type vlan id 3
ip link set dev enp9s0f1.3 master br-vlan-3
ip link set enp9s0f1.3 up

# --------------------------
# desktop.100 br-trunk-vm
# --------------------------
ip link add link enp9s0f1 name enp9s0f1.100 type vlan id 100
ip link set enp9s0f1.100 master br-trunk-vm
ip link set enp9s0f1.100 up
bridge vlan add vid 100 dev enp9s0f1.100 master
bridge vlan add vid 100 dev br-trunk-vm self

bridge vlan add vid 100 dev fw.100 pvid 100

网络图

=======
DESKTOP
=======
localhost:user ~ $  ip a
2: enp34s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:c4:b1:af brd ff:ff:ff:ff:ff:ff
4: br-vlan-100: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 1a:b1:36:43:f0:e4 brd ff:ff:ff:ff:ff:ff
    inet 10.66.100.44/24 scope global br-vlan-100
       valid_lft forever preferred_lft forever
7: enp.100@enp34s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-vlan-100 state UP group default qlen 1000
    link/ether 00:d8:61:c4:b1:af brd ff:ff:ff:ff:ff:ff
    
localhost:~ # cat /proc/net/vlan/enp.100 
enp.100  VID: 100        REORDER_HDR: 1  dev->priv_flags: 1221
         total frames received            0
          total bytes received            0
      Broadcast/Multicast Rcvd            0

      total frames transmitted          287
       total bytes transmitted        53964
Device: enp34s0
INGRESS priority mappings: 0:0  1:0  2:0  3:0  4:0  5:0  6:0 7:0
 EGRESS priority mappings: 


==========
HYPERVISOR
==========
bridge name     bridge id               STP enabled     interfaces
br-vlan-100             8000.1ab13643f0e4       no              enp.100

[root@fedora system]# ip a  
4: enp9s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether a0:36:9f:5d:09:19 brd ff:ff:ff:ff:ff:ff
13: br-trunk-vm: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 56:7e:22:6a:23:2d brd ff:ff:ff:ff:ff:ff
16: enp9s0f1.100@enp9s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-trunk-vm state UP group default qlen 1000
    link/ether a0:36:9f:5d:09:19 brd ff:ff:ff:ff:ff:ff
21: fw.100: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-trunk-vm state UNKNOWN group default qlen 1000
    link/ether fe:54:00:3e:97:72 brd ff:ff:ff:ff:ff:ff
    
    
[root@fedora system]# brctl show dev br-trunk-vm
bridge name     bridge id               STP enabled     interfaces
br-trunk-vm             8000.567e226a232d       no              enp9s0f1.100
                                                        fw.100
                                                        fw.103
                                                        fw.3


===============
VIRTUAL MACHINE 
===============                                                                    
[root@fedora system]# bridge vlan show
port              vlan-id  
br-trunk-vm       100
enp9s0f1.100      100
virbr0            1 PVID Egress Untagged
fw.100            100 PVID Egress Untagged


2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:3e:97:72 brd ff:ff:ff:ff:ff:ff
    inet 10.66.100.10/24 scope global enp1s0
       valid_lft forever preferred_lft forever

防火墙虚拟机的 Libvirt XML 网络配置:

<interface type='bridge'>
  <mac address='52:54:00:3e:97:72'/>
  <source bridge='br-trunk-vm'/>
  <target dev='fw.100'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>

3次尝试

我尝试在防火墙虚拟机上配置带标记和不带标记的 NIC。对于带标记的 NIC,我在防火墙虚拟机上创建了一个 VLAN 桥,并从虚拟分接头创建了一个虚拟分接头设备,fw.100VLAN 为 100:。[email protected]然后我将 的中继端口设置[email protected]为 master:。对于不带标记的 NIC 方法,我在防火墙虚拟机上未配置 VLAN,并将其中继端口设置为 PVID 100 不带标记。在这两种情况下,我都无法在桌面主机和防火墙虚拟机之间 ping 通。bridge vlan add vid 100 dev [email protected] masterbridge vlan add vid 100 dev fw.100 pvid 100 untagged

此问题仅发生在 libvirt KVM/QEMU 虚拟机中。作为主机连接到虚拟机管理程序的中继桥的两个物理 VLAN 标记主机可以相互 ping 通。

4 更新

看起来 libvirt 不支持具有 VLAN 的 Linux 桥接器。根据以下文章,如果虚拟机管理程序上有第二个具有相同 VLAN 的虚拟设备,则虚拟机 VLAN 将停止工作:https://alesnosek.com/blog/2015/09/07/bridging-vlan-trunk-to-the-guest/

或者可以使用 openvswitch,但为每个虚拟机和物理主机使用一个桥接器是更好的方法。然后,虚拟机管理程序允许将虚拟机和主机的桥接器转发到防火墙虚拟机的桥接器,其余的路由则在防火墙虚拟机内完成。

相关内容