Try   HackMD

Partially Enabling Predictable Network Interface Names

Suppose you have predictable network interface names disabled on your system, and enabling it is going to mess things up, but you're adding a new network card that uses a different driver, and that's going to mess things up too.

It's going to mess things up because while the order your driver enumerates devices in might be predictable (your interfaces always got named eth0 and eth1 in the right order), the order your drivers are loaded is not predictable, so your new network card might get eth0 and bump your earlier interfaces down the line. Worse, there's no guarantee that it will even be predictable from one boot to the next. What to do?

You could enable predictable names, but let's say you've got dozens of configs, scripts, and programs that all rely on eth0 being your default NIC. Sure it wasn't the best choice, but it's going to be costly to correct it. So instead let's partially enable predictable names.

Re-enabling Predictable Names

The most common way to disable predictable names is with net.ifnames=0 on the kernel commandline. This isn't processed by the kernel, but by udev, which uses it to disable all attempts at renaming interfaces altogther. It prevents you from selectively enabling interface renaming. So the first step is to remove this from your bootloader configuration.

Disabling Another Way

But you still want it disabled for everything but your new NIC. This part gets a little tricky. The default configuration is set by /usr/lib/systemd/network/99-default.link and can be overridden by /etc/systemd/network/99-default.link. You can also override parts of it by putting fragment .conf files in /etc/systemd/network/99-default.link.d/. But these might have no effect.

The reason overrides might be ineffective is that the system that builds the initramfs might be copying the original 99-default.link file and not bothering with any 99-default.link.d/*.conf files.

So the actually effective way to disable predictable names without disabling the whole system, is to disable the policies in /etc/systemd/network/99-default.link:

[Match]
OriginalName=*

[Link]
NamePolicy=
AlternativeNamesPolicy=
MACAddressPolicy=persistent

You need to also get this into your initramfs too, otherwise it will be renamed before you pivot to your root filesystem, using the config stored in the initramfs. This is what I had to do on Debian 12:

update-initramfs -u -k $(uname -r)

This will result in udev deciding:

Policies didn't yield a name and Name= is not given, not renaming.

Future kernel installs should pick up the same changes.

Partially Enabling Again

Now that you've got predictable names re-disabled in a more flexible way, you can enable predictable names for interfaces by creating a systemd.link file that's scoped to a specific driver (or some other supported scope). This example uses the same NamePolicy as the 99-default file.

[Match]
Driver=mlx5_core

[Link]
NamePolicy=keep kernel database onboard slot path
AlternativeNamesPolicy=database onboard slot path mac
MACAddressPolicy=persistent

With all of this in place, predictable names should be used only by interfaces with the matching driver.