Introduction
In this lab, you will learn the fundamentals of managing wireless network connections from the command line on a Linux system. We will be using nmcli, the command-line interface for NetworkManager. NetworkManager is a standard service on most modern Linux distributions that simplifies network configuration. Using nmcli, you can scan for networks, connect, disconnect, and manage connection profiles without needing a graphical user interface.
This lab will guide you through the essential commands to take control of your wireless connectivity, a crucial skill for any Linux administrator or power user. We will be working in a simulated environment, but the commands and concepts are directly applicable to a real-world Linux machine with a wireless card. Please note that while we can simulate a wireless device, this environment does not have real Wi-Fi networks to connect to. This means some commands related to establishing an active connection will not fully succeed, but you will still learn the complete workflow.
Scan for Networks with nmcli device wifi list Command
In this step, you will learn how to scan for available wireless networks. This is the first action you would typically take when trying to connect to a new Wi-Fi network. The nmcli tool provides a simple command to list all visible Wi-Fi access points.
First, let's identify the name of our wireless device. Run the following command:
nmcli device
You should see a device with the type wifi. The device name is likely wlan0. We will use this name in later steps. Your output may show additional network devices like eth0 or docker0. This is normal. The important device for this lab is the one with type wifi, which we will assume is wlan0.
DEVICE TYPE STATE CONNECTION
wlan0 wifi disconnected --
p2p-dev-wlan0 wifi-p2p disconnected --
docker0 bridge unmanaged --
eth0 ethernet unmanaged --
lo loopback unmanaged --
Now, use the nmcli device wifi list command to perform a scan. This command tells NetworkManager to search for nearby wireless networks and display them in a list.
Execute the command in your terminal:
nmcli device wifi list
In a real-world scenario with a physical Wi-Fi card, you would see a list of networks around you. In our simulated environment, the output will be empty, as there are no real Wi-Fi networks. Below is an example of what the output would look like if networks were detected. It shows the network's SSID (name), signal strength, security type, and other details.
IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY
MyHomeWiFi Infra 6 130 Mbit/s 80 ▂▄▆█ WPA2
AnotherNetwork Infra 11 54 Mbit/s 55 ▂▄▆_ WPA2
Public-Hotspot Infra 1 54 Mbit/s 30 ▂▄__ --
This command is essential for discovering which networks are available for you to connect to.
Create and Attempt to Activate a Wi-Fi Connection
In this step, we will connect to a wireless network. The standard command for this is nmcli device wifi connect. However, since we are in a simulated environment without real networks to connect to, this command would fail.
Instead, we will use an alternative and equally important method: creating and activating a NetworkManager connection profile. This approach is very useful for pre-configuring network connections. We will create a profile for a hypothetical network named MyLabWiFi. Remember to use the Wi-Fi device name you found in the previous step, which is likely wlan0.
First, create a new connection profile. This command defines all the necessary settings for the connection.
sudo nmcli connection add type wifi con-name MyLabConnection ifname wlan0 ssid MyLabWiFi
You will see a confirmation message:
Connection 'MyLabConnection' (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) successfully added.
Now that the profile is created, you can attempt to activate it. This is equivalent to connecting to the network.
sudo nmcli connection up MyLabConnection
This command will attempt to connect to the MyLabWiFi network. Since this network does not actually exist in our simulated environment, the command will not be able to establish a connection. It will appear to hang or keep trying to connect. This is expected behavior. After waiting a few seconds, press Ctrl+C to stop the command.
You have now learned how to create a connection profile and how to attempt to bring it up. In a real-world scenario with an available Wi-Fi network, this command would have connected you successfully.
Verify Connection with nmcli connection show Command
In this step, you'll learn how to verify your network status and view configured connection profiles. After attempting to connect, it's good practice to check the status.
The nmcli connection show command lists all the connection profiles saved on your system, whether they are currently active or not.
Run the command to see all profiles:
nmcli connection show
Your output should include the MyLabConnection profile we created in the previous step, along with its UUID and type. The DEVICE column will be empty because the connection is not active.
NAME UUID TYPE DEVICE
MyLabConnection xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx wifi --
To see only the currently active connections, you can add the --active flag. This is very useful for quickly checking your current network status.
nmcli connection show --active
Because our attempt to connect in the previous step could not succeed, this command will produce no output. This confirms that there are no active connections.
This command is your go-to tool for quickly inspecting the state of your network connections.
Deleting a Connection Profile
In this step, you will learn how to delete a connection profile that you no longer need. This is a common cleanup task. Since we were not able to activate the connection, we cannot disconnect it. Instead, we will delete the profile we created.
To delete the MyLabConnection profile, use the nmcli connection delete command followed by the connection name.
Execute the following command:
sudo nmcli connection delete MyLabConnection
You will see a confirmation that the connection was successfully deleted.
Connection 'MyLabConnection' successfully deleted.
To confirm, you can run nmcli connection show again. You will see that MyLabConnection is no longer in the list.
nmcli connection show
This command should now produce no output (or only show other pre-existing connections), confirming the profile has been removed.
Understanding Connection-Dependent Commands
In this final step, we will discuss commands that depend on an active network connection, like speedtest-cli. In the previous steps, we established that we cannot form an active Wi-Fi connection in this simulated environment.
Let's try to run speedtest-cli to see what happens without a connection. This tool was installed for you during the lab setup.
Run the command in your terminal:
speedtest-cli
The tool will try to connect to the speed test servers and fail. You will see an error message indicating a configuration or network issue. This is expected because our simulated wlan0 device is not connected to the internet.
In a real-world scenario where you are successfully connected to a network, the tool would automatically find the best server, test your download and upload speeds, and print the results. The output would look something like this (the values would vary):
Retrieving speedtest.net configuration...
Testing from ...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by ... [x.xx ms]: ...
Testing download speed...
Download: 95.32 Mbit/s
Testing upload speed...
Upload: 88.14 Mbit/s
This step demonstrates the importance of verifying your connection status before using tools that require internet access.
Summary
Congratulations on completing this lab! You have learned the essential commands for managing wireless connections on a Linux system using nmcli.
In this lab, you practiced the entire workflow of wireless network management within a simulated environment:
- Scanning for networks with
nmcli device wifi list. - Creating and attempting to activate a connection profile with
nmcli connection addandnmcli connection up. - Verifying the connection status with
nmcli connection show. - Deleting a connection profile with
nmcli connection delete. - Understanding the requirements for connection-dependent tools like
speedtest-cli.
These skills are fundamental for managing Linux servers and desktops, especially in environments where you rely on the command line. You are now better equipped to handle network configurations in a variety of situations.



