Disabling the wireless network on Linux is usually a simple process with the help of the command-line interface. Doing so can be useful in situations where we need higher security, better speed, or to save battery life. In this tutorial, we’ll see how to disable a wireless network from the command line in Linux.
Specifically, we’re using an Ubuntu 22.04 system for this tutorial. However, most of the commands can be applied to most major Linux distributions without changes.
2. Using nmcli Command
Let’s check the status of our Wi-Fi network with nmcli:
$ nmcli radio wifi enabled
Indeed, the wireless network connection is already enabled in our case.
Let’s disable the wireless network with the off option of nmcli:
$ nmcli radio wifi off
Conversely, we use the on option to enable the wireless network:
$ nmcli radio wifi on
This re-enables the wireless network on our system.
3. Using rfkill Command
The rfkill command is a way to control low-level switches that can turn on or off various wireless devices like Wi-Fi, Bluetooth, and others. Importantly, rfkill needs sudo access to block or unblock devices. Let’s see it in action.
First, we list all the available wireless devices:
$ rfkill list 0: phy0: Wireless LAN Soft blocked: no Hard blocked: no 3: hci0: Bluetooth Soft blocked: no Hard blocked: no
A Hard blocked device is physically turned off and cannot be turned back on with software. On the other hand, a Soft blocked device can be toggled with software.
So, to disable a wireless network, we first get the device number of the target wireless device from the output of rfkill list. After that, to block the device, we use the block sub-command:
$ sudo rfkill block <device_number>
Here, we replace <device_number> with the number of the wireless device we want to disable.
Let’s block a device with device number 0, which is the wireless LAN in our case:
$ sudo rfkill block 0
This command disables the specified wireless device.
Similarly, we can enable the wireless device using unblock:
$ sudo rfkill unblock <device_number>
To illustrate, let’s re-enable our wireless device using the unblock sub-command:
$ sudo rfkill unblock 0
This command enables the wireless device with the index number 0.
4. Using TLP Utility
TLP is a power management tool for Linux that helps optimize the battery life of a laptop. It provides various options to configure the system’s power-saving settings. These include the ability to enable or disable a wireless network.
We can install it using apt:
$ sudo apt install tlp
Now, we can simply switch our Wi-Fi connection on or off with the wifi command:
$ wifi on wifi = on
While on enables the connection, to stop it, we use off:
$ wifi off wifi = off (software)
Interestingly, we can also use the toggle option to switch between Wi-Fi states:
$ wifi toggle
Additionally, we can do the same with a Bluetooth device using the bluetooth command.
5. Using ip Command
The ip command is a versatile way to manage network interfaces. It allows us to control various aspects of network management from the command line. Notably, sudo privileges are also necessary for the ip command to control network interfaces.
Let’s disable Wi-Fi from the Linux command line using the ip command.
First, we list all available network interfaces:
$ ip link show ... 3: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000 link/ether d0:c5:d3:3d:22:cf brd ff:ff:ff:ff:ff:ff altname wlp3s0 ...
Next, we look for the name of the Wi-Fi interface from the output of ip link show above. It usually starts with wl. For example, in our case the Wi-Fi interface name is wlo1.
Once we’ve got the interface name, we can disable it using the down option:
$ sudo ip link set wlo1 down
Here, we can replace wlo1 with the interface name of our Wi-Fi interface. This command disables the given Wi-Fi interface.
Notably, this command shuts down the interface. Usually, this has the same effect as unplugging the cable from the connected device. It’s still possible for the system to use the IP address for internal communications or to receive packets sent to it from other interfaces since the configuration hasn’t been removed.
In the same way, we can re-enable the Wi-Fi interface using the up option:
$ sudo ip link set wlo1 up
Consequently, this command brings up the specified Wi-Fi interface.
In this article, we saw the different ways of disabling a wireless network connection from the Linux command line. Notably, if we’re using multiple tools on a system, they could interfere with each other. For example, if we have disabled the wireless network using rfkill, we might not be able to bring it up using the ip link set command. In this case, we get the error RTNETLINK answers: Operation not possible due to RF-kill.
Hence, it’s usually best to use one particular approach to work with.