Re: [Solved] Command to Toggle wifi adapter enabled/disabl

Questions about Wi-Fi and other network devices, file sharing, firewalls, connection sharing etc
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
johnywhy

Re: [Solved] Command to Toggle wifi adapter enabled/disabl

Post by johnywhy »

hi

i have two wifi adapters, the motherboard adapter, and a usb dongle.

i don't want to blacklist the internal adapter, but i don't want it to connect automatically either.

currently, both adapters are connecting at the same time, which doesn't make sense.

ps, if both are connected, would both contribute to my download speed?

thx!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 6 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: How to prevent adapter from connecting without blacklist

Post by Cosmo. »

In the settings for the connection you can unset the option for automatically connect.
johnywhy

Re: How to prevent adapter from connecting without blacklist

Post by johnywhy »

you mean for each hotspot?

that will work, but was hoping for a device setting, rather than hotspot setting. No luck?

if i have to go to the trouble of configuring every hotspot, i'd prolly leave autoconnect on, and pick the preferred device MAC address on the wifi tab. Hm, but i must not understand the purpose of that setting, since both devices are autoconnecting. What does that device MAC address setting do?

many thx
niowluka

Re: How to prevent adapter from connecting without blacklist

Post by niowluka »

johnywhy wrote:i don't want to blacklist the internal adapter
Why not ?
johnywhy wrote:if both are connected, would both contribute to my download speed?
No, by default Mint will actually be using just one of those (the first one establishing a connection).
johnywhy

Re: How to prevent adapter from connecting without blacklist

Post by johnywhy »

niowluka wrote:
johnywhy wrote:i don't want to blacklist the internal adapter
Why not ?
maybe because i want to be able to fallback to it, if the dongle breaks, or is lost.

Or maybe i'm just spoiled and i want a quick gui way to enable/disable devices.

another reason i'm hesitant to blacklist the old adapter is because i'm still evaluating the new adapter.

Another reason: at home I can use the internal adapter. Elsewhere I use the dongle.
Last edited by johnywhy on Thu Sep 17, 2015 1:59 pm, edited 2 times in total.
JeremyB
Level 21
Level 21
Posts: 13851
Joined: Fri Feb 21, 2014 8:17 am

Re: How to prevent adapter from connecting without blacklist

Post by JeremyB »

You may be able to accomplish what you want with

Code: Select all

sudo ifconfig wlan0 down
It may or may not be persistant after a reboot but if it does work and you want to reverse it just use

Code: Select all

sudo ifconfig wlan0 up
niowluka

Re: How to prevent adapter from connecting without blacklist

Post by niowluka »

johnywhy wrote:another reason i'm hesitant to blacklist the old adapter is because i'm still evaluating the new adapter.
Blacklisting is not permanent. It's just preventing a driver to load at boot. You can then load / unload the driver at will, thus enabling / disabling the device.
johnywhy

Re: How to prevent adapter from connecting without blacklist

Post by johnywhy »

JeremyB wrote:

Code: Select all

sudo ifconfig wlan0 down
to reverse it just use

Code: Select all

sudo ifconfig wlan0 up
Update: not solved. see next post.

extra credit:
i'd like to assign both to a single keyboard key as a 'toggle', but i cannot find a way to check on the up/down state of the interface. Any ideas?
johnywhy

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by johnywhy »

Update: Not solved. It worked until a reboot. Now, ifconfig return is weird, unexpected.

On boot, i can see both interfaces in Network Manager, and i get:
$ sudo ifconfig
eth0 Link encap:Ethernet HWaddr ac:22:0b:0d:ee:96
UP BROADCAST MULTICAST MTU:1500 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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:19

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:173 errors:0 dropped:0 overruns:0 frame:0
TX packets:173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12642 (12.6 KB) TX bytes:12642 (12.6 KB)

