31

How can I connect to 2 WiFi networks at the same time with only 1 WiFi-adapter?

I have two separate wireless networks, to which I need to connect the Ubuntu-PC simultaneously: The first with internet access and the other one without internet access.

I tried to create a Virtual Interface and even though there doesn't seem to be an error, it did not appear in the Network Manager. It would seem, the driver I am using, is ath9k:

lcpi

How can I find out whether my it can create virtual wireless interfaces? Can I replace the driver ath9k, if it doesn't support virtual interfaces?

  • I think you'll need multiple adaptors. But perhaps I'm wrong. http://serverfault.com/questions/192144/connect-to-multiple-ap-with-one-wifi-adapter-under-linux-freebsd might be of interest. – muru Jun 26 '14 at 18:58

2 Answers2

28

Yes you can, if your card support it. First of all look the documentation of iw and especially the page of virtual interfaces. Unless you are running 14.04, that is, due to a bug in udev scripts (probably fixed in 15.10, but no confirmation yet).

Note that in the following description wlan0 is my normal WiFi interface and wlan1 is the name I choosed for the virtual one (it's quite arbitrary). You have to adapt this to your system, of course.

You can create a new virtual interface with:

sudo iw dev wlan0 interface add wlan1 type station 

if your adaptor/driver support it, it's done --- you now have two interfaces; otherwise you will have some type of error or the interface will not appear.

You can check if the new interface exists by typing

 sudo ifconfig -a 

...and see if the wlan1 interface shows up. It will appear in the Network Manager too anyway:

enter image description here

You can remove the virtual interface with

sudo iw dev wlan1 del

I really never used it --- I tried to connect twice to my router and havoc arose (but that probably is normal). Moreover, you will probably need to see if packet forwarding between the two interfaces is enabled by default or not, and you probably need to play a bit with the routing after that. But it's a start.

PD --- one of the thing you will probably have to change is the MAC number of the "virtual" interface, which is by default the same as the other, and will create problems almost for sure.

Rmano
  • 31,947
  • How do I find out, whether my card supports it? – user203053 Jun 26 '14 at 20:57
  • 1
    @user203053, I update the answer. – Rmano Jun 26 '14 at 21:05
  • As an aside, see https://bugs.launchpad.net/ubuntu/+source/udev/+bug/1397654 --- maybe it's broken now – Rmano Nov 30 '14 at 15:13
  • ^^Has anyone found a solution to this bug? I wanted to create a virtual interface but was getting the exact same problem. – George J. Adams Jul 02 '15 at 16:48
  • @GeorgeAdams for what I know, no. The bug report seems as good as dead --- I do not think it has arrived to the developers attention. I bought an extra wifi USB adapter and be done. – Rmano Jul 02 '15 at 16:58
  • I actually need to have a virtual interface (conducting some research). So I can't use an extra adapter. Is there some other solution to make a virtual interface? – George J. Adams Jul 02 '15 at 17:07
  • @GeorgeAdams not that I know. Maybe it's worth another question. Moreover, I am not sure if the bug is Ubuntu-specific or not --- have you tried other distros? – Rmano Jul 02 '15 at 17:17
  • I've only tried this on Ubuntu until now but I will try other distros too. I might ask another question again too. – George J. Adams Jul 02 '15 at 17:25
  • @GeorgeAdams --- the bug says it's fixed now in 15.04 onward. – Rmano Oct 17 '15 at 16:42
  • @GeorgeAdams Excuse me, did you find any solution for Ubuntu 14.04? – Daniyal Javani Nov 11 '15 at 05:02
  • @Daniyal FWIK, no. And I personally don't think it will be fixed for 14.04; newer system (>= 15.10) should have a completely different way of naming device, and it may work there. --- there are just 4 people affected by the problem, it seems. I solved it buying a wifi usb dongle for my hub machine. – Rmano Nov 11 '15 at 08:12
  • @GeorgeAdams Thanks, I can't understand why just 4 people affected as you say! – Daniyal Javani Nov 12 '15 at 14:01
  • @Daniyal,well --- that's the number of affected people on the launchpad bug https://bugs.launchpad.net/ubuntu/+source/udev/+bug/1397654 – Rmano Nov 12 '15 at 16:06
  • 2
    In 16.04, the other interface is created but doesn't have an IP assigned and is listed as "Not enabled" in Network Manager. Any ideas how to finish the deed? – TenLeftFingers Oct 06 '16 at 18:51
  • Same to me, in 16.04 it appears as "not ready" in network manager – Kostanos Jul 21 '18 at 16:18
  • I had success in Ubuntu 18.04 when I paired this command with a change in mac-address: sudo ip link set dev <virtual-device-name> address <new-mac-address> – xcud Aug 06 '18 at 17:36
  • Trying on 18.04, was able to add virtual device and change mac, but it never connects. I'm not sure if my wifi card supports it. – Philip Kirkbride Jun 06 '19 at 18:54
  • My question is whether you can choose which process uses internet from what virtual interface, so that I can connect to both my corporate wifi and my hotspot from the phone. – Johannes Lemonde Jun 04 '21 at 11:53
3

That would be much convinient to add as comment but it would need 50 reputation score. Sorry


I have found another answer in this topic and it has a little extra just to save some time.
e.g.
About using both interfaces at the same time and the message about them not being unique: This is probably because they both use the same MAC address. You can try to change the MAC address of the new interface before activating it.
 ip link set dev <dev-name> address <new-mac-address> 

https://superuser.com/questions/592296/using-iw-to-add-a-virtual-wireless-interface-getting-the-error-no-such-device

osiixy
  • 432
  • 2
  • 11