Just spent hours diagnosing why my 18.04 VM wouldn't connect network after moving from VirtualBox to qemu.
Turns out that because of "hardware change", NIC got renamed from enp0s4 to enp1s0. And - naturally - /etc/netplan/01-netcfg.yaml specified explicitly that enp0s4 should get DHCP configuration, but not (anything else).
Comparing this to a freshly installed - and working - 19.04 didn't really help as 19.04 uses something else to configure the network. eh...
Anyway - Why is this? I have noticed such a change before, for example when I was upgrading BIOS on my motherboard. But every time this happens, I spend a lot of time diagnosing such an issue. Especially because it happens so rarely...
So, what causes this rename and how would I go about configuring my Ubuntu VMs such that this would no longer be an issue?
Explanation how the name is created can be found in src/udev/udev-builtin-net_id.c:
enp0s4
means ethernet, bus 0, slot 4.enp1s0
means ethernet, bus 1, slot 0.So the name changes when the bus or the slot changes. It refers to the PCI device. See ...
for a list of PCI devices. In my case that would be for my ethernet: port 4, slot 0, function 1. And for my wireless: port 3, slot 0. See ...
There are 4 methods; 2 of them are to use your own names (see
/etc/udev/rules.d/70-my-net-names.rules
) or use the MAC address (cp /usr/lib/udev/rules.d/80-net-setup-link.rules /etc/udev/rules.d/80-net-setup-link.rules
and edit the file as needed for you situation). Both have you set up an interface name that generally would not change (well you could change the MAC address on some NICs ;) )