Score:1

Set OVS interface MAC via netplan

xk flag

I have set up an ovs bridge in order to take advantage of libvirt's virtual network with vlan support. As recommended, the host network interface is configured on an ovs port, rather than directly on the bridge. The host nic receives tagged and untagged traffic. The latter for the host's own interface. I also wish for that interface to have a specific MAC.

How to do the equivalent of ovs-vsctl set interface vlan0 mac=\"00:11:22:33:44:55\" in netplan?

I am unsure how to target the ovs interface config within the vlan0 openvswitch: section.

mac: and other-config:hwaddr are invalid/ineffective options for ovs port.

So far:

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]

Or is this not possible in netplan yaml and I should resort to networkd-dispatcher hook scripts?

EDIT: Using networkd-dispatcher and removing deprecated options, I now have this config, which works for me. It would be good to know if the additional openvswitch commands are supported inside netplan yaml config, to keep it all in one place.

  • 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\"
Score:0
in flag

Netplan does not currently allow to set the MAC address directly using ovs-vsctl set [...] mac=...

But you should be able to set the desired MAC address using the networkd backend renderer, by adding a macaddress: 00:11:22:33:44:55 stanza. You can also get it into 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]

After running netplan apply, this produces the following output for me:

$ 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"
darcey avatar
xk flag
Thanks Lukas. I've tried both those methods separately and combined. No variation resulted in success. I believe systemd/networkd needs to be invoking `ovs-vsctl set interface vlan0 mac=...` somewhere along the line and I don't see that in the journal (as I do with the hook script). I am guessing you may see this. What netplan/systemd versions?
darcey avatar
xk flag
I now seem to have this working using the your netplan config after all. Thanks!
darcey avatar
xk flag
I am not certain my previous comment was correct. I believe your config appeared to work for me because ovs had preserved mac config created earlier by my hookscript. If I remove the OVS db, in /var/lib/openvswitch, and clean boot, then run `netplan apply`, it does not produce the anticipated MAC for vlan0.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.