JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 1:07 pm

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.

SkyRise
Posts: 179
Joined: Tue Jan 24, 2012 1:20 pm

Re: How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 1:24 pm

Search for "predictable interface names" - they're turned off in Raspbian by default.

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 1:30 pm

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.

SkyRise
Posts: 179
Joined: Tue Jan 24, 2012 1:20 pm

Re: How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 1:47 pm

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.

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 1:54 pm

Here they say it can be done but I dont see the files they are talking about.

https://raspberrypi.stackexchange.com/q ... -and-wlan1

User avatar
DougieLawson
Posts: 36515
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How do you force a wifi interface to be a certain wlanX?

Tue Nov 28, 2017 5:51 pm

JacoFourie wrote:
Tue Nov 28, 2017 1:54 pm
Here they say it can be done but I dont see the files they are talking about.

https://raspberrypi.stackexchange.com/q ... -and-wlan1
Forget that stackexchange stuff it's three year old junk and irrelevant to Raspbian Stretch.

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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Milliways
Posts: 473
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 10:38 am

DougieLawson wrote:
Tue Nov 28, 2017 5:51 pm
JacoFourie wrote:
Tue Nov 28, 2017 1:54 pm
Here they say it can be done but I dont see the files they are talking about.

https://raspberrypi.stackexchange.com/q ... -and-wlan1
Forget that stackexchange stuff it's three year old junk and irrelevant to Raspbian Stretch.

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.
Unless you are using a PI with onboard WiF; for the Pi3 and PIZeroW which is connected over sdio will use the name wlan0

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 11:05 am

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:

Code: Select all

ln -s /dev/null /etc/systemd/network/99-default.link
2. for explicit assignments create a file '/etc/udev/rules.d/72-xxx.rules'. A sample for this looks like this:

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"

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 11:59 am

sparkie777 wrote:
Wed Nov 29, 2017 11:05 am
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:

Code: Select all

ln -s /dev/null /etc/systemd/network/99-default.link
2. for explicit assignments create a file '/etc/udev/rules.d/72-xxx.rules'. A sample for this looks like this:

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"
Does this mean I use the MAC address of each device and config it this way ?

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:08 pm

correct.

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.

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:12 pm

the xxx can I call that static-names ?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6074
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:13 pm

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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:16 pm

@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.
Last edited by sparkie777 on Wed Nov 29, 2017 12:38 pm, edited 9 times in total.

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:26 pm

"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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:28 pm

yes, you can name it that way

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 12:47 pm

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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 1:04 pm

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):

Code: Select all

apt purge firmware-brcm80211
this will leave 'wlan0' (provided by your dongle) alone on your machine and you are done:-)

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 1:38 pm

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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 2:26 pm

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.

Milliways
Posts: 473
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: How do you force a wifi interface to be a certain wlanX?

Wed Nov 29, 2017 11:49 pm

JacoFourie wrote:
Wed Nov 29, 2017 1:38 pm
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.
The on-board WiFi should be allocated `wlan0` even with Predictable Network Interface Names.

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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Thu Nov 30, 2017 4:26 am

@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

Code: Select all

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="brcmfmac", NAME="wlan1"
this allows your dongle to allocate wlan0 since the onboard wlan is forced to wlan1
Last edited by sparkie777 on Sat Dec 02, 2017 5:46 am, edited 1 time in total.

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Thu Nov 30, 2017 7:43 am

Thanks a lot. I will try it out and let you know

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Fri Dec 01, 2017 2:57 pm

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

JacoFourie
Posts: 98
Joined: Thu Mar 10, 2016 6:51 pm

Re: How do you force a wifi interface to be a certain wlanX?

Fri Dec 01, 2017 4:42 pm

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?

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: How do you force a wifi interface to be a certain wlanX?

Fri Dec 01, 2017 5:09 pm

JacoFourie wrote:
Fri Dec 01, 2017 4:42 pm
Have you tested it. Does it work the way you say?
I wouldn't ever dare to publish untested code :D

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.
JacoFourie wrote:
Fri Dec 01, 2017 4:42 pm
The general vendor method does not work.
ok, I don't know this configuration. But at least my suggestion of Post should also work in your special case.

Return to “Raspbian”