-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
How do you force a wifi interface to be a certain wlanX?
Hi all.
I use 2 WiFi configs on my Pi.
1) The on-board WiFi (wlan0)
2) WiFi dongle (wlan1)
What I have seen is that these 2 will swap randomly and then the on-board will become wlan1 and the dongle will be wlan0. How can I stop this from happening?
We use the Pi in a steel cabinet and the on-board signal is very week. The dongle gets full signal. We use the on-board as backup to the dongle.
I use 2 WiFi configs on my Pi.
1) The on-board WiFi (wlan0)
2) WiFi dongle (wlan1)
What I have seen is that these 2 will swap randomly and then the on-board will become wlan1 and the dongle will be wlan0. How can I stop this from happening?
We use the Pi in a steel cabinet and the on-board signal is very week. The dongle gets full signal. We use the on-board as backup to the dongle.
Re: How do you force a wifi interface to be a certain wlanX?
Search for "predictable interface names" - they're turned off in Raspbian by default.
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
Hi. I don't want to give it new names. I need it to stay the same way all the time. wlan0 should always be the on-board and wlan1 should be the dongle.
Re: How do you force a wifi interface to be a certain wlanX?
It will give them new names, but they will always be static for each interface.
There is no other way to achieve this AFAIK, it all depends on how each interface interacts with the kernel, which is not predictable.
There is no other way to achieve this AFAIK, it all depends on how each interface interacts with the kernel, which is not predictable.
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
Here they say it can be done but I dont see the files they are talking about.
https://raspberrypi.stackexchange.com/q ... -and-wlan1
https://raspberrypi.stackexchange.com/q ... -and-wlan1
- DougieLawson
- Posts: 42214
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: How do you force a wifi interface to be a certain wlanX?
Forget that stackexchange stuff it's three year old junk and irrelevant to Raspbian Stretch.JacoFourie wrote: ↑Tue Nov 28, 2017 1:54 pmHere they say it can be done but I dont see the files they are talking about.
https://raspberrypi.stackexchange.com/q ... -and-wlan1
Enable predictable names and your wlan0 will become wlxaabbccddeeff (based on the hardware MAC address of wlan0), your wlan1 will become wlxffeeddccbbaa (based on the hardware MAC address of wlan1) and those names can NEVER change as the MAC address is burned into the hardware.
That's precisely what predictable names are for so that you can configure your network safe in the knowledge that nothing changes. You won't get any bad surprises.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: How do you force a wifi interface to be a certain wlanX?
Unless you are using a PI with onboard WiF; for the Pi3 and PIZeroW which is connected over sdio will use the name wlan0DougieLawson wrote: ↑Tue Nov 28, 2017 5:51 pmForget that stackexchange stuff it's three year old junk and irrelevant to Raspbian Stretch.JacoFourie wrote: ↑Tue Nov 28, 2017 1:54 pmHere they say it can be done but I dont see the files they are talking about.
https://raspberrypi.stackexchange.com/q ... -and-wlan1
Enable predictable names and your wlan0 will become wlxaabbccddeeff (based on the hardware MAC address of wlan0), your wlan1 will become wlxffeeddccbbaa (based on the hardware MAC address of wlan1) and those names can NEVER change as the MAC address is burned into the hardware.
That's precisely what predictable names are for so that you can configure your network safe in the knowledge that nothing changes. You won't get any bad surprises.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
there are 2 things to do:
1. switch off this 'predictable naming' crap. all it really does is to give unpredictable names unless you once had a chance to see the given interface names on a booted system. if you want back predictable names like eth0, eth1, wlan0, wlan1, wlan2 just do:
2. for explicit assignments create a file '/etc/udev/rules.d/72-xxx.rules'. A sample for this looks like this:
1. switch off this 'predictable naming' crap. all it really does is to give unpredictable names unless you once had a chance to see the given interface names on a booted system. if you want back predictable names like eth0, eth1, wlan0, wlan1, wlan2 just do:
Code: Select all
ln -s /dev/null /etc/systemd/network/99-default.link
Code: Select all
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:cd:f5:98", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:98:a0:cd", NAME="wlan1"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="60:e3:27:17:55:85", NAME="wlan0"
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
Does this mean I use the MAC address of each device and config it this way ?sparkie777 wrote: ↑Wed Nov 29, 2017 11:05 amthere are 2 things to do:
1. switch off this 'predictable naming' crap. all it really does is to give unpredictable names unless you once had a chance to see the given interface names on a booted system. if you want back predictable names like eth0, eth1, wlan0, wlan1, wlan2 just do:2. for explicit assignments create a file '/etc/udev/rules.d/72-xxx.rules'. A sample for this looks like this:Code: Select all
ln -s /dev/null /etc/systemd/network/99-default.link
Code: Select all
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:cd:f5:98", NAME="eth0" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:98:a0:cd", NAME="wlan1" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="60:e3:27:17:55:85", NAME="wlan0"
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
correct.
of course 2.) is advisable only if there are multiple interfaces of the same kind in use at the same time.
of course 2.) is advisable only if there are multiple interfaces of the same kind in use at the same time.
Last edited by sparkie777 on Wed Nov 29, 2017 12:12 pm, edited 1 time in total.
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
the xxx can I call that static-names ?
- ShiftPlusOne
- Raspberry Pi Engineer & Forum Moderator
- Posts: 6386
- Joined: Fri Jul 29, 2011 5:36 pm
Re: How do you force a wifi interface to be a certain wlanX?
sparkie777 wrote: ↑Wed Nov 29, 2017 11:05 am... all it really does is to give unpredictable names unless you once had a chance to see the given interface names on a booted system...Code: Select all
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:cd:f5:98", NAME="eth0" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:98:a0:cd", NAME="wlan1" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="60:e3:27:17:55:85", NAME="wlan0"
enxb827ebcdf598
wlxb827eb98a0cd
wlx60e327175585
That's unpredictable? If you had to put those values in a udev rule, you already know what the interface names would be.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
@JacoFourie:
I don't understand what you mean. Arbitrary names are allowed for this file as long as it (for practical reasons) starts with '72-' and ends with '.rules'
@ShiftPlusOne:
I'm not talking about Rasperries only. The systemd-naming scheme is totally unpredictable unless you know the motherboard/ bios/ mac-addresses and other features of your hardware in advance exactly.
This is impractical particularly if there are solely distinct interfaces (e.g. only 1x ethX and only 1x wlanX) interfaces in use.
No need at all to use any interface name other than good old predictable 'eth0' 'wlan0' in that case.
I don't understand what you mean. Arbitrary names are allowed for this file as long as it (for practical reasons) starts with '72-' and ends with '.rules'
@ShiftPlusOne:
I'm not talking about Rasperries only. The systemd-naming scheme is totally unpredictable unless you know the motherboard/ bios/ mac-addresses and other features of your hardware in advance exactly.
This is impractical particularly if there are solely distinct interfaces (e.g. only 1x ethX and only 1x wlanX) interfaces in use.
No need at all to use any interface name other than good old predictable 'eth0' 'wlan0' in that case.
Last edited by sparkie777 on Wed Nov 29, 2017 12:38 pm, edited 9 times in total.
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
"2. for explicit assignments create a file '/etc/udev/rules.d/72-xxx.rules'. A sample for this looks like this: "
I want to know can I call the rules file 72-static-name.rules
Thanks for the help.
I want to know can I call the rules file 72-static-name.rules
Thanks for the help.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
yes, you can name it that way
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
OK so I will leave eth0 alone and only config wlan0 and wlan1.
The problem is we want to get to a general image that we use on a lot of pi's. This solution will mean that we have to edit each image before it is rolled out as the MAC will be diffrent on each Pi.
The problem is we want to get to a general image that we use on a lot of pi's. This solution will mean that we have to edit each image before it is rolled out as the MAC will be diffrent on each Pi.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
in that case the easiest thing to do to apply step 1.) of above and
2. simply uninstall the Broadcom 802.11 wireless firmware (as you don't need it anyway):
this will leave 'wlan0' (provided by your dongle) alone on your machine and you are done:-)
2. simply uninstall the Broadcom 802.11 wireless firmware (as you don't need it anyway):
Code: Select all
apt purge firmware-brcm80211
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
No we need both.
We want to set-up the on-board as an AP and the dongle as the client.
If the pi is in a wifi hot spot it should connect to the network.
But if it is not then we want to be able to connect to the Pi's AP and then control it that way.
We want to set-up the on-board as an AP and the dongle as the client.
If the pi is in a wifi hot spot it should connect to the network.
But if it is not then we want to be able to connect to the Pi's AP and then control it that way.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
there exist methods to distinguish interfaces other than by their MAC address. E.g. relying on the vendor could help in your case. You have to look further. I haven't dealt with that since I switch off predictable stuff all the time.
Re: How do you force a wifi interface to be a certain wlanX?
The on-board WiFi should be allocated `wlan0` even with Predictable Network Interface Names.JacoFourie wrote: ↑Wed Nov 29, 2017 1:38 pmNo we need both.
We want to set-up the on-board as an AP and the dongle as the client.
If the pi is in a wifi hot spot it should connect to the network.
But if it is not then we want to be able to connect to the Pi's AP and then control it that way.
If you want to use as an AP you should set `dhcpcd.conf` to ignore the `wlan0` interface, it will then only configure your WiFi dongle.
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
@JacoFourie:
if you don't want to use MAC addresses (because they are too specific) you could setup a file with a more generous rule specification (probably sufficient in your case):
/etc/udev/rules.d/72-static-name.rules
this allows your dongle to allocate wlan0 since the onboard wlan is forced to wlan1
if you don't want to use MAC addresses (because they are too specific) you could setup a file with a more generous rule specification (probably sufficient in your case):
/etc/udev/rules.d/72-static-name.rules
Code: Select all
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="brcmfmac", NAME="wlan1"
Last edited by sparkie777 on Sat Dec 02, 2017 5:46 am, edited 1 time in total.
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
Thanks a lot. I will try it out and let you know
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
inspired by your question (and because I had similar problems in the past myself) I now dug deeper into this.
What came out is this more general approach: [HOWTO] assign predictable WLAN device names without fiddling with MAC addrs - Raspberry Pi Forums
What came out is this more general approach: [HOWTO] assign predictable WLAN device names without fiddling with MAC addrs - Raspberry Pi Forums
-
- Posts: 105
- Joined: Thu Mar 10, 2016 6:51 pm
Re: How do you force a wifi interface to be a certain wlanX?
Wow thanks for this. I will give a try. The general vendor method does not work. I saw the on-board and Edimax dongle still swap around. I agree with your post. We need a way to make sure that the adapters are always the same as we have setup a image with everything we need. We then flash this image to about 20 Pi’s at a time. You can not fiddle with each one to change the mac. And for support we can not expect the client to have to fiddle with the files to get it to work.. We want to leave a spare SD card should one fail. And this will help sort out that problem.
Have you tested it. Does it work the way you say?
Have you tested it. Does it work the way you say?
-
- Posts: 301
- Joined: Tue Nov 27, 2012 4:37 am
Re: How do you force a wifi interface to be a certain wlanX?
I wouldn't ever dare to publish untested code

I think it should work flawlessly. Unless you connect your wifi dongles via an external USB hub. In which case the given configuration must be slightly altered.
ok, I don't know this configuration. But at least my suggestion of Post should also work in your special case.