Sometimes you may need to connect to wifi using command line in Linux. This is especially true if you are using Linux which does not have a desktop, as in virtual machines. There are many tools, such as nmcli, that allow you to do this in Linux. In this article, we will look at how to connect to wifi using nmcli.
What is nmcli?
nmcli is the command line interface for network manager. Most Linux systems have a desktop version of this tool. But almost every Linux system has a command line interface of this tool too. Unlike other network manager tools, it is very easy to configure and manage networks using nmcli. You can quickly connect to your wifi by simply knowing its SSID (name of your network) and its password.
How to Connect to Wifi using nmcli
Here are the steps to connect to wifi using nmcli.
1. Enable Wifi device
First of all, you need to enable your wifi network card in order to be able to connect to it. Open terminal and run the following command to list all network devices on your system.
$ nmcli dev status
The above command will list all your network devices along with their name, state, type, and connection info.
Alternatively, you can use the following command to check if your wifi is enabled or not.
$ nmcli radio wifi
If the output of command is disabled, then run the following command to enable it.
$ nmcli radio wifi on
2. Identify Wifi point
If you don’t know the name of your wifi network, run the following command to list all nearby wifi networks, including yours.
$ nmcli dev wifi list
In the output, under SSID column, note the name of your wifi.
3. Connect to Wifi
Now that you have enabled wifi and noted the name of your network, run the following command to connect to it.
$ sudo nmcli dev wifi connect network-ssid
In the above command replace network-ssid with the ssid of your network. You will be prompted for password. Enter it for authentication. You may also supply the network password in your command as shown.
$ sudo nmcli dev wifi connect network-ssid password "network-password"
If you don’t want to mention password in your command use the –ask option to prompt the user for password.
$ sudo nmcli --ask dev wifi connect network-ssid
Once you have connected to your network, you can test it using ping command. Here’s an example to ping google.com.
$ ping google.com
If you want to view all network connections saved on your system, run the following command.
$ nmcli con show
If you want to disconnect from a network, use the down keyword. Replace the SSID below with that of your network. If you have multiple networks, replace SSID with UUID of the network.
$ nmcli con down ssid/uuid
On the other hand, if you want to connect to a network, use the up keyword. Replace the SSID below with that of your network. If you have multiple networks, replace SSID with UUID of the network.
$ nmcli con up ssid/uuid
Also read:
How to Set JAVA_HOME in Ubuntu
How to Create Large File in Linux
How to Find JDK Path in Ubuntu
How to Get Length of List in Ubuntu
Difference Between df and du command
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.