ra0 Link encap:Ethernet HWaddr 00:e1:b0:27:84:71
inet addr:10.3.192.177 Bcast:10.3.255.255 Mask:255.255.0.0
inet6 addr: fe80::2e1:b0ff:fe27:8471/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7721 errors:0 dropped:0 overruns:0 frame:0
TX packets:324 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1686498 (1.6 MB) TX bytes:49929 (49.9 KB)

wlan0 Link encap:Ethernet HWaddr 0c:84:dc:09:2b:80
UP BROADCAST MULTICAST MTU:1500 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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
after this:
sudo ifconfig wlan0 down
i can STILL see the internal interface in Network Manager, and i get:
eth0 Link encap:Ethernet HWaddr ac:22:0b:0d:ee:96
UP BROADCAST MULTICAST MTU:1500 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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:19

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:229 errors:0 dropped:0 overruns:0 frame:0
TX packets:229 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:18341 (18.3 KB) TX bytes:18341 (18.3 KB)

ra0 Link encap:Ethernet HWaddr 00:e1:b0:27:84:71
inet addr:10.3.192.177 Bcast:10.3.255.255 Mask:255.255.0.0
inet6 addr: fe80::2e1:b0ff:fe27:8471/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28698 errors:0 dropped:0 overruns:0 frame:0
TX packets:967 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6454832 (6.4 MB) TX bytes:204377 (204.3 KB)

wlan0 Link encap:Ethernet HWaddr 0c:84:dc:09:2b:80
UP BROADCAST MULTICAST MTU:1500 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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
thx for any help!
JeremyB
Level 21
Level 21
Posts: 13851
Joined: Fri Feb 21, 2014 8:17 am

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by JeremyB »

The rfkill state might be remembered so post the output of

Code: Select all

rfkill list all
johnywhy

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by johnywhy »

JeremyB wrote:post the output of

Code: Select all

rfkill list all
$ rfkill list all
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: asus-wlan: Wireless LAN
Soft blocked: no
Hard blocked: no
niowluka wrote:You can then load / unload the driver at will, thus enabling / disabling the device.
--how?

thx
ralplpcr
Level 6
Level 6
Posts: 1096
Joined: Tue Jul 28, 2015 10:11 am

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by ralplpcr »

Is this along the lines of what you're looking for?
I'm not sure which flavor of Mint you're using, but at least in Cinnamon you can easily turn on/off whichever Wifi connection you want by using the sliders.
Screenshot from 2015-09-17 09_26_50.png
johnywhy

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by johnywhy »

ralplpcr wrote: in Cinnamon you can easily turn on/off whichever Wifi connection you want by using the sliders.
I'm in xfce.

A GUI or CLI solution would be fine.
ralplpcr
Level 6
Level 6
Posts: 1096
Joined: Tue Jul 28, 2015 10:11 am

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by ralplpcr »

johnywhy wrote:I'm in xfce.

A GUI or CLI solution would be fine.
I don't have an XFCE installation handy with multiple Wifi adapters, but I think you can do that from the GUI as well. What do you see when you click on the network icon in your "systray" (panel - lower right)?

There should be an entry allowing you to "disconnect", and I believe it should show both adapters individually... can you post a screen shot of what you see? (press PrtSc, then attach the resulting screenshot into this thread)

Here's what I see with 1 Ethernet and 1 Wifi adapter:
20150917_151323.jpg
johnywhy

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by johnywhy »

ralplpcr wrote:. What do you see when you click on the network icon in your "systray" (panel - lower right)? There should be an entry allowing you to "disconnect", ]
"Disconnect" is not the same as "disable." There's no "disable" option.
ralplpcr
Level 6
Level 6
Posts: 1096
Joined: Tue Jul 28, 2015 10:11 am

Re: [Unsolved] Disable wifi adapter without blacklisting?

Post by ralplpcr »

johnywhy wrote: "Disconnect" is not the same as "disable." There's no "disable" option.
Alright, then how about this?

Code: Select all

gksudo gedit /etc/network/interfaces
Add the following line to the bottom of the file:
(use wlan0 or wlan1, depending on which one you want to disable)

