There is a way to disconnect my laptop from the wifi connection by pressing an icon on the dock and/or by executing a script?
Thanks
There is a way to disconnect my laptop from the wifi connection by pressing an icon on the dock and/or by executing a script?
Thanks
How to Enable/Disable WI-Fi interface Adapter?
To enable your Wi-Fi, run the following command:
$ nmcli radio wifi on
To disbale your Wi-Fi, run the following command:
$ nmcli radio wifi off
To test the status of Wi-Fi whether enabled or not, issue the following command:
$ nmcli radio wifi
disabled
There is another way. In order to apply this method, first you need to find out the Wi-Fi device, so issue the following command:
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 1c:1b:0d:62:cf:95 brd ff:ff:ff:ff:ff:ff
3: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether 1c:1b:0d:62:cf:93 brd ff:ff:ff:ff:ff:ff
4: wlp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
link/ether e4:a4:71:58:d5:e5 brd ff:ff:ff:ff:ff:ff
Refer item-4 in the output which displays the Wi-Fi device wlp5s0
. Notice that the state of device from output is state UP
which means that the Wi-Fi is up and running.
To enable Wi-Fi, run the following command:
$ sudo ip link set wlp5s0 up
To disable Wi-Fi, issue the following command:
$ sudo ip link set wlp5s0 down
To know the status of Wi-Fi, issue the following command:
$ ip link show wlp5s0
4: wlp5s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
link/ether e4:a4:71:58:d5:e5 brd ff:ff:ff:ff:ff:ff
From the above output, one can observe that the state of device is state DOWN
which means that the Wi-Fi is disabled.
You can create alias to turn on Wi-Fi as follows:
alias wifion='nmcli radio wifi on'
Similarly, to turn off create another alias as follows:
alias wifioff='nmcli radio wifi off'
To check the status of Wi-Fi whether it is diabled or not, create another alias as follows:
alias wifi='nmcli radio wifi'
Create a file ~/wifi/wifioff.desktop
and copy the following contents into the file:
[Desktop Entry]
Name=WiFi-Off
Type=Application
Exec=/home/krishna/wifi/wifioff.sh
Icon=/home/krishna/wifi/wifioff.png
Comment=WiFi Off Script
Terminal=true
Categories=Utility;Application;
Now, run the following command to install shortcut file in /usr/share/applications/
directory:
$ sudo desktop-file-install wifioff.desktop
Now create ~/wifi/wifioff.sh
file having the following command:
$ gnome-terminal -e "/bin/bash -c 'nmcli radio wifi off;nmcli radio wifi;$SHELL'"
Now make the script file executable by the following command:
$ chmod +x ~/wifi/wifioff.sh
You may download a suitable icon file.
The ~/wifi/wifioff.png
file represents as the icon of the desktop launcher wifioff.desktop
.
If you click icon WiFi-Off
on Dash, then your Wi-Fi interface will be disabled and you will also see message Disabled
displayed on the command terminal.
You can also install another Desktop Shortcut Launcher
to turn on Wi-Fi. You need three files similar to Wi-Fi Off
which are wifion.desktop, wifion.sh and wifion.png respectively.
Create a file ~/wifi/wifion.desktop
and copy the following contents into the file:
[Desktop Entry]
Name=WiFi-On
Type=Application
Exec=/home/krishna/wifi/wifion.sh
Icon=/home/krishna/wifi/wifion.png
Comment=WiFi On Script
Terminal=true
Categories=Utility;Application;
Now, run the following command to install shortcut file in /usr/share/applications/
directory:
$ sudo desktop-file-install wifion.desktop
Now create ~/wifi/wifion.sh
file having the following command:
$ gnome-terminal -e "/bin/bash -c 'nmcli radio wifi on;nmcli radio wifi;$SHELL'"
Now make the script file executable by the following command:
$ chmod +x ~/wifi/wifion.sh
You may download a suitable icon file.
The ~/wifi/wifion.png
file represents as the icon of the desktop launcher wifion.desktop
.
If you click icon WiFi-On
on Dash, then your Wi-Fi interface will be enabled and you will also see message Enabled
displayed on the command terminal.
You can also install a third Desktop Shortcut Launcher
to find out the status of Wi-Fi whether it is enabled or not. To accomplish this, just follow the procedure.
Create a file ~/wifi/wifistatus.desktop
and copy the following contents into the file:
[Desktop Entry]
Name=WiFi-Status
Type=Application
Exec=/home/krishna/wifi/wifistatus.sh
Icon=/home/krishna/wifi/wifistatus.png
Comment=WiFi Status On Script
Terminal=true
Categories=Utility;Application;
Now, run the following command to install shortcut file in /usr/share/applications/
directory:
$ sudo desktop-file-install wifistatus.desktop
Now create ~/wifi/wifistatus.sh
file having the following command:
$ gnome-terminal -e "/bin/bash -c 'nmcli radio wifi;$SHELL'"
Now make the script file executable by the following command:
$ chmod +x ~/wifi/wifistatus.sh
You may download a suitable icon file.
The ~/wifi/wifistatus.png
file represents as the icon of the desktop launcher wifistatus.desktop
.
If you click icon WiFi-Status
on Dash, then the status of your Wi-Fi interface will be displayed either as Enabled
or Disabled
on the command terminal.
Dash displays the presence of all three icons regarding Wi-Fi installed on the system as shown in the screenshot below.
There is an extension to do what you want as described in Ubuntu Handbook. Open Ubuntu Software
and enter Disconnect WiFi
After installation you can disconnect with image on left and reconnect with image on right:
The following command should work:
nmcli device disconnect wlo1
where wlo1 is your WIFI device. You can get the network device names using:
ip a
or just
nmcli
nmcli radio wifi off
. You can check the status withnmcli radio wifi
. To enable WiFinmcli radio wifi on
. – Marmayogi May 14 '19 at 09:42sudo ip link set <device> down
. To enablesudo ip link set <device> up
. Theip a
command. For example, thewlp5s0
. So give command assudo ip link set wlp5s0 down
to turn off Wi-Fi. Similarly the commandsudo ip link set wlp5s0 down
turn on Wi-Fi.turn-on
as well as forturn-off
such asalias WiFiOff='nmcli radio wifi off'
andalias WiFiON='nmcli radio wifi on'
. You can also create a desktop shortcut launcher for this command (create sh script and add this command) with any icon of your choice. – Marmayogi May 14 '19 at 09:56