Renaming network interfaces on Debian GNU/Linux
I use Debian Bullseye on a Lenovo T14 AMD. This laptop is great and works very well with a recent Linux kernel (5.10). It has 3 network interfaces: a wireless one, a wired one with a normal ethernet port, and a second wired one, with a prioprietary port, for Lenovo docks, I don’t use.
The interfaces are named wlp3s0
, enp2s0f0
and enp5s0
in Debian. Yes, it turns out nowadways network interfaces are not simply named wlanX for wifi and ethX for ethernet as they conveniently used to.
There are good reasons for this change: depending on which interface was detected first during each boot, they could change name randomly. For example what was eth0
on a boot could become eth1
on the next one, which is problematic, as interface names can be used in some configuration files.
The solution is to give each interface some unique predictable names, based on the “BIOS device name” of the interface. This is great, but really annoying in practice, as I always forget how the interfaces are named, and which of the wired interfaces is the one I use 😕
Renaming network interfaces #
Thanksfully, it is possible to rename interfaces. On Debian, this is done using systemd configuration, as apparently nowadays udev is part of systemd.
First, we need to find the “path id” of the device, that is to say a unique identifier of the device, based on the PCI domain, the number of the bus and the device position on the bus.
It can be done using the command udevadm
. For my wireless interface wlp3s0
the command looks like:
$ sudo udevadm info /sys/class/net/wlp3s0 | grep ID_PATH
E: ID_PATH=pci-0000:03:00.0
E: ID_PATH_TAG=pci-0000_03_00_0
In this case the path_id
is pci-0000:03:00.0
. I can then create a .link
file to choose the name of the interface;
$ sudoedit /etc/systemd/network/10-rename-wlp3s0.link
$ cat /etc/systemd/network/10-rename-wlp3s0.link
[Match]
Path=pci-0000:03:00.0
[Link]
Name=wlan0
I did this for all the interfaces I wanted to rename, then rebooted and checked the result:
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback ***************** brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: lenovo0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether ***************** brd ff:ff:ff:ff:ff:ff
3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether ***************** brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether ***************** brd ff:ff:ff:ff:ff:ff
inet ************/24 brd ************* scope global dynamic noprefixroute wlan0
valid_lft 82650sec preferred_lft 82650sec
inet6 *************************************/64 scope global dynamic noprefixroute
valid_lft 1784sec preferred_lft 584sec
inet6 *************************/64 scope link noprefixroute
valid_lft forever preferred_lft forever
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether ***************** brd ff:ff:ff:ff:ff:ff
inet **********/16 brd ************** scope global docker0
valid_lft forever preferred_lft forever
The interfaces are now renamed wlan0
, eth0
(the ethernet port) and lenovo0
(Lenovo’s prioprietary port) 🎉