Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Switch automatically between usb and built-in wireless cards

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
Seigma
Posts: 3
Joined: 2018-02-13 07:30

Switch automatically between usb and built-in wireless cards

#1 Post by Seigma »

Hello,

Yesterday I got a new wifi usb adapter and I would like to use it as main wireless device. However, I have no idea about how to switch between wireless cards.
So, first of all, how can I shut an interface to switch to another one? Is it correct to just use the code below?

Code: Select all

$ ip link set dev [interface1] down
$ ip link set dev [interface2] up
Secondary, the name of the adaptor interface is kinda dirty, no way to remember it, how can I change it?

And last question, is there a way to set a priority between network interfaces? For example when I plug an ethernet cable, the eth interface has higher priority compared to built-in wireless card interface.
I would like to replicate the same thing with usb wifi adaptor, is there a common way to do this without too many messy scripts?

EDIT: I'm using NetworkManager to manage interfaces.

Thank you in advance,
Seigma

n_hologram
Posts: 459
Joined: 2013-06-16 00:10

Re: Switch automatically between usb and built-in wireless c

#2 Post by n_hologram »

Although I don't use networkmanager, I think what you want to do can be accomplished with some udev scripting and manual network programs/configurations (eg, /etc/network/interfaces and wpasupplicant). That itself is another ballgame, however...
bester69 wrote:There is nothing to install in linux, from time to time i go to google searching for something fresh to install in linux, but, there is nothing
the crunkbong project: scripts, operating system, the list goes on...

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Switch automatically between usb and built-in wireless c

#3 Post by bw123 »

I use a wireless usb sometimes and disable the built in. I do this either through the wireless hotkey or just by running the script.

The script can either just remove the module, rfkill the device, or add the MAC to networkmanager.conf as unmanaged.
[keyfile]
unmanaged-devices=mac:

Without doing this you see two entries for everything in networkmanager, gets confusing. I guess you could automate it, I haven't really needed this enough to try and figure that out. I bet someone has though.
resigned by AI ChatGPT

n_hologram
Posts: 459
Joined: 2013-06-16 00:10

Re: Switch automatically between usb and built-in wireless c

#4 Post by n_hologram »

You should be able to use udev to automate the process, assuming the fundamentals -- like a custom script -- are understood and properly created first.
bester69 wrote:There is nothing to install in linux, from time to time i go to google searching for something fresh to install in linux, but, there is nothing
the crunkbong project: scripts, operating system, the list goes on...

Seigma
Posts: 3
Joined: 2018-02-13 07:30

Re: Switch automatically between usb and built-in wireless c

#5 Post by Seigma »

Thank you for your answers guys!

In the end I decided to use this:
bw123 wrote:I use a wireless usb sometimes and disable the built in. I do this either through the wireless hotkey or just by running the script.

The script can either just remove the module, rfkill the device, or add the MAC to networkmanager.conf as unmanaged.
[keyfile]
unmanaged-devices=mac:

Without doing this you see two entries for everything in networkmanager, gets confusing. I guess you could automate it, I haven't really needed this enough to try and figure that out. I bet someone has though.
However, another BIG problem raised. I was used have lot of configurations for my regular network interface, like scanning mac randomization, cloned mac, and various other stuffs regarding ipv6. It seems like the wifi adapter is having many troubles with switching mac settings, and problems in general. In particular:
- If I want to keep up both the wireless interfaces, they both tries to connect to the same AP whenever I click on it, even if I EXPLICITLY click on the built-in interface window.
- I disabled the built-in wireless interface by putting it into /etc/network/interfaces (so it doesn't get managed by NetworkManager) and disabled my mac settings. seems like the adapter has still many issues connecting in a normal way.

So in the end I may decide to get rid of this buggy NetworkManager and put the wireless adapter as unmanaged device. hope everything will work fine then.

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Switch automatically between usb and built-in wireless c

#6 Post by stevepusser »

You could disable an unwanted interface by unloading its kernel module.

There is some way to go back to the old style wlanX interface names; Debian went with the new predictable yet hard-to-remember names because sometimes two devices would swap the interfaces at boot. MX uses the old style of names...the net says it's a kernel boot command:

Code: Select all

net.ifnames=0 biosdevname=0
MX Linux packager and developer

User avatar
sunrat
Administrator
Administrator
Posts: 6412
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 461 times

Re: Switch automatically between usb and built-in wireless c

#7 Post by sunrat »

There have been a few posts recently (ie last couple of years) about certain interfaces having problems with mac address randomisation.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Switch automatically between usb and built-in wireless c

#8 Post by bw123 »

Seigma wrote:
...another BIG problem raised. I was used have lot of configurations for my regular network interface, like scanning mac randomization, cloned mac, and various other stuffs regarding ipv6. It seems like the wifi adapter is having many troubles with switching mac settings, and problems in general. In particular:
- If I want to keep up both the wireless interfaces, they both tries to connect to the same AP whenever I click on it, even if I EXPLICITLY click on the built-in interface window.
- I disabled the built-in wireless interface by putting it into /etc/network/interfaces (so it doesn't get managed by NetworkManager) and disabled my mac settings. seems like the adapter has still many issues connecting in a normal way.

So in the end I may decide to get rid of this buggy NetworkManager and put the wireless adapter as unmanaged device. hope everything will work fine then.
Networkmanager does have issues, and bugs, but it's VERY configurable so you should be able to work around the problems. I have used two different ways to assign cloned mac, you can either set up the cloned mac in the connection, or seti it by device by creating a section in a *.conf file by using options like these:

[device-A-whatever]
match-device=mac:
wifi.cloned-mac-address=
wifi.generate-mac-address-mask=

You can also restrict a connection to a specific device by using the gui, or editing it through nmtui it's up to you to read the man pages for nm-settings, I think it's pretty complicated. The settings you want to apply for whatever connection is active could be done by the nm-dispatcher, it is documented in man networkmanager.

I have never used both networkmanager and ifupdown at the same time, I think that would be a bigger mess than using one or the other. Both methods have issues and bugs.
resigned by AI ChatGPT

n_hologram
Posts: 459
Joined: 2013-06-16 00:10

Re: Switch automatically between usb and built-in wireless c

#9 Post by n_hologram »

op: just to follow up, I modified my wifi networking script to accommodate your particular issue. If you'd like to test it, it should be fairly easy to write a udev script that runs "wefe -i $usb" on insert and "wefe -i $internal" on removal.

https://github.com/souperdoupe/crunkbon ... fe-netdude
Last edited by n_hologram on 2018-02-18 16:45, edited 1 time in total.
bester69 wrote:There is nothing to install in linux, from time to time i go to google searching for something fresh to install in linux, but, there is nothing
the crunkbong project: scripts, operating system, the list goes on...

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Switch automatically between usb and built-in wireless c

#10 Post by Head_on_a_Stick »

Seigma wrote:is there a way to set a priority between network interfaces?
If you could be persuaded away from NetworkMangler [sic] then systemd-networkd can offer such functionality through the kernel's RouteMetric (or just plain Metric for static IPs) parameter.

This example from the ArchWiki shows how to prefer an ethernet interface over a wireless connection using this method:

https://wiki.archlinux.org/index.php/Sy ... me_machine

It can be adapted for your needs, I think.
deadbang

Post Reply