Nmtui or nmcli, connect to a Wi-Fi network from the terminal

 

about nmtui or nmcli

In the next article we are going to take a look at how we can establish a Wi-Fi connection from the terminal with nmtui or nmcli. If you have a device with wireless capability, you will be able to connect easily from the graphical environment to the Internet, but in some cases it is possible that the user is interested in being able to do this from the terminal

The nmtui tool is a text-based user interface developed to manage networks. It is not as powerful or complete as its sister nmcli, but the console interface that it offers us is very simple, intuitive and also does not require a learning curve. Nmcli is another tool for the terminal, which manages the NetworkManager of our Gnu / Linux system. This tool is effective and fast, in addition to being very useful for creating, displaying, editing, deleting, activating or deactivating network connections, it is also capable of controlling and showing us the status of the network hardware.

Connect to a WiFi network from the terminal with nmtui or nmcli

Using nmtui

Nmtui (Network Manager Text User Interface) is a command line tool that used for network configuration on Gnu / Linux systems. When run, it invokes a graphical text interface that helps users configure network interfaces in a simple and effective way. We can also use it to connect to a wireless network with a few simple steps.

Launch nmtui

For, start nmtui we are going to open a terminal (Ctrl + Alt + T) and execute the following command:

nmtui

This command will launch your graphical interface. In it we will have to to select 'Activate a connection' as shown in the following screenshot. Once selected, with the key TAB we can get to select 'I Accept'.

nmtui activate connection

Connect to a wireless network

On the next screen we will see the network interfaces and wireless networks that are available. For this example I am going to select the WiFi network created for this article, which I called SapoWifi and that can be selected by pressing Intro.

nmtui network selection

The next thing we will have to do is enter the password for the wireless network in the pop-up dialog that will appear. Once again, we will use the key TAB to select the option 'I Accept'.

nmtui write wifi key

Once successfully connected to the wireless network, we will only have to select the option 'Back'to return to the home screen of the nmtui interface and, finally, go to the option'Logout'.

For, test internet connectivity, we can ping Google DNS from the terminal as shown in the following screenshot:

nmtui ping google dns secondary

Using nmcli

The command line tool nmcli is another utility that we can use to connect to a wireless or WiFi network from the terminal. Just doing it we will only have to follow the following steps.

Get the name of our WiFi adapter and wireless network

First of all, let's use the iwconfig command to display the system's wireless interfaces and check their status:

iwconfig with nmcli

iwconfig

The output of the above command shows that there is a wireless interface labeled as wlp9s0 in this case. Also, from the output, we can see that we are not connected to any wireless network.

For, list wireless interfaces, we will have to execute the command:

iw dev interface name

iw dev

We can also check if the interface is connected to some wireless device using the command:

iw nombre-interfaz link

In this example, the command to use would be the following:

wifi connection status

iw wlp9s0 link

The output confirms that we are not connected to any wireless network.

Connect to a WiFi network from the terminal

Before connecting to a WiFi network, it is interesting perform a scan from the terminal to search for available wireless networks. With the data from this example, we will be able to do this with the command:

Wi-Fi networks available with nmcli

sudo iwlist wlp9s0 scan | grep -i ESSID

The output will indicate the wireless networks at our disposal to which we can connect, as long as we have their corresponding password. As in the previous case we are going to connect to the network 'SapoWifi'using nmcli command as follows:

activate connection with nmcli

nmcli dev wifi connect [NOMBRE-ESSID] password [ESCRIBIR LA CONTRASEÑA]

After executing the command, we should get the result that confirms that we have successfully connected to the WiFi network. Now we can confirm that the interface is connected using the command iwconfig shown lines above.

In addition we can also check if we are connected with the command:

nmcli connection verification

sudo iw wlp9s0 link

Generally, most users prefer to use graphical means to select and connect to their wireless network. Nevertheless, for fans of the terminal or for some specific cases, connect to a WiFi network from the terminal is also a viable option.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.