Help me rename my wireless interfaces, permanently

I’m studying networking and having a blast, but the thing is I often plug in a new interface, put it into monitor mode, start capturing with it, unplug it, move it to my laptop, raspberry pi… and have to cope with all the pesky names that each time they receive from the kernel (or systemd I should say).
I’m not too familiar with adding rules in systemd and tbh I found almost none to take inspiration from in my default install here in Garuda (my main distro on all my machines).

Looking around I found something in /usr/lib/systemd/network/99-default.link from which I quote:

To make local modifications, one of the following methods may be used:

  1. yadayada
  2. copy this file into /etc/systemd/network or one of the other paths checked
    by systemd-udevd and edit it there.
    This file should not be edited in place, because it’ll be overwritten on upgrades.

[Match]
OriginalName=*

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

Can you help me create this rule and explain me all the fields I need to edit or comment out? Like, I get what ‘OriginalName’ means, but where to put the ‘modified name’? And what do all those rules mean in the ‘AlternativeNamesPolicy’ field?

So far I’m using a shell script but that’s very inconvenient since I need to stop all the networking daemons first, rename the interfaces and restart the daemons. Not happy about it. Any other way to achieve the same result without adding a new rule?

Let me understand this a bit better. You want some kind soul to write you a full tutorial and post it here?

What do you have to bring to the table?

Is it some big secret?

4 Likes

I confess I know nothing about this topic and bring to the table only my usual Arch Wiki link, right or wrong, useful or not :wink:
https://wiki.archlinux.org/title/Network_configuration#Change_interface_name

5 Likes

I only asked for the systemd rule to add but maybe there are better options.

What do I have to offer? Hey here's my inefficient command line which is so inefficient it made me open a help request here:

$ sudo ip link set wlp5s0 name wlan0 <-- doesn't survive a reboot!

There you go I paid my fee, now you :slight_smile:

It just works!

/etc/udev/rules.d/10-network.rules
SUBSYSTEM==“net”, ACTION==“add”, ATTR{address}==“aa:bb:cc:dd:ee:ff”, NAME=“net1”
SUBSYSTEM==“net”, ACTION==“add”, ATTR{address}==“ff:ee:dd:cc:bb:aa”, NAME=“net0”

I mean, I’m still fighting with the usb ‘random MAC address’ thing (and not really understanding how a MAC address can be randomized) but hey, what do I know. I’ll fix it ser!

1 Like

I couldn't be bothered with a udev rule. I simply add net.ifnames=0 as a kernel boot parameter to revert to the old standard names.

2 Likes

Ok I need to spew out another bunch of words because life be tough.

What I wanted to achieve was basically to assign a fixed easy-to-read&remember name to each and every card I own across multiple machines. So that wherever I plug my 'omni alfa card' it's always gonna be (say) 'myalfa0', while my 'directional alfa card' was always gonna be (say) 'myalfa1', and my pc wifi 'mywlan0' and my pc eth 'myeth0' or whatever. This was of course to facilitate writing scripts and few other reasons.

So far... not so good. Meaning: I managed to assign easy&readable names to my cards but I cannot make them match their actual MAC address because they are all USB (except wlan0 which is PCI) and so their MAC address is... 'funny'. Basically even with this new naming system whatever is plugged in first via USB will be (say) 'alfa0' and whatever is second will be 'alfa01'.

So, all in all I can say that using the kernel parameter 'net.ifnames=0' is by far the easiest and most 'portable' solution. But I still believe that there's a way to do what I wanted via the systemd rules. Let's keep diggin then :slight_smile:

So, for those who managed to read all this, I have a present for you! This is the line I perfected for the USB recognition via udev. Trust me, it's a bunch of times better than the one in the wiki :smile:

SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*/usb*/*/net/*", NAME="yosup"

Just for future reference I leave here some links that I found and that have been useful to understand a couple of things I wasn't aware of about these 'non persistent MAC addresses', but that ultimately didn't really fix what I was trying to do. I'll hopefully have more time to waste on these minor issues one day.

udevd: Could not generate persistent MAC address for $name

Manipulate how your Linux system handles physical devices with udev.

[SOLVED] wireless interface renamed after installation

[SOLVED] systemd network predictable device names not so predictable?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.