After importing a virtual machine exported from VirtualBox into libvirt, the network interface shows up as ens3. Would it be possible to adapt the domain configuration to make it instead appear as enp0s3 like it did in VirtualBox?

At first one might think that it was the reboot, not the migration, which caused systemd to enumerate the interface differently. However, since the interface in source environment still remains enp0s3 after reboot, that is verified to not be the case

While it is trivial to update network configuration inside the virtual machine, it would be preferable to solve it outside of the vm. There are more than one to migrate, and they are of many different flavors.

My host with the target libvirt (7.0.0-3) is running Debian bullseye and KVM is the hypervisor used.

This answer suggests the p0 part is decided by the bus number. The top comment in this source code for systemd authoritatively shouts a link to predictable interface names, which claims the goal is stable naming even after hardware changes. I stopped myself short of diving into the details of trying to understand how it all is actually implemented. I find the description of whether to include p0 or not, quoted below, to be in insufficient detail for me to understand:

  1. Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1)
  2. Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0)

…falling back to 3) if applicable…

What makes it applicable? I understand all the words, but fail to understand where to search. So instead, over to the fun part of attempting to accomplish while lacking full understanding. If editing the bus number in raw XML definition of the network interface the interface name does become enp1s3.

--- ens3    2022-05-28 00:00:00 +0000
+++ enp1s3  2022-05-28 01:00:00 +0000
@@ -100,3 + 100,3 @@
      <alias name='net0'/>
-     <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+     <address type='pci' domain='0x0000' bus='0x01' slot='0x03' function='0x0'/>

What is causing systemd to select policy 3 when running under VirtualBox, but policy 2 when in the libvirt environment? Can libvirt be configured to make systemd include the bus number even when it is zero?

I've attempted all options imaginable to me. Including adding another interface, but that only ended up in a state of mixed naming (with policy 2 used for ens3 and policy 3 for enp1s3, which rhymes well with naming being stable). Did also try selecting every available type of network card, but no success.

1 Answer 1


When on bus 0, the generated network interface name depends on whether it sits on a PCI or a PCIe bus. PCI NICs are enumerated primarily in the short ens3 format while PCIe NICs get the longer enp0s3 name.

With udev lingo, the short format is ID_NET_NAME_SLOT and ID_NET_NAME_PATH is the longer format. When ID_NET_NAME_SLOT is set, it takes precedence. The source code file linked in the question sets these values.

In Linux 5.5 (changelog) and systemd 245 (release notes) the concept of alternative names was introduced, which means that since 2019 ID_NET_NAME_PATH has been set as an altname (see ip link) on PCI NICs. Your migrated VM is likely older than that if you're not able to use enp0s3 interchangeably with ens3.

So in addition to merely looking at the interface configuration, which you seem to have understood the parameters of, make sure something like the following is in your domain definition (note the existence of an e in the model) and that your NIC sits on the PCIe bus:

<controller type='pci' index='0' model='pcie-root'/>

Not all machine types support all controllers, so recreating the VM with the desired configuration and importing again might be the easiest solution.

One might speculate that there are historical reasons for the naming. When only a single PCI bus 0 was expected and all NICs were in different slots on the same bus it likely seem irrelevant to include the bus number.

In order to list all names and alternative names udevadm info -e should do the trick.

  • Indeed switching to PCIe brings back the interface name to enp0s3. This particular vm is stuck on Linux 4.4 and system 229. Thank you!
    – sampi
    May 29, 2022 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .