2

I'm developing yocto-base Linux distribution and I have to manage a WiFi-USB adapter.

When I insert the adapter in the USB connector, Linux kernel and udev add a wifi ethernet interface and set its name to wlp0s21f0u8.

I know that a new naming scheme has been introduced, to solve problems that arose from the old (eth0, wlan0) naming standards. The name wlp0s21f0u8 is a consequence of this new scheme. Basically, the first two letter describe the type of interface: wl for wlan (wireless lan), en for ethernet.

When I plug in the WiFi-USB adapter the command udevadm monitor, that is available in my distribution, gives many logs that are listed below:

KERNEL[3538.552002] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8 (usb)
KERNEL[3538.554908] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0 (usb)
KERNEL[3538.628751] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/wakeup/wakeup39 (wakeup)
KERNEL[3538.629103] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/ieee80211/phy8 (ieee80211)
KERNEL[3538.629536] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/ieee80211/phy8/rfkill8 (rfkill)
KERNEL[3538.641836] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0 (net)
KERNEL[3538.642081] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-0 (queues)
KERNEL[3538.642111] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-1 (queues)
KERNEL[3538.642133] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-2 (queues)
KERNEL[3538.642201] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-3 (queues)
KERNEL[3538.642381] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-0 (queues)
KERNEL[3538.642490] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-1 (queues)
KERNEL[3538.642567] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-2 (queues)
KERNEL[3538.642669] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-3 (queues)
KERNEL[3538.649652] bind     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0 (usb)
KERNEL[3538.649986] bind     /devices/pci0000:00/0000:00:15.0/usb1/1-8 (usb)
UDEV  [3538.652456] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8 (usb)
UDEV  [3538.654593] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0 (usb)
UDEV  [3538.657451] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/wakeup/wakeup39 (wakeup)
UDEV  [3538.660210] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/ieee80211/phy8 (ieee80211)
UDEV  [3538.661866] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/ieee80211/phy8/rfkill8 (rfkill)
KERNEL[3538.666927] move     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlp0s21f0u8 (net)
UDEV  [3538.684035] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlp0s21f0u8 (net)
UDEV  [3538.689310] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-0 (queues)
UDEV  [3538.690951] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-2 (queues)
UDEV  [3538.691687] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-1 (queues)
UDEV  [3538.697841] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-3 (queues)
UDEV  [3538.700271] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-0 (queues)
UDEV  [3538.701113] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-2 (queues)
UDEV  [3538.702787] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/tx-1 (queues)
UDEV  [3538.703428] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0/queues/rx-3 (queues)
UDEV  [3538.707760] bind     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0 (usb)
UDEV  [3538.711545] bind     /devices/pci0000:00/0000:00:15.0/usb1/1-8 (usb)
UDEV  [3538.982603] move     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlp0s21f0u8 (net)

Among them I want to highlight the following that, in my opinion, are the most important:

...
KERNEL[3538.641836] add      /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlan0 (net)
...
KERNEL[3538.666927] move     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlp0s21f0u8 (net)
...
UDEV  [3538.982603] move     /devices/pci0000:00/0000:00:15.0/usb1/1-8/1-8:1.0/net/wlp0s21f0u8 (net)

Previous logs show that kernel adds the interface wlan0 and after its name is changed (move) to wlp0s21f0u8.

How can I rename the ethernet interface from wlp0s21f0u8 to a name of my choice?

Please can someone help me to do that?

Thanks

1
  • At this link there are some info about this topic Predictable Network Interface Names. An this is an other link useful.
    – User051209
    Oct 19, 2022 at 7:01

1 Answer 1

4

If all you want is to revert all interfaces to their original kernel names, the easiest way to do so is to boot with the net.ifnames=0 kernel option – this tells udev to disable renaming entirely.

There are two ways to rename individual interfaces:

  • Using a .link file in /etc/systemd/network. These are processed by udev rules (not by systemd-networkd) and this is actually the same mechanism that renames your interface to wlp0s21f0u8 in the first place. See the systemd.link(5) manual page for more details.

    If you want to revert the interface to the kernel name, use NamePolicy= with an empty value; if you want to use a custom name, specify it through Name=.

    [Match]
    <some match conditions>
    
    [Link]
    NamePolicy=
    Name=usbwifi
    

    Take a look at /usr/lib/systemd/network/99-default.link to see how the renaming feature gets enabled in the first place.

    All .link files are processed as part of udev's 80-net-setup-link.rules. This being an embedded system, you could remove the rules file entirely (and the corresponding udev helper binary) if you don't use any .link file features.

  • Using an udev rule. If you have an earlier rule that directly assigns NAME= (e.g. in a 70-custom-names.rules), the later rule in that handles .link files will not override it.

    ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan0", NAME="usbwifi"
    

In both cases, avoid trying to rename something "back" to kernel-style wlan# names; if you want those, it's better to disable renaming entirely (e.g. by setting an empty NamePolicy) rather than try to undo it after the fact.

4
  • Thank you very much. I'll study and try your tips and after I'll give a feedback.
    – User051209
    Sep 29, 2022 at 8:15
  • Thank you @user1686 I have tested the second way and it works perfectly. I knew the rule but not the position of the file 70-custom-names.rules and I put it in the folder /etc/udev/rules.d so it had not effect.
    – User051209
    Sep 30, 2022 at 8:41
  • /etc/udev/rules.d is actually correct – it's the ordering/position respective to other rules that matters the most. Sep 30, 2022 at 8:44
  • you are right again if I put the file 70-custom-names.rules in /etc/udev/rules.d it works the same. So I suppose that when I tried before your answer I was using an erroneus rule.
    – User051209
    Sep 30, 2022 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .