Ubuntu 26.04, KVM, netplan, and NetworkManager

Ubuntu has been getting less usable year by year ever since moving to systemd init. This year, the new papercut is that NetworkManager will violently conflict with–and override–anything you set in /etc/netplan, unless you manually tell it to bugger off.

This is a particular problem on systems that need network bridges (like KVM hosts), since NetworkManager will confidently blow away any consistent configuration you’ve done in /etc/netplan, in favor of the “duh, let’s DHCP every NIC we can find, this is probably just somebody’s laptop” defaults NetworkManager assumes you’ll want… despite having manually configured the interfaces already!

Configuration changes

Short version follows. Here’s your /etc/netplan/00-installer-config.yaml, assuming you’ve got two interfaces named enp67s0 and enp69s0, and would like to create a bridge named br0:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp67s0:
      dhcp4: false
      dhcp6: false
    enp69s0:
      dhcp4: false
      dhcp6: false
  bridges:
    br0:
      interfaces: [ enp67s0, enp69s0 ]
      dhcp4: true
      dhcp6: false
      # or if you want to static the interface, after setting dhcp4 to false:
      #addresses: [ x.x.x.x/yy ]
      #nameservers:
      #  addresses: [ 8.8.8.8,1.1.1.1 ]
      #routes:
      #  - to: default
      #    via: x.x.x.x

So far, so good–but if you want a desktop interface available on this system, you’ll need to tell NetworkManager to leave your wired interfaces the hell alone. You do this by creating a new file, /etc/NetworkManager/conf.d/99-unmanaged-devices.conf:

[keyfile]
unmanaged-devices=interface-name:enp67s0
unmanaged-devices=interface-name:enp69s0

In theory, once you’ve done this a simple sudo networkctl reload and sudo netplan apply will get you sorted–but I strongly recommend actually rebooting and verifying that your netplan configs are both applied and stay applied, since in my experience, running sudo netplan apply will work for the moment whether you’ve successfully nerfed NetworkManager or not.

Troubleshooting tips

If you still aren’t seeing the output you expect from ip a after the reboot, here are some troubleshooting tips:

  • bridge link show returns no output if your bridge is down, or something along the lines of 2: enp69s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100 if the bridge is up and running.
  • networkctl status will show you lines like Foreign process ‘NetworkManager[3938]’ changed… if NetworkManager is screwing around with your configs.
  • If you need more a more verbose version of the above, try sudo journalctl -xeu systemd-networkd
  • If all else fails, just disable NetworkManager entirely. I wouldn’t recommend removing it–removing parts of the ubuntu-desktop metapackage can sometimes cause apt autoremove to try to nuke the entire desktop later–but a simple systemctl disable NetworkManager && systemctl stop NetworkManager will keep it from running and interfering with your wired configs–only potential issue there being losing the convenience of using the GUI to connect to Wi-Fi networks. But if you’re not using Wi-Fi on the system… this might be the easiest win.

Recommended additional steps

While you’re at it, go ahead and systemctl mask systemd-networkd-wait-online and systemctl mask NetworkManager-wait.online to disable the unlimited length timeouts for each of those services, which will otherwise add 120 entirely useless seconds to every single boot of your system.

Published by

Jim Salter

Mercenary sysadmin, open source advocate, and frotzer of the jim-jam.

Leave a Reply

Your email address will not be published. Required fields are marked *