In Linux systems, configuring network connections is essential for the system to function properly. nmcli (Network Manager Command Line Interface) is a powerful command-line tool that allows users to easily manage network connections. This article will guide you on how to use nmcli to configure network connections, including creating new connections, editing existing ones, and connecting to Wi-Fi networks.
- Installing and Verifying nmcli
Most modern Linux distributions come with NetworkManager and nmcli pre-installed. If itβs not installed, you can use a package manager to install it. For example, on a Debian-based system, you can run the following command:
|
|
After installation, you can verify that nmcli has been successfully installed by running nmcli --version
.
- Displaying Network Status
First, you can check the status of the network using nmcli
. Run the following command:
|
|
This will display the status of all network devices, including Ethernet and Wi-Fi interfaces.
- Listing Network Connections
To view the currently configured network connections, you can use the following command:
|
|
This will list all configured network connections, including Ethernet and Wi-Fi connections.
- Adding an Ethernet Connection
Suppose you want to add an Ethernet connection; you can use the following command:
|
|
Here is a breakdown of the parameters:
type ethernet
: Specifies the connection type as Ethernet.ifname eth0
: Specifies the interface name as eth0.con-name MyEthernet
: Assigns a name to the connection, in this case, MyEthernet.ipv4.addresses 192.168.1.100/24
: Sets the IPv4 address and subnet mask.ipv4.gateway 192.168.1.1
: Sets the IPv4 gateway.ipv4.dns 8.8.8.8
: Sets the IPv4 DNS server.ipv4.method manual
: Specifies the IPv4 configuration method as manual.
- Adding a Wi-Fi Connection
1. Open Terminal
First, you need to open the terminal. You can use the shortcut Ctrl+Alt+T
, or find and open the terminal from the application menu.
2. Scan for Available Wi-Fi Networks
Before connecting to a Wi-Fi network, we need to know what networks are available. By using the nmcli device wifi
command, we can rescan and list all available Wi-Fi networks.
|
|
After running these commands, you will see a list of all available Wi-Fi networks, including their SSIDs, encryption methods, and signal strengths.
3. Choose and Connect to a Wi-Fi Network
From the scan results, select the Wi-Fi network you want to connect to, and use the nmcli device wifi connect
command. You will need to provide the Wi-Fi’s SSID and password.
|
|
Replace YourSSID
with the name of the Wi-Fi network you wish to connect to, and YourPassword
with the password for that network. If the connection is successful, you will see a message indicating that the device has been successfully activated.
4. Set Up Automatic Connection on Boot
If you want the system to automatically connect to this Wi-Fi network on startup, you can use the nmcli connection modify
command to set this up. However, you first need to find out the UUID (Universally Unique Identifier) of the connection. You can view all connections and their UUIDs using the command:
|
|
Find the UUID of the Wi-Fi connection you just created, then set it to connect automatically on boot with the following command:
|
|
Replace YourUUID
with the UUID of your Wi-Fi connection.
- Modifying Connection Settings
To modify the settings of an existing connection, you can use the modify
command. For example, to change the DNS server for the Ethernet connection you created earlier, run:
|
|
This will change the DNS server for the MyEthernet connection to 8.8.4.4.
- Enabling/Disabling Connections
To enable or disable a connection, you can use the up
and down
commands. For example, to enable the MyEthernet connection, run:
|
|
To disable it, you can run:
|
|
- Deleting Connections
If you no longer need a connection, you can delete it using the delete
command. For example:
|
|
This will remove the connection named MyEthernet.
- Exporting and Importing Connections
NetworkManager also supports exporting and importing connection settings, which is useful for backing up or migrating network settings.
- To export connection settings:
|
|
- To import connection settings:
|
|
With this guide, you should now have a foundational understanding of how to use nmcli
to configure and manage network connections. Whether you’re adding, modifying, or deleting network connections, nmcli
provides a powerful command-line interface to accomplish these tasks.