Simple Steps to Access Wi-Fi via Linux Terminal with Nmcli

Simple Steps to Access Wi-Fi via Linux Terminal with Nmcli

ยท

5 min read

If you're a Linux user, you might occasionally find yourself in a situation where you need to connect to Wi-Fi without the luxury of a graphical user interface. Fear not, for NetworkManager Command Line Interface (nmcli) is here to save the day.

In this comprehensive guide, we will walk you through the steps of connecting to Wi-Fi using nmcli, the powerful command-line tool for managing network connections in Linux. So, whether you're on a headless server or just prefer the terminal, we've got you covered.

What Is nmcli?

First things first, what exactly is nmcli? NetworkManager is a widely used application in the Linux world for identifying and configuring internet connections. While most Linux distributions provide a user-friendly graphical interface for NetworkManager, not all situations grant you access to these conveniences, especially if you're working on a headless server.

Enter nmcli, the command-line interface for NetworkManager. Unlike some other methods of connecting to Wi-Fi via the terminal, nmcli offers a relatively hassle-free solution. Instead of dealing with intricate configuration files or memorizing your PSK key, all you need to get started is the SSID (the name of the network you wish to connect to) and the network password (if there is one).

Now, let's dive into the step-by-step process to connect to Wi-Fi using nmcli.

Step 1: Enable Your Wi-Fi Device

Before you can connect to a Wi-Fi network, your Wi-Fi card needs to be enabled. To check the status of all your network interfaces, open your terminal and execute the following command:

nmcli dev status

Running this command will provide you with a list of your network devices, including their type, state, and network connection information.

If you're unsure whether your Wi-Fi device is currently enabled or disabled, you can check its status using:

nmcli radio wifi

If the output indicates that Wi-Fi is disabled, you can enable it by running:

nmcli radio wifi on

Step 2: Identify a Wi-Fi Access Point

To connect to a Wi-Fi network, you need to know the name of the access point, commonly referred to as the SSID. If you don't already know the SSID of the network you want to connect to, you can scan for nearby Wi-Fi networks using the following command:

nmcli dev wifi list

Look for the name listed under the 'SSID' column for the network you intend to connect to. You'll need this information for the next step.

Step 3: Connect to Wi-Fi With nmcli

With your Wi-Fi device enabled and the SSID identified, you're now ready to establish a connection. You can use the following command, replacing network-ssid with the actual name of your network:

sudo nmcli dev wifi connect network-ssid

If your Wi-Fi network employs WEP or WPA security, you can specify the network password in the command as follows:

sudo nmcli dev wifi connect network-ssid password "network-password"

Alternatively, if you prefer not to display your password on the screen for security reasons, you can use the --ask option as follows:

sudo nmcli --ask dev wifi connect network-ssid

Upon execution, the system will prompt you to enter your network password without displaying it visibly on the screen.

Your Linux device should now be successfully connected to the Wi-Fi network. You can test the connection by pinging a website, such as Google:

ping google.com

NetworkManager will automatically save the connection, ensuring it reconnects on boot. You won't need to reissue the connection command each time you start your Linux machine.

Managing Network Connections on Linux With nmcli

Nmcli offers additional functionalities for managing network connections. You can view all the saved connections on your system by executing the following command:

nmcli con show

If you're currently connected to one network but wish to switch to another saved connection, you can disconnect from the current network by bringing the connection down. To do so, specify the SSID or, if you have multiple connections with the same SSID, use the UUID:

nmcli con down ssid/uuid

To connect to another saved connection, use the up option in the nmcli command, ensuring that you specify the SSID or UUID of the new network you wish to connect to:

nmcli con up ssid/uuid

Connecting to Wi-Fi Without a GUI on Linux

Congratulations! You've successfully connected to a Wi-Fi network without relying on a graphical user interface. This newfound skill makes you a more versatile Linux user and allows you to work efficiently in various environments, even headless servers.

If you need to transfer files wirelessly, numerous Linux applications are at your disposal, whether or not you are running a desktop environment.

In conclusion, nmcli is a powerful tool that empowers Linux users to manage network connections seamlessly through the command line. It's a valuable skill to have in your Linux toolkit, especially when graphical interfaces are not readily available. So, next time you find yourself in need of a Wi-Fi connection on your Linux device, remember that nmcli has your back.

Additional Resources

For more in-depth information and advanced usage of nmcli, you can refer to the official NetworkManager documentation here.

If you're interested in learning more about Linux command-line networking tools, our guide on "Essential Networking Commands for Linux" will provide you with a comprehensive overview here.

In the event that you encounter any issues or have questions, feel free to ask for assistance on popular Linux forums like Ask Ubuntu and Stack Overflow. The Linux community is always ready to help fellow enthusiasts.

With nmcli, connecting to Wi-Fi from the Linux terminal is a breeze, offering a reliable and efficient method for Linux users, even in the absence of a graphical user interface. So, go ahead and explore the world of Wi-Fi connectivity on your Linux machine, and master the art of the command line.

ย