为什么使用 Debian 10.5 时,我的以太网接口没有在启动时添加到 openvswitch 桥中?

为什么使用 Debian 10.5 时,我的以太网接口没有在启动时添加到 openvswitch 桥中?

我正在设置一个带有两个以太网接口的 kvm/qemu/libvirt 主机 (debian buster 10.5):eno1用于主机流量和eno2虚拟机流量。eno2连接到承载 VLAN 4、7、221 和 800 的中继交换机端口。的设置eno1由 systemd-networkd 完成。对于 openvswitch 配置,我似乎必须依赖 osv-extensions(参见/usr/share/doc/openvswitch-switch/README.Debian.gz

所以我把它放进去了/etc/network/interfaces

auto lo
iface lo inet loopback

iface eno1 inet manual

allow-ovs br0
iface br0 inet manual
    ovs_type OVSBridge
    ovs_ports eno2
    pre-up ip link set $IFACE up
    post-down ip link set $IFACE down

allow-br0 eno2
iface eno2 inet manual
    ovs_bridge br0
    ovs_type OVSPort
    pre-up ip link set $IFACE up
    post-up ovs-vsctl add-port br0 $IFACE
    post-down ip link set $IFACE down

这让我

ovs-vsctl show
0946b4ce-fb87-4fb5-84fd-c9fec7d7dbd5
    Bridge "br0"
        Port "vnet1"
            tag: 800
            Interface "vnet1"
        Port "br0"
            Interface "br0"
                type: internal
        Port "vnet0"
            tag: 800
            Interface "vnet0"
    ovs_version: "2.12.0"

vnet0 和 vnet1 是虚拟机。顺便说一下,这是相应网络的 XML:

<network connections='2'>
  <name>guest-network</name>
  <uuid>c6c325fb-cd95-4d1a-971a-dc241c2c853e</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
  <virtualport type='openvswitch'/>
  <portgroup name='vlan-4'>
    <vlan>
      <tag id='4'/>
    </vlan>
  </portgroup>
  <portgroup name='vlan-7'>
    <vlan>
      <tag id='7'/>
    </vlan>
  </portgroup>
  <portgroup name='vlan-800'>
    <vlan>
      <tag id='800'/>
    </vlan>
  </portgroup>
  <portgroup name='vlan-all'>
    <vlan trunk='yes'>
      <tag id='4'/>
      <tag id='7'/>
      <tag id='221'/>
      <tag id='800'/>
    </vlan>
  </portgroup>
</network>

如果我手动激活 eno2 接口,ip link set eno2 up我会得到

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 34:48:ed:f0:a9:e8 brd ff:ff:ff:ff:ff:ff
    inet 195.37.235.117/26 brd 195.37.235.127 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::3648:edff:fef0:a9e8/64 scope link
       valid_lft forever preferred_lft forever
3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 34:48:ed:f0:a9:e9 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3648:edff:fef0:a9e9/64 scope link
       valid_lft forever preferred_lft forever
4: ovs-system: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 36:97:3a:8e:fd:fb brd ff:ff:ff:ff:ff:ff
5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether 36:66:8b:eb:9a:42 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3466:8bff:feeb:9a42/64 scope link
       valid_lft forever preferred_lft forever
6: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 1000
    link/ether fe:ad:be:ef:02:02 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fcad:beff:feef:202/64 scope link
       valid_lft forever preferred_lft forever
7: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 1000
    link/ether fe:ad:be:ef:01:01 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fcad:beff:feef:101/64 scope link
       valid_lft forever preferred_lft forever

为什么 eno2 没有出现在 br0 上?最好的方法是告诉 /etc/network/interfaces eno2 应该处于 UP 状态才能使用该pre-up符号吗?我想使用 openvswitch 数据库来让我的配置在重启后生效

如果我手动将 eno2 添加到 br0,ovs-vsctl add-port br0 eno2我的设置就可以工作,并且我的虚拟机可以访问网络。

答案1

对于那些遇到同样问题的人:ifupdown 支持pre-up/up/post-up直接在 中挂钩/etc/network/interfaces。没有意外/etc/network/if-post-up.d

    # the configuration for eno2 may be completely removed from this file
    auto vmbr0
    iface vmbr0 inet manual
    ovs_type OVSBridge
    pre-up ip link set eno2 up
    pre-up ovs-vsctl add-port vmbr0 eno2

答案2

这可以通过创建目录来完成/etc/network/if-post-up.d

mkdir /etc/network/if-post-up.d

使用文件(例如/etc/network/if-post-up.d/05-configure-eno2)并执行其中的手动步骤:

#!/bin/bash
ip link set eno2 up
ovs-vsctl add-port br0 eno2

并使其可执行

chmod +x /etc/network/if-post-up.d/05-configure-eno2

这不是一个好的解决方案,因为它违反了最小惊喜规则。没有人会自己找到那个脚本。/etc/network/interfaces最好有一个可行的解决方案。

相关内容