guillaumewuip
Posts: 5
Joined: Tue May 12, 2015 8:06 am

2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 8:53 am

Hi.

I'm a real beginner in linux networking and I'm trying to connect my Pi to two wifi at the same time.
What I've done so far :
  • buying two different wifi dongle (TP-LINK TL-WN722N and Edimax EW-7811UN)
  • they both work separately
  • I can connect my Pi to two different wifi network using the two dongles
Here's my /etc/network/interfaces :

Code: Select all

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-ssid "wifi1"
        wpa-psk "pwd1"

auto wlan1
allow-hotplug wlan1
iface wlan0 inet dhcp
        wpa-ssid "wifi2"
        wpa-psk "pwd2"
Here's the output of sudo ip show :

Code: Select all

eth0      Link encap:Ethernet  HWaddr b8:27:eb:8c:e2:10  
          inet addr:192.168.0.19  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:109 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12425 (12.1 KiB)  TX bytes:8743 (8.5 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 74:da:38:0c:c6:f0  
          inet addr:192.168.43.43  Bcast:192.168.43.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:3 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4198 (4.0 KiB)  TX bytes:2025 (1.9 KiB)

wlan1     Link encap:Ethernet  HWaddr c0:4a:00:2a:ab:6c  
          inet addr:192.168.0.32  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:44 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6920 (6.7 KiB)  TX bytes:1147 (1.1 KiB)
But I want wlan0 to use TP-LINK TL-WN722N and wlan1 to use Edimax EW-7811UN.

After googling I haven't found anything helping. Is there a command in /etc/network/interfaces to force an interface to use a specific device ? Or is it always the usb port order ?

Thanks :)

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 9:12 am

hi, use the

sudo route

... command to view|set your default gateway. Basically, you need to define which network interface (iface) which nic will be used for default gateway out to the Internet. The IP address, netmask, default route and iface must all be set correctly.
marcus
:ugeek:

guillaumewuip
Posts: 5
Joined: Tue May 12, 2015 8:06 am

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 10:09 am

I don't really understand. I could use route to config which card goes with which interface ?

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

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 10:11 am

You can use udev to assign fixed names. This used to be used but for some reason was changed way back so wlanx did not get a fixed name.

So first remove the dongle you want calling wlan1, then ...

What you need to do is edit file /lib/udev/rules.d/75-persistent-net-generator.rules and add wlan* to the device name whitelist.

So open file /lib/udev/rules.d/75-persistent-net-generator.rules using command

Code: Select all

sudo nano /lib/udev/rules.d/75-persistent-net-generator.rules
then change line 20 from this

Code: Select all

# device name whitelist
KERNEL!="ath*|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
                                        GOTO="persistent_net_generator_end"
to this by adding wlan*| to the beginning of the list of devices to assign fixed names

Code: Select all

# device name whitelist
KERNEL!="wlan*|ath*|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
                                        GOTO="persistent_net_generator_end"
Terminate the editor with keys cntl-x,y enter.

Now reboot and you should find the wifi module named wlan0, Now plug in the second dongle and it should be called wlan1, and you should now find that the dongles always keep these names.

Editing file /lib/udev/rules.d/75-persistent-net-generator.rules has caused a new file to be generated /etc/udev/rules.d/70-persistent-net.rules which stores data about your modules and assigns the names. It will look something like

Code: Select all

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# USB device 0x:0x (rtl8821au)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="74:da:38:2a:d3:86", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

# USB device 0x:0x (rtl8188eu)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="e8:94:f6:25:f0:f4", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan1"
If you add different dongles they will be assigned new names e.g wlan2 etc.. The names are assigned based on their MAC address. You can change names if necessary by editing file /lib/udev/rules.d/75-persistent-net-generator.rules.

If you want to stop using these fixed addresses remove "wlan*|" from file /lib/udev/rules.d/75-persistent-net-generator.rules and delete the file /lib/udev/rules.d/75-persistent-net-generator.rules.

Hopefully this helps and is not too confusing.


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

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

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 10:13 am

guillaumewuip wrote:I don't really understand. I could use route to config which card goes with which interface ?
Yes, or you can set a rule to do the same thing... see above.
marcus
:ugeek:

guillaumewuip
Posts: 5
Joined: Tue May 12, 2015 8:06 am

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 10:26 am

Thanks both of you for your help.
I've used the MrEngman solution which works perfectly and is perfectly explain (and thank you for the /etc/udev/rules.d/70-persistent-net.rules tips).

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

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Tue May 12, 2015 10:28 am

guillaumewuip wrote:Thanks both of you for your help.
I've used the MrEngman solution which works perfectly and is perfectly explain (and thank you for the /etc/udev/rules.d/70-persistent-net.rules tips).
Glad to be able to help.


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

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

henryco
Posts: 33
Joined: Sat Jul 19, 2014 12:25 pm

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Mon Sep 05, 2016 7:45 pm

Hi ,
i also have several wifi devices and would like one to be renamed wlTx and other ones as usual e.g wlan0, wlan1, ...

i can successfully rename a device using idVendor or idProduct with this line

SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0cf3", ATTRS{idProduct}=="9271", KERNEL=="wlan*", NAME="wlTx"

but because all devices have the same idVendor and idProduct i rather need to do it with the MAC address , but it does not work

I suspect something wrong with the MAC address ifconfig gave me for such device :

Link encap:UNSPEC HWaddr EC-08-6B-1C-4A-77-00-00-00-00-00-00-00-00-00-00

why are there those 00 added to the 48 bits Mac address ?

Anyway i tried both the 00 as in:

SUBSYSTEM=="net", ACTION=="add", ATTRS{address}=="EC:08:6B:1C:4A:77:00:00:00:00:00:00:00:00:00:00", KERNEL=="wlan*", NAME="wlTx"

or without the 00 , but nothing works... can anyone help? thanks

henryco
Posts: 33
Joined: Sat Jul 19, 2014 12:25 pm

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Mon Sep 05, 2016 9:15 pm

problem solved: MAC address must be written in lowercase !

larsnl
Posts: 1
Joined: Wed Dec 05, 2018 9:25 pm

Re: 2 wifi , 2 devices: force wlan0 to use one specific

Wed Dec 05, 2018 9:28 pm

henryco wrote:
Mon Sep 05, 2016 9:15 pm
problem solved: MAC address must be written in lowercase !
Man!
You're my hero of today :)
thanks..

Return to “Troubleshooting”