wlan number assignment

How or where does Linux determine the assignment of a network device? Specifically, wlan0 or wlan1 for wireless USB devices.

I plugged in a TP USB wireless a while ago, and it was assigned wlan0. I removed it. This week I plugged in an Edimax USB wireless device and it comes up as wlan1. I removed it today to try a second Edimax USB wireless device (I bought two) and now it comes up wlan2.

I know enough of Unix/Linux to know this is being configured somewhere, and if I delete the unused config file I can make the latest Edimax become wlan0. But how/where?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Udev is the system component that determines the names of devices under Linux — mostly file names under /dev, but also the names of network interfaces.

Versions of udev from 099 to 196 come with rules to record the names of network interfaces and always use the same number for the same device. These rules are disabled by default starting from udev 174, but may nonetheless be enabled by your distribution (e.g. Ubuntu keeps them). Some distributions provide different rule sets.

The script that records and reserves interface names for future use is
/lib/udev/rules.d/75-persistent-net-generator.rules. It writes rules in
/etc/udev/rules.d/70-persistent-net.rules. So remove the existing wlan0 and wlan1 entries from your /etc/udev/rules.d/70-persistent-net.rules, and change wlan2 to wlan0. Run udevadm --trigger --attr-match=vendor='Edimax' (or whatever --attr-match parameter you find matches your device) to reapply the rules to the already-plugged-in device.

Method 2

This issue has been solved as of systemd v197 with the introduction of persistent naming for network devices.

According to the freedesktop Predictable Network Interface Names page, the kernel simply assigned names based on the order they were probed by the relevant drivers:

The classic naming scheme for network interfaces applied by the kernel is to simply assign names beginning with “eth0”, “eth1”, … to all interfaces as they are probed by the drivers. As the driver probing is generally not predictable for modern technology this means that as soon as multiple network interfaces are available the assignment of the names “eth0”, “eth1” and so on is generally not fixed anymore and it might very well happen that “eth0” on one boot ends up being “eth1” on the next.

If your distro uses systemd, you can either use the predictably assigned but perhaps unwieldy names like wlp0s11 or you can write a udev rule to give them a name you are more comfortable with, like wifi1, based on the mac address…

Include a file in /etc/udev/rules.d/ called 10-network-device.rules:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="22:bb:cc:33:44:dd", NAME="wifi1"


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x