Code: Select all

iface wlan0 inet manual
Save the file and exit gedit. Then restart network manager:

Code: Select all

sudo service network-manager restart
It should not not start the adapter now until you tell it to start. Though you may need to log out/reboot before that takes effect.
johnywhy

Re: [Unsolved] Command to Toggle wifi adapter enabled/disabl

Post by johnywhy »

ralplpcr wrote:Alright, then how about this?

Code: Select all

gksudo gedit /etc/network/interfaces
performed all your steps, and rebooted. Adapter was disabled.

then i did
sudo ifconfig wlan0 up
adapter did not enable. Should i use a different command?

I googled "iface wlan0 inet manual" and saw some stuff about hotplugging. Does that mean manually plugging in the adapter? If so, can it work with the internal adapter (which is already plugged in on boot, and never unplugged).

ps, i edited my OP title to more accurately describe what i want.

thx!
ralplpcr
Level 6
Level 6
Posts: 1096
Joined: Tue Jul 28, 2015 10:11 am

Re: [Unsolved] Command to Toggle wifi adapter enabled/disabl

Post by ralplpcr »

johnywhy wrote:

Code: Select all

sudo ifconfig wlan0 up
adapter did not enable. Should i use a different command?
I don't have an XFCE box to test at the moment, but I believe from a terminal the steps should be the same. Try entering the following 3 commands to re-enable your adapter and get an IP assigned:

Code: Select all

sudo ip link set wlan0 up
sudo ifconfig wlan0 up
sudo dhclient wlan0
It works on my Cinnamon box, anyhow? :D

FYI - If you want to DISABLE your wlan0, you can simply enter

Code: Select all

sudo ip link set wlan0 down
to instantly turn it off.
johnywhy

Re: [Unsolved] Command to Toggle wifi adapter enabled/disabl

Post by johnywhy »

Tried a few different scenarios, sorry if confusing. Trying not to get confused myself! :P

Scenario 1: Disabled in /etc/network/interfaces
ralplpcr wrote:Try entering the following 3 commands to re-enable your adapter and get an IP assigned

Code: Select all

sudo ip link set wlan0 up
sudo ifconfig wlan0 up
sudo dhclient wlan0
How can i get an IP assigned without connecting to a specific wifi network? I tried this and, after your first command the adapter appears in network manager, with the label "device not managed", and no wifi networks listed. Your second command has no visible affect. After your third command, the command window hangs, with no change in device manager.

If it helps, my /etc/network/interfaces contains:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
iface wlan0 inet manual
Scenario 2: Disabled in /etc/modprobe.d/blacklist

i tried to blacklist the internal adapter using the following:
blacklist RT5390
blacklist wlan0
blacklist Ralink corp. RT5390 Wireless 802.11n 1T/1R PCIe
However, on reboot, it's still listed in Network Manager, and i'm able to connect to a wifi network with it, using Network Manager.


Scenario 3: NOT disabled in /etc/network/interfaces or /etc/modprobe.d/blacklist
ralplpcr wrote:FYI - If you want to DISABLE your wlan0, you can simply enter

Code: Select all

sudo ip link set wlan0 down
to instantly turn it off.
after doing that, i notice lshw shows wlan0 as "DISABLED". However, it's still listed in Network Manager, available networks are still listed underneath it, and i'm able to connect to a wifi network with it, using Network Manager. Something seems wrong here. Same thing happens with sudo ifconfig wlan0 down

Seems that, when lshw shows wlan0 as "DISABLED", it's not really disabled (or network manager overrides the disable?)

thx!
JeremyB
Level 21
Level 21
Posts: 13851
Joined: Fri Feb 21, 2014 8:17 am

Re: [Unsolved] Command to Toggle wifi adapter enabled/disabl

Post by JeremyB »

Post

Code: Select all

lspci -nnk | grep -iA2 net
Locked

Return to “Networking”