0

How can I change persistent network names (e.g. enx00b56d00d500) to be aliases — not replacements — for the standard names given by Linux (eth0)?

I want to be able to use both names, but systemd.link currently destroys the original interface name with no obvious way to tell it not to.

Background

I'm running Debian GNU/Linux. I understand the benefits of persistent naming and want to continue using them, but have also found it frustrating that I can't rely on the simple Linux names working from the command line.

For example, some of my machines don't have any built-in ethernet and I have a dozen different USB to ethernet dongles on my workbench. I want whatever one I happen to plug in to be available as both eth0 and as whatever persistent name systemd wants to give it.

I know from the Debian Wiki that I can disable network renaming by using the net.ifnames=0 kernel parameter, but that page also states that it is not possible to create aliases such that one is free to use either name. I believe that may be old information since Linux has had the capability to add alternative network names since 2019.

Note that I do not wish to manually rename the interfaces. Ideally, a solution would prevent systemd from deleting the original name, but it would be fine if there was some automatic way to add the Linux name back as an alternative.

hackerb9
  • 1,418
  • 13
  • 20
  • Does this answer your question? [How to add an alternative name for the interface?](https://unix.stackexchange.com/questions/391535/how-to-add-an-alternative-name-for-the-interface) – larsks Feb 20 '23 at 21:28
  • Thanks, @larsks, but that deals with manually adding alternative names. I've expanded my question to clarify that I am looking to automatically retain the original name when a persistent name is assigned. – hackerb9 Feb 21 '23 at 02:03

1 Answers1

1

If you are running Debian 11 (or later) you should already have the behavior you want. Automatic configuration of altname for interfaces is controlled by the AlternativeNamesPolicy setting in /usr/lib/systemd/network/99-default.link. With the default configuration:

[Match]
OriginalName=*

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

If I boot a Debian 11 system with net.ifnames=0, I get:

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:f7:e2:94 brd ff:ff:ff:ff:ff:ff
    altname eth0

And I can refer to this interface as either enp1s0 or as eth0:

root@debian:~# ip -br link show eth0
enp1s0           UP             52:54:00:f7:e2:94 <BROADCAST,MULTICAST,UP,LOWER_UP>
root@debian:~# ip -br link show enp1s0
enp1s0           UP             52:54:00:f7:e2:94 <BROADCAST,MULTICAST,UP,LOWER_UP>

If you are running a version of Debian older than Debian 11, I think you may be out of luck: the iproute package on earlier distributions does not have altname support.


In response to your comment:

Does Debian have a way to disable that (and any other *.link files that might be created in the future)?

You cannot disable "any other *.link files that might be created in the future", but you can disable or replace any specific file with an equivalently named file in /etc/systemd/network (this is true for any sort of systemd unit file). For the "disable" case, the easiest solution is to symlink the file to /dev/null; from https://www.freedesktop.org/software/systemd/man/systemd.link.html:

Files in /etc/ have the highest priority, files in /run/ take precedence over files with the same name in /usr/lib/. This can be used to override a system-supplied link file with a local file if needed. As a special case, an empty file (file size 0) or symlink with the same name pointing to /dev/null disables the configuration file entirely (it is "masked").

So you can mask the 73-usb-net-by-mac.link file by running:

ln -s /dev/null /etc/systemd/network/73-usb-net-by-mac.link
larsks
  • 32,449
  • 5
  • 54
  • 70
  • Oh! That would be lovely. Unfortunately, it appears that that behavior is overriden by `/usr/lib/systemd/network/73-usb-net-by-mac.link`. Does Debian have a way to disable that (and any other *.link files that might be created in the future)? – hackerb9 Feb 21 '23 at 07:58
  • 1
    I've updated the answer to address your comment. – larsks Feb 21 '23 at 14:23
  • I think we're getting closer, but disabling 73-usb-net-by-mac.link doesn't work. Now my USB-to-Ethernet dongles show up with a different persistent name (enp3s0f3u1u1u4), but still no eth0. [I tried this on both Debian 11 (bullseye) and Debian 12 (bookworm). I have the same 99-default.link file as in your answer.] – hackerb9 Feb 21 '23 at 15:10
  • 1
    I don't have handy a debian-based system into which I can plug a usb ethernet dongle. Does your interface have *any* altnames defined? – larsks Feb 21 '23 at 15:12
  • No, at least not according to `ip link show | grep alt`. – hackerb9 Feb 21 '23 at 15:15