In this article, we will show you how to connect to your WiFi network from the command line on modern Linux distributions that use the NetworkManager to manage the network devices.
This article should work on the following listed Linux distributions and other Linux distributions (not listed) that use the NetworkManager for managing the networks and have the “nmcli” command-line tool available.
- Ubuntu
- Debian
- Linux Mint
- Elementary OS
- Fedora
- RHEL
- CentOS Stream
- AlmaLinux
- Rocky Linux
- openSUSE
- SUSE Linux Enterprise Server (SLES)
- Oracle Linux
Topic of Contents:
- Listing All the Network Devices of Linux from the Command Line Using Nmcli
- Searching for Available WiFi Networks on Linux from the Command Line Using Nmcli
- Connecting to a WiFi Network on Linux from the Command Line Using Nmcli
- Checking for WiFi/Internet Connectivity from the Command Line
- Disconnecting from the WiFi Network on Linux from the Command Line Using Nmcli
- Conclusion
Listing All the Network Devices of Linux from the Command Line Using Nmcli
To list all the network devices that are installed on your Linux computer, run the following command:
You should find your WiFi network interface in the list. In our case, the WiFi network interface is called “wlp7s27u1”.
Searching for Available WiFi Networks on Linux from the Command Line Using Nmcli
To list all the WiFi networks in your area, run the following command:
As you can see, all the WiFi networks in our area are listed.
If, for some reason, your desired WiFi SSID is not displayed on the list, do a rescan with the following command:
As you can see, a lot more WiFi networks are listed after the rescan.
Connecting to a WiFi Network on Linux from the Command Line Using Nmcli
To connect to the “NodeKite-2.4G” WiFi network SSID (let’s say) that’s configured with the WPA2 “secret” password, run the following command:
You can also use the BSSID of your WiFi router to connect to the WiFi network as follows:
If you want to connect to a hidden WiFi network with the “HiddenNet” SSID (let’s say), you can do so as follows:
If you have multiple WiFi network interfaces on your computer and you want to connect to a WiFi network using a specific WiFi network interface, you can do so by adding the “ifname” flag at the end as follows:
A new NetworkManager connection should be created and activated and your computer should be connected to the WiFi network.
As you can see, a new “NodeKite-2.4G” NetworkManager connection profile (same name as the WiFi SSID that you configured to connect) is created.
Checking for WiFi/Internet Connectivity from the Command Line
Once you’re connected to your desired WiFi network, your WiFi network interface (wlp7s27u1 in this case) should receive an IP address from your router via DHCP as you can see in the following screenshot:
You should also be able to ping “google.com” (or the domain names of any other popular websites).
Disconnecting from the WiFi Network on Linux from the Command Line Using Nmcli
To disconnect from the WiFi network SSID NodeKite-2.4G, run the following command:
As you can see, the “NodeKite-2.4G” NetworkManager connection is down[1] as well as the “wlp7s27u1”[2] WiFi network interface. You won’t be able to ping the DNS names of any website as well once you’re disconnected from the WiFi network[3].
$ ip a
$ ping -c 3 google.com
Conclusion
In this article, we showed you how to use the “nmcli” NetworkManager command-line tool to list the available WiFi networks in your area and connect to your desired WiFi network. We also showed you how to check for internet connectivity once you’re connected to a WiFi network from the command line on Linux. After reading this article, you should be able to manage the WiFi networks on your Linux system from the command line using the “nmcli” NetworkManager tool.