13

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?

2 Answers 2

16

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.

4
  • Thanks very much. This is debian on the raspberry pi (raspbian) so the persistent storage is just a bit different.
    – Huntrods
    Commented Apr 25, 2013 at 2:09
  • The file where specific wlan assignments are stored on this (latest, I think) version of raspbian is: /etc/udev/rules.d/70-persistent-net.rules. I found this out using your info above and then typing "man udev" to see why I could not find 'wlan' in the /lib/udev/rules.d directory.
    – Huntrods
    Commented Apr 25, 2013 at 2:11
  • For raspbian, the wlan number is set based on the mac address of the wireless device (in this case, whichever one is plugged into the USB port). It allocates numbers (wlan0, wlan1, etc.) based on the order it first sees a new mac address when it recognizes and configures the wireless device. Editing this file as you suggest allows you to set any device to any wlan# by it's static IP. - thanks.
    – Huntrods
    Commented Apr 25, 2013 at 2:13
  • a couple of points of clarification to offer: 1) Gilles is spot on in his answer, would love to see an example of assigning ID's by hwaddr, 2) interfaces are assigned on order seen -- e.g. I have two edimax USB NIC's, placement in the four available USB slots is highly relevant to the order they are scanned. 3) you can re-order the interfaces by unplugging them and manually inserting them in the order you want them identified. Commented Aug 1, 2016 at 17:16
4

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"
2
  • 1
    You're missing a step here. Huntrods evidently doesn't have a post-197 udev with the new naming scheme, and also evidently has a persistent naming scheme. It's this persistent naming scheme that he needs to tweak. Commented Apr 25, 2013 at 0:47
  • What can I say; I took a punt...
    – jasonwryan
    Commented Apr 25, 2013 at 2:40

You must log in to answer this question.

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