Switch automatically between usb and built-in wireless cards

New to Debian (Or Linux in general)? Ask your questions here!

Switch automatically between usb and built-in wireless cards

Postby Seigma » 2018-02-13 07:40

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
Seigma
 
Posts: 3
Joined: 2018-02-13 07:30

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

Postby n_hologram » 2018-02-13 15:13

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...
n_hologram
 
Posts: 433
Joined: 2013-06-16 00:10

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

Postby bw123 » 2018-02-13 16:08

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.
User avatar
bw123
 
Posts: 3088
Joined: 2011-05-09 06:02
Location: TN_USA

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

Postby n_hologram » 2018-02-13 16:57

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...
n_hologram
 
Posts: 433
Joined: 2013-06-16 00:10

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

Postby Seigma » 2018-02-14 12:18

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.
Seigma
 
Posts: 3
Joined: 2018-02-13 07:30

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

Postby stevepusser » 2018-02-14 18:06

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
The MX Linux repositories: Backports galore! If we don't have something, just ask and we'll try--we like challenges. New packages: GIMP 2.10.2, Pale Moon 27.9.3, wine-staging 3.10, QuiteRSS 0.18.11, Linux kernel 4.17, Krita 4.0.4
User avatar
stevepusser
 
Posts: 9654
Joined: 2009-10-06 05:53

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

Postby sunrat » 2018-02-14 21:11

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
sunrat
 
Posts: 2330
Joined: 2006-08-29 09:12
Location: Melbourne, Australia

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

Postby bw123 » 2018-02-14 21:36

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.
User avatar
bw123
 
Posts: 3088
Joined: 2011-05-09 06:02
Location: TN_USA

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

Postby n_hologram » 2018-02-18 15:51

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...
n_hologram
 
Posts: 433
Joined: 2013-06-16 00:10

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

Postby Head_on_a_Stick » 2018-02-18 16:13

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.
"Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y a plus rien à retrancher."
— Antoine de Saint Exupéry, Terre des Hommes (1939).
User avatar
Head_on_a_Stick
 
Posts: 7572
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable