2

I'm running Ubuntu 18.04 64-bit server. I do a clean install, set up all of my custom software, and all is good. I use clonezilla to create a master image, which I later clone. I deal with the machine-id file so that cloned instances on new hardware get a new MAC address and IP address. My issue is that now, on some recent hardware, the ethernet interface name is coming up different than on the original cloned image. So DHCP will not work automatically for example, because the config file in /etc/netplan is specifying the interface name of the old hardware, not the new hardware.

Is there a way to cause netplan to auto-config things on boot? Maybe remove all the yaml files in /etc/netplan? The issue is that the cloned image contains a netplan yaml file with configuration that do not apply to the new hardware. This must be a simple thing to fix, but I've failed to find it in searches online and in this forum. Thanks for any help!

MGD
  • 41
  • "I do a clean install, set up all of my custom software, and all is good." --- perhaps you'd have a look at cloud-init; have a look at (the second handles some network/dhcp issues) https://help.ubuntu.com/community/CloudInit https://askubuntu.com/questions/1040820/what-are-the-use-cases-for-cloud-init https://cloudinit.readthedocs.io/en/latest/topics/merging.html – d1bro Jun 22 '20 at 20:01
  • Thanks for the links. We were purposely not using cloud-init, we wanted a lighter install as this is for a fairly locked down medical device ultimately, so the fewer packages to keep track of the better. Previously (we started with 16.04) we were using systemd networking directly and it seemed perfectly happy to enable dhcp by default no matter what the interface name was at boot. We are ok with netplan being installed, as long as we can trigger some sort of re-scan to set up the config correctly, or use a minimal netplan config maybe. – MGD Jun 23 '20 at 00:32
  • a systemd job running before netplan gets called, that runs sed s/enOLD/$(ip -a | grep en | sed <egex limbo>)/ /etc/netplan/WHATEVER.yaml -- would be what would come to my mind; the $(..) part could be a separat thing that gets passed as variable? – d1bro Jun 23 '20 at 00:54
  • or perhaps use the match: property in the original setup? - see https://netplan.io/reference#common-properties-for-physical-device-types – d1bro Jun 23 '20 at 01:14

1 Answers1

2

Got it working. db429's suggestion to use match was the answer (I'd give you credit but as a new user I could not figure it out).

Here's the new netplan config I'm using now:

# generic ethernet adapter config, matches any interface names beginning with "en"
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      match:
        name: en*
      dhcp4: yes

Basically, at early boot, netplan reads this config, and generates a file in /run/systemd/network called 10-netplan-eth0.network Note the eth0 in the file name which matches the block I provided in the netplan yaml config file.

The generated contents of 10-netplan-eth0.network are:

[Match]
Name=en*

[Network] DHCP=ipv4 LinkLocalAddressing=ipv6

[DHCP] RouteMetric=100 UseMTU=true

This generated network file is then used correctly to initialize any matching interfaces with dhcp. This .network file can also be used directly by systemd-networkd and in fact netplan.io could be removed later (I tested that also, as systemd-networkd is enabled on my server).

MGD
  • 41
  • my use of eth0 was a bad choice, I would recommend something more generic, like enwild or something. – MGD Jun 23 '20 at 14:12