๐Ÿ”Œ ens192 became eth0: netplan after a VMware to Hyper-V move

A real incident, and a lab that reproduces the mechanism: a netplan file that names an interface that no longer exists, and what DNS does while the machine is half configured.

Moving Ubuntu servers from VMware to Hyper-V, the network card changed its name from ens192 to eth0. The netplan file still said ens192, so it matched nothing. DNS then worked only some of the time, apt in particular. Changing ens192 to eth0 in the file made everything normal again.

ip -br link                         what the interface is called now
networkctl list                     SETUP "unmanaged" means no netplan file matched it
sudo netplan get                    what netplan thinks the config is, all files merged
resolvectl status                   which DNS servers each link really has
grep -rn ens192 /etc/netplan/       find every file that still names the old interface

Netplan matches a config block to a network card by its name (or by a MAC address if you say so). When the name changes and nothing else does, the block silently stops applying. There is no error. This page reproduces that in a lab, shows the half-configured state that makes DNS flaky, and gives two fixes.

What happened at work is the starting point of this page, reported by the person who fixed it: The servers had a static IP address and used Active Directory for their DNS. Hyper-V presented a synthetic network card and supplied DNS while the server was being moved, the interface name in the netplan file changed from ens192 to eth0, name resolution failed intermittently (apt was the visible symptom), and after the name in the file was changed to eth0 everything worked normally again. Hyper-V itself was not available for the lab. The rename is imitated with a udev link file, and the Hyper-V-supplied DNS is imitated with the DHCP server of the lab network. So the lab shows the mechanism, not Hyper-V's own behaviour. The section "What was not run" says exactly what that means.

Everything else below was run for real on Ubuntu 24.04 (netplan.io 1.1.2, systemd 255) in a virtual machine.

Why the name changes

Ubuntu uses predictable interface names. On VMware a virtual card sits at a fixed PCI slot, and the name is built from that slot, which is how ens192 comes about (slot 192). A different hypervisor puts the card on a different bus path, or uses a different driver, so the same rule gives a different name or no slot-based name at all. On Hyper-V guests the name is commonly eth0. Treat that as the usual pattern, not a promise: it was not checked in this lab, and the name you get depends on the hypervisor, the driver and the udev rules on the machine.

