dionhouston
Posts: 2
Joined: Fri Sep 13, 2013 2:27 pm

USB->WLANx Assignment

Fri Sep 13, 2013 2:50 pm

Hi all,

Hopefully this is not a basic question. I come from a fairly technical background, but I'm weak in Linux specifics.

I just recently got my Pi, and I'm hoping to do several different projects. One of the first I wanted to get up was a Wireless-Wireless router. As a bit of (probably non-essential) background, I'm currently in Kuwait where our internet provider sets up a pay for internet system using web-based authentication. This is also MAC filtered. Both those qualities make it hard to connect certain devices (e.g. the XBox). So I thought routing that connection makes sense.

So far so good... I have two wireless cards. My desired set up is WLAN0 is the LAN interface, WLAN1 is the WAN interface. Following a variety of guides, I have this working consistently.

The problem is, if both of my wireless devices are plugged into the RPi at the time of boot, there is little consistency on which gets picked up for WLAN0 and WLAN1. I've tried plugging one wireless into the RPi, and the other in the hub, both in the hub, different plugs on the hub. USB is a black box to me, but the only thing I can think of, is perhaps one comes up a few milliseconds quicker or something. Ideally, it'd be nice to not be tied to something physically that affects the logical interface names anyway.

The problem of this of course is that my wireless cards require slightly different set ups for hostapd, etc. So when usb #2 comes up as WLAN0, it breaks hostapd which then breaks DHCP, UPNP, etc.

So here's the question... What's the best way to influence this? I tried changing the sym links for the devices - that didn't work. I thought about creating a script that creates a new /etc/network/interfaces, hostapd.conf, etc. but that seems kludgy.

Realize that this is probably a relatively unusual situation, appreciate any help you guys can give me :)

Dion

MrEngman
Posts: 3830
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: USB->WLANx Assignment

Fri Sep 13, 2013 5:27 pm

Hi,

You probably need to use udev. This service assigns permanent names to I/O devices. It used to be used for wifi at one time but was removed maybe a year or so ago. I have re-enabled it on some of my images so I can use multiple wifi adaptors and ensure that they maintain the same names permanently across reboots etc.

To enable it to control the assignment of permanent names to wlan devices you will need to edit file /lib/udev/rules.d/75-persistent-net-generator.rules and change line

Code: Select all

# device name whitelist
KERNEL!="ath*|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
                                        GOTO="persistent_net_generator_end"
to

Code: Select all

# device name whitelist
KERNEL!="ath*|wlan*[0-9]|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
                                        GOTO="persistent_net_generator_end"
With this modification a file will be generated /etc/udev/rules.d/70-persistent-net.rules which will be used to associate a wifi MAC address with a particular wifi name e.g. wlan0 or whatever.

Probably the easiest way to make sure wifi adaptors are assigned the names you want, wlan0 etc., is to first remove the wifi adaptors before editing /lib/udev/rules.d/75-persistent-net-generator.rules. Then power off and insert the wifi adaptor you want to be wlan0 and boot the system. This wifi should now be permanently assigned the name wlan0. Now add the second adaptor wlan1, probably after powering down first. After rebooting the second adapter should be assigned the permanent name wlan1. You can review the names assigned by viewing the file /etc/udev/rules/70-persistent-net.rules. This file will maintain a list of wifi adaptors with each different MAC address assigned to a particular wifi name.

Hope this does what you need. PLEASE NOTE: I have only made these changes to raspbian images. If you use a different image you may have to make alterations as to how to do this.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

dionhouston
Posts: 2
Joined: Fri Sep 13, 2013 2:27 pm

Re: USB->WLANx Assignment

Fri Sep 13, 2013 6:25 pm

That is PRECISELY what I was looking for. Now it looks like I just need to fight with /etc/network/interfaces a little bit more and I should be golden.

This is actually precisely the reason I bought an RPi. I was looking to get back involved in "fun" computing like I did way back in the day (on Commodore 64s and CP/M boxes). I was tempted by some boards that were more powerful and more expensive, but the community here is what made my decision.

Thanks!

mnbv0987
Posts: 1
Joined: Mon Oct 31, 2016 4:29 am

Re: USB->WLANx Assignment

Mon Oct 31, 2016 4:32 am

MrEngman wrote:Probably the easiest way to make sure wifi adaptors are assigned the names you want, wlan0 etc., is to first remove the wifi adaptors before editing /lib/udev/rules.d/75-persistent-net-generator.rules. Then power off and insert the wifi adaptor you want to be wlan0 and boot the system. This wifi should now be permanently assigned the name wlan0. Now add the second adaptor wlan1, probably after powering down first. After rebooting the second adapter should be assigned the permanent name wlan1.
This doesn't work.

The first part creates 70-persistent-net.rules with a wlan0 device. After inserted the other dongle it is immediately assigned wlan1.

But then after reboot, the second dongle is named "rename4" instead of "wlan1" and nothing else is added to 70-persistent-rules.

Any other suggestions?

epoch1970
Posts: 3064
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: USB->WLANx Assignment

Mon Oct 31, 2016 10:21 am

I wouldn't mess with /lib/udev/rules.d/, rather add rules in /etc/udev/rules.d/.
This "rename4" name you get is due to a conflict in udev rules.
It would be also much easier if I were to choose a name different from the system's "wlan" name

I have this in /etc/udev/rules.d/70-my_network_interfaces.rules:

Code: Select all

# Built-in wifi interface used in hostapd - identify device by MAC address
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="b8:27:eb:01:02:03", NAME="wap0"
...
I refer to this wap0 name everywhere in the system (eg interfaces, dnsmasq...) without issue.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Advanced users”