DEV Community

Junxiao Shi
Junxiao Shi

Posted on • Originally published at

Rename WiFi Interface on Ubuntu 20.04

This post is originally published on blog

During an experiment, I need to use three WiFi interfaces on a Raspberry Pi running Ubuntu 20.04.
In addition to Raspberry Pi's internal WiFi interface, I added two USB WiFi adapters.
Three network interfaces showed up in the system (ip link command), and they are named wlan0, wlan1, and wlan2 by default.

I often need to capture packets with tcpdump, and I often have to be type these interface names manually.
It isn't easy to remember the purpose of each network interface, so I wanted to rename the interfaces to reflect their role in my application.
However, this isn't as easy as it sounds.

🚫 Netplan

Ubuntu 20.04 configures network interfaces using Netplan, so my first thought was: I can write a Netplan configuration that matches network interfaces with their MAC addresses, and assigns the desired name to each network interface.

The config file would look like this:

  version: 2
      optional: true
        macaddress: ba:fe:de:f0:b9:e4
      set-name: uplink
          password: rP8jKHJ64
      dhcp4: true
      dhcp6: true
      accept-ra: true
Enter fullscreen mode Exit fullscreen mode

However, this method would not work:

$ sudo netplan apply
ERROR: uplink: networkd backend does not support wifi with match:, only by interface name
Enter fullscreen mode Exit fullscreen mode

🚫 70-persistent-net.rules

Many online guides refer to a file /etc/udev/rules.d/70-persistent-net.rules, which is processed by udev during boot.
The file should have been created automatically by the system upon discovery of the network interfaces, and I just need to modify the interface names to the desired names.

However, this file does not exist in Ubuntu 20.04, so it's another dead end.


After carefully reading Debian's NetworkInterfaceNames guide, I found the correct way:

To rename WiFi interfaces, I can create a systemd configuration file for each network interface:

echo '[Match]
Name=uplink' | sudo tee /etc/systemd/network/
Enter fullscreen mode Exit fullscreen mode

After rebooting, the network interface is renamed to what I wanted.

Top comments (3)

edtguy profile image

I tried implementing the approach. It did not work for me. I have a raspberry pi 3b+ rev 1.3 with raspberry pi o/s (Debian GNU/Linux 12 (Bookworm)) and a Realtek external wifi. Sometimes the internal is wlan0 and the external is wlan1, other times they are flipped. I need the internal to consistently be wlan1 and the external wlan0. Also, when the external is wlan0 and I put the external in monitor mode, the internal is not connected to my local wifi. I have to manually connect it.
I used ifconfig to determine the mac address of each of the two devices. The first file I created was for the internal with Name=wlan1 and the second file is with Name=wlan0
I did notice that there are two link files: /etc/systemd/network/ -> /dev/null and /etc/systemd/network/ -> /dev/null. Do I need to do anything with these?

yoursunny profile image
Junxiao Shi

When a systemd unit is symlinked to /dev/null, it's impossible to activate them.
If your setup works without these units activated, you don't need to edit these symlinks.

edtguy profile image

I came up with an alternate approach. From within my application, I check the mac address of wlan0 and wlan1 with "ip -brief link show dev [wlan0 | wlan1]" I expect the internal wifi to begin "b8:27:eb" for Broadcom. If I find a match on wlan0, then wlan1 becomes the monitor; otherwise wlan0 is set as the monitor. It may not be foolproof, but it works for automating the configuration of several units so far.