Hetzner Cloud: Predictable Network Interface Names

ens3 ens10 ens11 ens12 enp1s0 enp7s0 enp8s0 enp9s0

With the release of the new AMD EPYC based cloud servers (CPX), Hetzner has applied some changes to their virtualization platform (QEMU). The network interface names have changed due to the modern virtio_net network adapter 0x1041 including different pcie bus addresses.

All Hetzner standard images are now using the net.ifnames=0 setting to enforce the kernel naming scheme of the ethernet devices. Previously, the Predictable Network Interface Names were used.

But in case you’re using central managed, customized images you will run into serious trouble when running both CP (intel), CPX (amd) and CAX (arm) machines.

Note: the new naming scheme is only used in case you’ve created a cloud server based on AMD EPYC (CPX). By upgrading/switching between machine types, the scheme of the initial created type will be used.

Edit April 2023: the redundant Virtualization check has been removed from the link unit since systemd-detect-virt fails on Hetzner CAX platform.

systemd .link solution#

To address this issue, you can add some systemd network link files which are matching the PCI-E path of the interfaces. This allows you to create a bulletproof solution which works on both machine types using custom interface names.

The following network interface naming scheme will be used:

  • wan – the public interfaces
  • net0 – the first cloud network
  • net1 – the second cloud network
  • net2 – the third cloud network

File: /etc/systemd/network/10-hcloud-wan.link

[Match]
Driver=virtio_net

# first ethernet device used for wan conneciton
# - legacy intel: pci-0000:00:03.0
# - amd epyc:     pci-0000:01:00.0
Path=pci-0000:00:03.0 pci-0000:01:00.0

[Link]
Name=wan

File: /etc/systemd/network/11-hcloud-net0.link

[Match]
Driver=virtio_net

# second ethernet device (cloud network 1)
# - legacy intel: pci-0000:00:0a.0
# - amd epyc:     pci-0000:07:00.0
Path=pci-0000:00:0a.0 pci-0000:07:00.0

[Link]
Name=net0

File: /etc/systemd/network/12-hcloud-net1.link

[Match]
Driver=virtio_net

# third ethernet device (cloud network 2)
# - legacy intel: pci-0000:00:0b.0
# - amd epyc:     pci-0000:08:00.0
Path=pci-0000:00:0b.0 pci-0000:08:00.0

[Link]
Name=net1

File: /etc/systemd/network/13-hcloud-net2.link

[Match]
Driver=virtio_net

# fourth ethernet device (cloud network 3)
# - legacy intel: pci-0000:00:0c.0
# - amd epyc:     pci-0000:09:00.0
Path=pci-0000:00:0c.0 pci-0000:09:00.0

[Link]
Name=net2

udev info#

The udevadm shows all device attributes currently used by the system.

udevadm info -e

Legacy environment (intel, ens3)#

P: /devices/pci0000:00/0000:00:03.0/virtio0/net/eth0
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:03.0/virtio0/net/eth0
E: SUBSYSTEM=net
E: INTERFACE=eth0
E: IFINDEX=2
E: USEC_INITIALIZED=4515430
E: net.ifnames=0
E: ID_NET_NAMING_SCHEME=v240
E: ID_NET_NAME_MAC=enx96000033f656
E: ID_NET_NAME_PATH=enp0s3
E: ID_NET_NAME_SLOT=ens3
E: ID_BUS=pci
E: ID_VENDOR_ID=0x1af4
E: ID_MODEL_ID=0x1000
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Red Hat, Inc.
E: ID_MODEL_FROM_DATABASE=Virtio network device
E: ID_PATH=pci-0000:00:03.0
E: ID_PATH_TAG=pci-0000_00_03_0
E: ID_NET_DRIVER=virtio_net
E: ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/eth0
E: TAGS=:systemd:

New environment (amd epyc, eth0)#

P: /devices/pci0000:00/0000:00:02.0/0000:01:00.0/virtio1/net/eth0
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:02.0/0000:01:00.0/virtio1/net/eth0
E: SUBSYSTEM=net
E: INTERFACE=eth0
E: IFINDEX=2
E: USEC_INITIALIZED=5865912
E: net.ifnames=0
E: ID_NET_NAMING_SCHEME=v240
E: ID_NET_NAME_MAC=enx960000543284
E: ID_NET_NAME_PATH=enp1s0
E: ID_BUS=pci
E: ID_VENDOR_ID=0x1af4
E: ID_MODEL_ID=0x1041
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Red Hat, Inc.
E: ID_MODEL_FROM_DATABASE=Virtio network device
E: ID_PATH=pci-0000:01:00.0
E: ID_PATH_TAG=pci-0000_01_00_0
E: ID_NET_DRIVER=virtio_net
E: ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/eth0
E: TAGS=:systemd: