Managing Wi-Fi Connections with nmcli in Linux
Introduction
nmcli is a command-line tool for managing NetworkManager, which is the default network management service in most modern Linux distributions. It allows you to create, manage, and troubleshoot network connections, including Wi-Fi. This article will guide you through using nmcli to manage Wi-Fi connections, view Wi-Fi devices using lspci and lsusb, list available SSIDs, create a Wi-Fi connection, and view the capabilities of your Wi-Fi device using iw list.Viewing Wi-Fi Devices with lspci and lsusb
To identify the Wi-Fi devices connected to your system, you can use the lspci and lsusb commands.- lspci: This command lists all PCI devices, including internal Wi-Fi adapters.
Code:
lspci | grep -i wireless
- lsusb: This command lists all USB devices, including external Wi-Fi adapters.
Code:
lsusb | grep -i wireless
Listing Available SSIDs
To view the available Wi-Fi networks (SSIDs) within range, use the following nmcli command:
Code:
nmcli device wifi list
Creating a Wi-Fi Connection
To connect to a Wi-Fi network using nmcli, you need the SSID and the password (if applicable). Here’s how to do it:- Enable your Wi-Fi device (if it’s not already enabled):
Code:
nmcli radio wifi on
- Connect to the Wi-Fi network:
Code:
nmcli device wifi connect "SSID" password "PASSWORD"
- Create a Wi-Fi profile (optional):
Code:
nmcli connection add type wifi con-name "PROFILE_NAME" ifname "DEVICE_NAME" ssid "SSID"
Viewing Wi-Fi Device Capabilities
To view the capabilities of your Wi-Fi device, use the iw list command:
Code:
iw list