Prevent Ubuntu 22.04 from Trying to Autoconnect to New Wi-Fi Networks
If you've ever found yourself in a situation where your Ubuntu 22.04 system is trying to connect to a new Wi-Fi network without your permission, you're not alone. This can be a frustrating experience, especially if you're in a hurry or if you don't want to connect to that particular network. In this article, we'll show you how to prevent Ubuntu 22.04 from trying to autoconnect to new Wi-Fi networks.
Why Does Ubuntu Try to Autoconnect to New Wi-Fi Networks?
Ubuntu tries to autoconnect to new Wi-Fi networks as a convenience feature. The idea is that if you've connected to a network before, Ubuntu will remember it and try to connect to it again in the future. This can be helpful if you're in a location where you frequently use the same Wi-Fi network, such as your home or office. However, it can also be annoying if you don't want to connect to a particular network.
How to Prevent Ubuntu from Autoconnecting to New Wi-Fi Networks
To prevent Ubuntu from autoconnecting to new Wi-Fi networks, you can follow these steps:
- Click on the Wi-Fi icon in the top right corner of the screen.
- Click on
Wi-Fi Settings. - Click on the gear icon next to the Wi-Fi network you want to prevent Ubuntu from autoconnecting to.
- Uncheck the box next to
Connect automatically when in range. - Click
Closeto save your changes.
#!/bin/bash
# Prevent Ubuntu from autoconnecting to a specific Wi-Fi network
WIFI\_SSID="MyWiFiNetwork"
# Check if the Wi-Fi network is currently connected
if nmcli device status | grep -q "^${WIFI\_SSID} wifi-connected,${WIFI\_SSID},"; then
# Disconnect from the Wi-Fi network
nmcli device disconnect "${WIFI\_SSID}"
# Forget the Wi-Fi network
nmcli device wifi rescan
nmcli device wifi forget "${WIFI\_SSID}"
fi
In this article, we've shown you how to prevent Ubuntu 22.04 from trying to autoconnect to new Wi-Fi networks. By following the steps outlined in this article, you can ensure that Ubuntu only connects to Wi-Fi networks that you explicitly tell it to connect to.
References
- Ubuntu Help: Connecting to a wireless network
- Ask Ubuntu: How can I prevent Ubuntu from automatically connecting to certain Wi-Fi networks?
- NetworkManager Developer Documentation
Note: This article assumes that you are using the default GNOME desktop environment on Ubuntu 22.04. If you are using a different desktop environment, the steps may be slightly different.