通过 netplan 设置 OVS 接口 MAC

通过 netplan 设置 OVS 接口 MAC

我已设置 ovs 桥接器,以便利用 libvirt 的虚拟网络和 VLAN 支持。根据建议,主机网络接口配置在 ovs 端口上,而不是直接配置在桥接器上。主机网卡接收标记和未标记的流量。后者用于主机自己的接口。我还希望该接口具有特定的 MAC。

如何ovs-vsctl set interface vlan0 mac=\"00:11:22:33:44:55\"在 netplan 中做等效操作?

我不确定如何在 vlan0openvswitch:部分中定位 ovs 接口配置。

mac:并且other-config:hwaddr对于 ovs 端口来说是无效的/无效的选项。

迄今为止:

network:
  version: 2

  ethernets:
    enp0s31f6: {}

  bridges:
    ovsbr0:
      interfaces: [enp0s31f6]
      openvswitch: {}

  vlans:
    vlan0:
      id: 0
      link: ovsbr0
      openvswitch: {}
      addresses: [192.168.0.11/24]
      gateway4: 192.168.0.1
      nameservers:
        search: [home.lan]
        addresses: [192.168.0.10]

或者这在 netplan yaml 中是不可能的,我应该求助于 networkd-dispatcher 钩子脚本?

编辑:使用 networkd-dispatcher 并删除弃用的选项后,我现在有了这个配置,它对我有用。如果知道 netplan yaml 配置中是否支持其他 openvswitch 命令,那就太好了,这样就可以将它们全部放在一个地方。

  • Ubuntu 20.04.5
  • openvswitch-switch 2.13.8-0ubuntu1.1
  • netplan.io 0.104-0ubuntu2~20.04.2
#/etc/netplan/01-ovsbr0.yaml
network:
  version: 2
  renderer: networkd

  ethernets:
    enp0s31f6: {}

  bridges:
    ovsbr0:
      interfaces: [enp0s31f6]
      link-local: []
      openvswitch: {}

  vlans:
    vlan0:
      id: 0
      link: ovsbr0
      openvswitch: {}
      addresses: [192.168.0.11/24]
      routes:
        - to: default
          via: 192.168.0.1
      nameservers:
        search: [home.lan]
        addresses: [192.168.0.10]
#!/bin/sh
#/etc/networkd-dispatcher/configuring.d/99-vlan0-mac.sh

IFACE_MATCH='vlan0'
MAC='00:11:22:33:44:55'
[ "$IFACE" = "$IFACE_MATCH" ] && /usr/bin/ovs-vsctl set interface $IFACE mac=\"$MAC\"

答案1

Netplan 目前不允许使用以下方式直接设置 MAC 地址ovs-vsctl set [...] mac=...

但是您应该能够通过添加节来使用 networkd 后端渲染器设置所需的 MAC 地址macaddress: 00:11:22:33:44:55。您还可以将其放入other-config

#/etc/netplan/01-ovsbr0.yaml
network:
  version: 2
  renderer: networkd

  ethernets:
    enp0s31f6: {}

  bridges:
    ovsbr0:
      interfaces: [enp0s31f6]
      link-local: []
      openvswitch: {}

  vlans:
    vlan0:
      id: 0
      link: ovsbr0
      macaddress: "00:11:22:33:44:55"
      openvswitch:
        other-config:
          hwaddr: "00:11:22:33:44:55"
      addresses: [192.168.0.11/24]
      routes:
        - to: default
          via: 192.168.0.1
      nameservers:
        search: [home.lan]
        addresses: [192.168.0.10]

运行后netplan apply,会产生以下输出:

$ ip l show vlan0
5: vlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
$ ovs-vsctl list Interface vlan0 | grep 00:11:22:33:44:55
external_ids        : {netplan="true", "netplan/other-config/hwaddr"="00:11:22:33:44:55"}
mac_in_use          : "00:11:22:33:44:55"
other_config        : {hwaddr="00:11:22:33:44:55"}
$ ovs-vsctl show
2a78b99d-e009-40c8-9598-43b5581c5999
    Bridge ovsbr0
        fail_mode: standalone
        Port ovsbr0
            Interface ovsbr0
                type: internal
        Port eth0
            Interface eth0
        Port vlan0
            tag: 0
            Interface vlan0
                type: internal
    ovs_version: "3.1.0"

相关内容