4

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?

RCH
  • 43
  • 1
  • 3

2 Answers2

6

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).

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
6

This is possible using a match rule within the netplan config, for those who'd prefer to keep it all in one place. Here's a simple solution I've been using in my pre-configured images for USB interfaces with varying device names:

/etc/netplan/01-netcfg.yaml:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth:
      match:
        name: en*
      dhcp4: yes

Further details here: Netplan reference

nospi
  • 61
  • 1
  • 2