Ubuntu – way to automatically add network interfaces to systemd-networkd and/or netplan

systemdsystemd-networkdUbuntu

I'm currently building pre-configured disk images for Ubuntu 18.04 servers. While the hardware is mostly the same, there are a few different network interfaces between the devices (and some are virtual machines rather than bare metal). Because of this I don't know exactly what network devices will be present beforehand or what they will be called (some have a single one called ens33, others have multiples called eno1, eno2, etc.)

systemd-networkd doesn't automatically bring up interfaces on, they have to be explicitly specified in config files.

I'm currently bypassing this by using NetworkManager instead of networkd since it will automatically bring up any interfaces it finds, but considering the Ubuntu installer seems to automatically add any interfaces it finds to netplan's config, I figure there must be a way to setup a service or something that does the same thing at startup. Anyone know a way to do this?

Best Answer

systemd-networkd can apply a configuration to multiple interfaces at once, using a wildcard [Match].

For example:

# cat /etc/systemd/network/99-wildcard.network
[Match]
Name=en*

[Network]
DHCP=yes

This will bring up DHCP on any interface whose name starts with en (which is every wired interface).