Well, this looks like a bug on 20.04. .network
files are meant to be processed in lexical order, according to this extract from the systemd-networkd
docs:
The .network files are read from the files located in the system
network directories /usr/lib/systemd/network and
/usr/local/lib/systemd/network, the volatile runtime network directory
/run/systemd/network and the local administration network directory
/etc/systemd/network. All configuration files are collectively sorted
and processed in lexical order, regardless of the directories in which
they live.
However, if I turn on systemd-networkd
debugging (see here if you don't know how), it turns out that the lowest-lexically-sorted file has precedence. I can't be entirely sure, because the logs don't show the processing order, and only stop at the first hit for the relevant network interface.
This is what I know, for the plain Ubuntu 20.04 server install:
- There are 5
.network
files across the system
- One of these is created by netplan at runtime, and is
/run/systemd/network/10-netplan-enp1s0.network
- My new file is
/etc/systemd/network/static.network
- On
systemctl restart systemd-networkd
the netplan file takes precedence over my own
- If I manually remove the netplan file, and restart networking, my file is acted on. However, this is only temporary till the next reboot
- If I rename my file to
05-static.network
then it takes precedence over the netplan file
Ergo, processing order broken, unless I'm doing something stupid.
As a temporary fix you need to give your file a low lexical order by prefixing with something like 05-
. However, this might break on a future update if the processing order is reversed. A better fix would be to disable netplan (not sure how to do this), but this might also break if something else then decides it has to create a .network
file to make up for the missing netplan one.
Edit - removing netplan
You can remove netplan entirely with apt purge netplan.io
. However, this may not be a good idea - it also removes cloud-init
, for example, which is required by DigitalOcean. So:
# cd /etc/netplan
# rm 00-installer-config.yaml
# netplan apply
After a reboot, you no longer get the auto-generated .network
file, and can use normal file naming in your .network
files without a conflict.