1

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

  • 1
    You can disconnect your wifi with nmcli radio wifi off. You can check the status with nmcli radio wifi. To enable WiFi nmcli radio wifi on. – Marmayogi May 14 '19 at 09:42
  • You can also disconnect your wifi with sudo ip link set <device> down. To enable sudo ip link set <device> up. The name can be obtained with ip a command. For example, the is wlp5s0. So give command as sudo ip link set wlp5s0 down to turn off Wi-Fi. Similarly the command sudo ip link set wlp5s0 down turn on Wi-Fi. – Marmayogi May 14 '19 at 09:48
  • 1
    You can create aliases for turn-on as well as for turn-off such as alias WiFiOff='nmcli radio wifi off' and alias 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

3 Answers3

4

How to Enable/Disable WI-Fi interface Adapter?

Method-1:

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

Method-2:

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.

Turn on and off using aliases.

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'

Desktop Shortcut Launcher to turn off Wi-Fi.

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

enter image description here

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.

enter image description here

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.

Desktop Shortcut Launcher to turn on Wi-Fi.

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

enter image description here

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.

enter image description here

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.

Desktop Shortcut Launcher to display Enable/Disable Status of Wi-Fi.

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

enter image description here

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.

Desktop Shortcut Launchers for Wi-Fi on Dash.

Dash displays the presence of all three icons regarding Wi-Fi installed on the system as shown in the screenshot below.

enter image description here

Marmayogi
  • 2,488
1

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:

Wifi Disconnect.png

0

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
FedKad
  • 10,515