Ubuntu and Netplan: gotchas

I finally figured out a networking configuration problem on my Ubuntu 20.04 system.

In theory all Ubuntu systems since 2017 have been configured with Netplan. It’s some simplified high level configuration language that systemd applies. Like any Unix thing built after 1993 or so I reflexively hate it, I kinda miss the old days of /etc/interfaces and hacking stuff in /etc/rc.local. But I gotta admit Netplan is pretty good. When it works; the problem I’ve had is my config gets overridden.

The first problem is cloud-init, some thing that Ubuntu ships to configure “cloud servers” from yet other files. I believe default Ubuntu systems are configured via /etc/netplan/50-cloud-init but if you edit that file, joke’s on you; it gets rewritten by something else. The solution is to create a file /etc/cloud/cloud.cfg.d/99-custom-networking.cfg with the contents network: {config: disabled}. That will prevent cloud-init from rewriting your files.

Having done that you can either delete 50-cloud-init or replace it with your own stuff. Note that config files are additive; I ended up configuring my ethernet twice until removing the cloud-init file.

The bigger problem I ran into is that I had a dhcpcd installed, the package dhcpcd5. I don’t quite know why, it’s probably something I did manually. But if that’s installed it will override the netplan files. You can have dhcp4: no right there in your netplan file and dhcpcd will still override your static configuration. I fixed this by uninstalling dhcpcd. I think the modern systemd world uses dh-client anyway.

Once that’s done netplan seems to operate as it’s supposed to, without mysterious other things overriding my configuration.