I had this problem when adding a new usb wifi dongle for my raspberry setup. That it sometimes gets assigned with
wlan0 name. I expect that
wlan0 name should be assigned to the built-in wifi card device, hence the wifi dongle should get
wlan1 name instead. But that's not the case. This leads to problem, since I need this naming to be deterministic for my network configuration (e.g: which device acts as wifi client vs which one as access point, which one does support 5 Ghz band vs only support 2.4 GHz band).
Fortunately there are ways to solve this.
Predictable Network Interface Names
The straightforward way to enable this is via
raspi-config. This feature provides a predictable naming mechanism by generating the name from device firmware/topology/location information.
Assigning fixed names based on firmware/topology/location information has the big advantage that the names are fully automatic, fully predictable, that they stay fixed even if hardware is added or removed (i.e. no reenumeration takes place) and that broken hardware can be replaced seamlessly. That said, they admittedly are sometimes harder to read than the "eth0" or "wlan0" everybody is used to. Example: "enp5s0"
In the Network Options, enable predictable network device name, and reboot.
This solution is simple and easy. However, the assigned name (something like this
enp0s31f6) are harder to remember compared to the old naming
eth0. Which brings me to seek another simple solution that can achieve this classic naming.
Since raspbian uses
systemd for the init system, we can utilize the
systemd.link. Basically what we can do with it is to put a simple rule that assigns a certain name for device with certain mac address. So I can just take a note of my wifi device mac address and assign it a unique name.
Since I have 2 wifi devices, I setup two
> cat /etc/systemd/network/09-wlan1.link [Match] MACAddress=d0:37:45:5a:c7:22 [Link] Name=wlan1 > cat /etc/systemd/network/10-wlan0.link [Match] MACAddress=dc:a6:32:4b:1e:d7 [Link] Name=wlan0
That's it and reboot.