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?
1 Answer
Explanation how the name is created can be found in src/udev/udev-builtin-net_id.c:
* Two character prefixes based on the type of interface: * en -- ethernet * sl -- serial line IP (slip) * wl -- wlan * ww -- wwan * * Type of names: * b<number> -- BCMA bus core number * ccw<name> -- CCW bus group name * o<index>[d<dev_port>] -- on-board device index number * s<slot>[f<function>][d<dev_port>] -- hotplug slot index number * x<MAC> -- MAC address * [P<domain>]p<bus>s<slot>[f<function>][d<dev_port>] * -- PCI geographical location * [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>] * -- USB port number chainenp0s4means ethernet, bus 0, slot 4.enp1s0means ethernet, bus 1, slot 0.- (if there is an f that refers to "function". A 3rd subset of the device)
So the name changes when the bus or the slot changes. It refers to the PCI device. See ...
$ for i in `seq 2 5`; do lspci -s 0${i}:; done
03:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01)
04:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTL8411B PCI Express Card Reader (rev 01)
04:00.1 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 12)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 ...
$ networkctl
IDX LINK TYPE OPERATIONAL SETUP 1 lo loopback n/a unmanaged 2 enp4s0f1 ether n/a unmanaged 3 wlp3s0 wlan n/a unmanaged how would I go about configuring my Ubuntu VMs such that this would no longer be an issue?
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 ;) )