Why that breaks netplan: a block in /etc/netplan/*.yaml is keyed by an interface name.

network:
  version: 2
  ethernets:
    ens192:
      addresses: [10.30.1.50/24]
      routes:
        - to: default
          via: 10.30.1.2
          metric: 50
      nameservers:
        addresses: [172.17.0.2]
        search: [corp.example]

This file says "the card called ens192 gets 10.30.1.50 and this DNS server". If no card is called ens192 any more, the block applies to nothing. Netplan does not complain, because a config for a card that is not there yet (a USB adapter, a VLAN, a card that is plugged in later) is legitimate.

The lab

One Ubuntu 24.04 virtual machine (QEMU). It has a management NIC with its own name so that SSH keeps working, and a second NIC that plays the server's real network card. A systemd link file gives that second card the VMware-style name, and later the Hyper-V-style one:

$ cat /etc/systemd/network/10-vmware-name.link
[Match]
MACAddress=52:54:00:bb:01:01

[Link]
Name=ens192

The "company DNS" stands in for the Active Directory DNS servers. It is a dnsmasq container that answers repo.corp.example and forwards everything else. It is not Active Directory, and nothing in the lab is joined to a domain. The "Hyper-V supplied DNS" is the DHCP server of the lab network, which knows public names but not the company's. In a real move you will probably have only one NIC, so a mistake here costs you SSH access too: do this change from a console, not over SSH.

Versions:

Ubuntu 24.04.5 LTS
netplan.io 1.1.2-8ubuntu1~24.04.3
systemd 255 (255.4-1ubuntu8.18)

Step 0: before the move

A working server with a static address, like the one at work. The card is ens192, the netplan file matches it, the company DNS is the only DNS server on the link, and both internal and public names resolve.

$ ip -br addr show ens192
ens192           UP             10.30.1.50/24 fec0::5054:ff:febb:101/64 fe80::5054:ff:febb:101/64 

$ resolvectl status ens192 | grep -E 'Current DNS|DNS Servers|DNS Domain'
Current DNS Server: 172.17.0.2
       DNS Servers: 172.17.0.2
        DNS Domain: corp.example

$ getent hosts repo.corp.example; getent ahostsv4 archive.ubuntu.com | head -1
10.30.1.20      repo.corp.example
91.189.90.40    STREAM archive.ubuntu.com

$ sudo apt-get update 2>&1 | tail -2
Hit:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists...

Step 1: the card is now eth0, the file still says ens192

Change the card's name to eth0 (the lab does it by editing the link file, then rebooting, as a hypervisor change would):

[Match]
MACAddress=52:54:00:bb:01:01

[Link]
Name=eth0

After the reboot, the card exists, but it has no address and no DNS:

$ ip -br addr | grep -v '^lo'
enp0s2           UP             10.0.2.15/24 metric 100 fec0::5054:ff:febb:1/64 fe80::5054:ff:febb:1/64 
eth0             DOWN           

networkctl says why. The state is "unmanaged": no network file matched this card, so systemd-networkd leaves it alone.

$ networkctl list --no-pager
IDX LINK   TYPE     OPERATIONAL SETUP
  1 lo     loopback carrier     unmanaged
  2 enp0s2 ether    routable    configured
  3 eth0   ether    off         unmanaged

3 links listed.

$ networkctl status eth0 --no-pager | head -8
โ— 3: eth0
                   Link File: /etc/systemd/network/10-vmware-name.link
                Network File: n/a
                       State: off (unmanaged)
                Online state: unknown
                        Type: ether
                        Path: pci-0000:00:03.0
                      Driver: virtio_net

"Network File: n/a" is the line to look for. Now the part that makes this hard to find: nothing complains.

$ sudo netplan generate; echo "exit status $?"
exit status 0

$ journalctl -u systemd-networkd -b --no-pager | grep -iE 'eth0|ens192'


(That grep printed nothing: no log line mentions either name.) DNS has nothing to ask, and apt fails with the message that points everyone at DNS first:

$ resolvectl query repo.corp.example
Link 3 (eth0)
repo.corp.example: resolve call failed: No appropriate name servers or networks for name found

$ sudo apt-get update 2>&1 | tail -3
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/noble-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/noble-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

In the lab the management NIC kept SSH alive. On a one-NIC server this state means you are locked out of the network entirely, unless something else configures the card.

Step 2: another source configures the card, and only half the story is right

Real servers often have more than one network file: a cloud-init file, a provisioning tool's file, an installer's file. Suppose a second file configures eth0 with plain DHCP (the lab file below is an assumption about what such a file looks like; the incident report does not say what supplied the DNS during the move, only that Hyper-V did).

$ cat /etc/netplan/50-hyperv.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true

$ sudo netplan apply; ip -br addr show eth0; ip route | grep '^default'
eth0             UP             10.30.1.15/24 metric 100 fec0::5054:ff:febb:101/64 fe80::5054:ff:febb:101/64 
default via 10.30.1.2 dev eth0 proto dhcp src 10.30.1.15 metric 100 

The network is back, but it is not the same network. The static address 10.30.1.50 is gone and a DHCP address took its place. The DNS server also comes only from DHCP now:

$ resolvectl status eth0 | grep -E 'Current DNS|DNS Servers|DNS Domain'
       DNS Servers: 10.30.1.3

The DHCP-supplied DNS knows public names, not the company's. So the part of the problem you notice first, apt reaching archive.ubuntu.com, works, and anything internal fails:

$ getent hosts repo.corp.example || echo 'repo.corp.example: not found'; getent ahostsv4 archive.ubuntu.com | head -1
repo.corp.example: not found
185.125.190.81  STREAM archive.ubuntu.com

$ sudo apt-get update 2>&1 | tail -2
Hit:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists...

That is a consistent failure, not a flaky one. A system with an internal apt mirror or an internal package repository would fail every time. The next step is the flaky one.
Now suppose the company DNS is also listed on the same link, next to the one DHCP supplies. This is the natural result of someone adding nameservers to the file that owns eth0.

Current DNS Server: 172.17.0.2
       DNS Servers: 172.17.0.2 10.30.1.3
        DNS Domain: corp.example

$ for i in $(seq 1 12); do getent hosts repo.corp.example ...; done      # ok or FAIL per lookup
ok ok ok ok ok ok ok ok ok ok ok ok 

systemd-resolved talks to one server at a time, the "Current DNS Server", and moves to the next one in the list only when that one fails to answer. Make the company DNS unreachable for a few seconds (a restart, a failover, a network blip):

FAIL FAIL FAIL 

(Those failures are expected: the company DNS was paused.) Bring it back and look again:

$ (same 12 lookups, company DNS healthy again)
FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL 

$ resolvectl status eth0 | grep -E 'Current DNS|DNS Servers'
Current DNS Server: 10.30.1.3
       DNS Servers: 172.17.0.2 10.30.1.3

Resolved switched to the DHCP server during the outage and stayed there. That server knows public names, so most things keep working:

$ getent ahostsv4 archive.ubuntu.com | head -1
185.125.190.83  STREAM archive.ubuntu.com

and the internal name stays broken, even 30 seconds after the company DNS is healthy:

FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL FAIL 

A restart of systemd-resolved makes it start from the first server again:

$ sudo systemctl restart systemd-resolved; (same 12 lookups); resolvectl status eth0 | grep 'Current DNS'
ok ok ok ok ok ok ok ok ok ok ok ok 
Current DNS Server: 172.17.0.2

What this does and does not prove. It shows one way a mixed configuration produces name resolution that works for some names and fails for others, and that comes and goes with outages. It does not show that this is what happened at work. Hyper-V's DNS behaviour was not reproduced, and the first symptom the person saw was apt, which a flip like this would not necessarily break.

Fix 1: change the name in the file

This is what fixed it at work. Replace the old name with the new one:

$ sudo sed -i 's/ens192:/eth0:/' /etc/netplan/60-corp.yaml; sudo grep -n 'eth0:' /etc/netplan/60-corp.yaml
4:    eth0:

If another file still configures eth0, the two files are merged, and the result is both configurations at once:

$ sudo netplan apply; ip -br addr show eth0; ip route | grep '^default'
eth0             UP             10.30.1.50/24 10.30.1.15/24 metric 100 fec0::5054:ff:febb:101/64 fe80::5054:ff:febb:101/64 
default via 10.30.1.2 dev eth0 proto static metric 50 
default via 10.30.1.2 dev eth0 proto dhcp src 10.30.1.15 metric 100 

$ resolvectl status eth0 | grep -E 'Current DNS|DNS Servers'
       DNS Servers: 172.17.0.2 10.30.1.3

$ sudo netplan get ethernets.eth0
addresses:
- "10.30.1.50/24"
nameservers:
  addresses:
  - 172.17.0.2
  search:
  - corp.example
dhcp4: true
routes:
- metric: 50
  to: "default"
  via: "10.30.1.2"

Two addresses (the static one and a DHCP one), two default routes, two DNS servers, and "dhcp4: true" sitting next to a static address. Internal names resolve again (the company DNS is first), but the machine is not configured the way the file in front of you says, and the Step 3 flip is still possible.

10.30.1.20      repo.corp.example

Remove (or move away) the file that you do not want, and apply again:

$ sudo rm /etc/netplan/50-hyperv.yaml; sudo netplan apply; ip -br addr show eth0; ip route | grep '^default'
eth0             UP             10.30.1.50/24 fec0::5054:ff:febb:101/64 fe80::5054:ff:febb:101/64 
default via 10.30.1.2 dev eth0 proto static metric 50 

$ resolvectl status eth0 | grep -E 'Current DNS|DNS Servers|DNS Domain'
       DNS Servers: 172.17.0.2
        DNS Domain: corp.example

$ getent hosts repo.corp.example; sudo apt-get update 2>&1 | tail -1
10.30.1.20      repo.corp.example
Reading package lists...

One address, one route, one DNS server, as in Step 0. Use "sudo netplan get" and "ip -br addr" after every change; they show the merged result, which a single file never does.

Fix 2: match by MAC address, so the name stops mattering

Fix 1 breaks again the next time the name changes (another hypervisor, a new virtual hardware version, a driver update). Netplan can match a card by MAC address instead. The block gets its own label (here "lan"), and the name is no longer part of the match:

$ cat /etc/netplan/60-corp.yaml
network:
  version: 2
  ethernets:
    lan:
      match:
        macaddress: 52:54:00:bb:01:01
      addresses: [10.30.1.50/24]
      routes:
        - to: default
          via: 10.30.1.2
          metric: 50
      nameservers:
        addresses: [172.17.0.2]
        search: [corp.example]

To check that the name no longer matters, the lab renamed the card to a third name (ens160) and rebooted:

$ ip -br addr | grep -v '^lo'; resolvectl status | grep 'Current DNS'; getent hosts repo.corp.example; sudo apt-get update 2>&1 | tail -1
enp0s2           UP             10.0.2.15/24 metric 100 fec0::5054:ff:febb:1/64 fe80::5054:ff:febb:1/64 
ens160           UP             10.30.1.50/24 fec0::5054:ff:febb:101/64 fe80::5054:ff:febb:101/64 
Current DNS Server: 172.17.0.2
10.30.1.20      repo.corp.example
Reading package lists...

$ networkctl list --no-pager | grep -E 'IDX|ens160|eth0'
IDX LINK   TYPE     OPERATIONAL SETUP
  3 ens160 ether    routable    configured

Same address, same DNS, new name. Two cautions. A MAC address can change in a move (many hypervisors let you pick static or dynamic MACs, and a clone may get a new one), so check it. And if you add "set-name:", netplan will also rename the card to that name, which is a different thing from matching it.

A checklist for the next migration

Before the move, write down what the machine looks like, so you can compare afterwards:

ip -br link; ip -br addr; ip route
sudo netplan get
resolvectl status
ls /etc/netplan/; sudo cat /etc/netplan/*.yaml

After the move, if the network or DNS is odd, go in this order:

1. ip -br link: what is the card called now?
2. networkctl list: is it "configured", or "unmanaged"? Unmanaged means no file matched it.
3. grep -rn 'ens192' /etc/netplan/: which files still use the old name?
4. sudo netplan get: the merged result. Look for duplicate addresses and DNS servers.
5. resolvectl status: the DNS servers each link really has, and which one is current.

Use "sudo netplan try" instead of "netplan apply" when you change the network config of a machine you are logged into over that network: it rolls back by itself if you do not confirm. (It was not run in this lab; see the next section.)

Cheat sheet

ip -br link                         names and state of all interfaces
networkctl list                     "unmanaged" = no netplan/networkd file matched
sudo netplan get                    the merged config of all files
sudo netplan try                    apply with automatic rollback
resolvectl status                   DNS servers per link, and "Current DNS Server"
sudo systemctl restart systemd-resolved    forget which DNS server is "current"
grep -rn OLDNAME /etc/netplan/      find leftovers of the old name
ethernets:
  lan:
    match:
      macaddress: aa:bb:cc:dd:ee:ff     match by MAC; the name no longer matters

What was not run

Not run: Active Directory. The servers at work used AD DNS and were presumably domain-joined; the lab has a plain DNS server in its place, and no realm join, SSSD, Winbind or Kerberos. A domain-joined machine looks up AD service records through DNS, so a wrong DNS server can hurt more than name lookups there. That was not tested.

Not run: Hyper-V itself. The synthetic network card, its driver and its naming, and the DNS that Hyper-V supplies during a move were not available. The rename was imitated with a systemd link file on a QEMU virtual machine, and the "Hyper-V DNS" was the DHCP server of the lab network. Whether Hyper-V's own DNS or DHCP can behave differently from this is not known here.

Not run: the second netplan file is an assumption. It stands for whatever supplied DNS to the card at work (a DHCP file, cloud-init, a provisioning tool). The incident report says Hyper-V supplied DNS during the move, not how.

Not run: Ubuntu versions other than 24.04, other netplan versions, the NetworkManager renderer (everything here is systemd-networkd), cloud-init regenerating its network file on a changed card, DHCP with a reserved address, IPv6 configuration, bonds, bridges, VLANs, and more than one card.

Not run: "netplan try" (it needs someone to press Enter within the timeout, so it is not a good fit for a script).

The "some of the time" behaviour in Step 3 was reproduced with a short outage of the company DNS. Other causes of intermittent DNS exist and were not tried.

Common problems and tips

apt says "Temporary failure resolving" and nothing is wrong with DNS. Check ip -br addr first: if the interface has no address, DNS is not the problem.

networkctl shows the card as "unmanaged". No file matched it. Compare the name in ip -br link with the key under ethernets: in every netplan file.

netplan apply printed nothing and the card is still not configured. That is normal. Netplan accepts a block for a card that does not exist. It is also why the failure is quiet.

The address changed after the fix. A DHCP file for the same card was merged with your static one, or won over it. Run sudo netplan get and look at every file in /etc/netplan/.

Internal names fail after a DNS outage and public names work. Look at "Current DNS Server" in resolvectl status. Restart systemd-resolved, and then remove the DNS server that does not know your internal names from the link (use DHCP overrides, or a file that only the right source writes).

Tips. Match by MAC when the machine will move between hypervisors. Keep one file per card. Take the before-and-after notes in the checklist. Do the change from a console, not over SSH, when the card is the only one.