manage network connections in linux with nmcli and terminal

In the Linux world, managing network connections can sometimes seem complex, especially outside of familiar graphical environments. While graphical user interfaces (GUIs) greatly facilitate configuration, mastering command-line tools remains crucial for effectively managing network connections, especially on servers without a graphical interface or during advanced troubleshooting. The nmcli utility, a command-line client of the popular NetworkManager service, stands out as a powerful and flexible tool for controlling network interfaces. This ability to manipulate Ethernet, Wi-Fi, or VPN connections via the terminal is an essential asset for system administrators working with renowned distributions such as Red Hat, Debian, Fedora, OpenSUSE, or Arch Linux. Knowing how to use nmcli not only provides clear visibility into the status of network interfaces, but also allows for rapid intervention in the event of a connection outage or changes to be made, whether it’s a simple reconnection or the configuration of a static IP address, essential for certain server roles. Understanding Network Interfaces and the nmcli Tool in Linux

Each network connection in Linux is managed by an interface, whether physical or virtual. These interfaces have specific names that have evolved considerably over the years. At the time, names like eth0 for Ethernet or wlan0 for Wi-Fi were commonplace. Since then, distributions such as Ubuntu (Canonical) and Fedora (Red Hat) have adopted more descriptive names based on hardware location, such as enp3s0 for an Ethernet interface and wlp2s0 for Wi-Fi.

The nmcli utility is a command-line tool that controls the NetworkManager daemon, which is responsible for automatically and dynamically managing network connections in many distributions such as Linux Mint, AlmaLinux, and Linux Mint. or even CentOS . By default, nmcli is installed with NetworkManager, making it easy to use on most modern GNU/Linux systems. With nmcli, you can perform a wide range of operations: List network interfaces and their status. Detailed configuration of a network connection. Enable or disable an interface. Modify settings such as IP addresses, gateways, or DNS. Create new connection profiles, whether Ethernet, Wi-Fi, or VPN. This rich functionality makes it an essential tool, especially for users of distributions without a graphical desktop, such as Debian or

Slackware , where the command line reigns supreme.To view the complete list of interfaces, a simple command is all it takes: nmcli -p dev status The -pparameter adds more readable and structured output. It displays the interface names, their type, their current status (connected, disconnected), and the active connection profile. This initial diagnostic is essential when a network problem occurs.

Discover how to manage your network connections in Linux with nmcli. Explore the essential commands to configure, modify, and troubleshoot your network interfaces quickly and efficiently.

  • Clearly identify the status of interfaces and their active connections
  • It is common in system administration to need to target a specific interface before intervening. To display only active connections, thus avoiding getting bogged down in a long list, the following command is effective:
  • nmcli -p con show –active
  • Environments such as
  • OpenSUSE

or Arch Linux also use this approach to ensure fine-grained management of network profiles. The details displayed include not only the connection name but also the type and UUID, a unique identifier for each connection profile. To dig deeper, you can examine a specific connection:nmcli -p con show

where

<!– wp:code {"content":"
nmcli -p dev status
“} –>

corresponds to the identifier displayed previously. This allows you to verify: The configured IP addresses. The gateway used.

The active DNS servers.

The type of IP assignment method (DHCP or static).

This in-depth exploration is the starting point before making any changes, ensuring a complete understanding of the current network configuration.

<!– wp:code {"content":"
nmcli -p con show --active
“} –>
https://www.youtube.com/watch?v=X6_9aS5-cT8

Mastering nmcli commands to enable, disable, and troubleshoot connections When network connectivity is problematic, it is crucial to act quickly by disabling and re-enabling the affected interface, a process often referred to as “cycling” or “resetting” the connection. This technique is essential on all systems running NetworkManager, from Red Hat Enterprise Linux to Linux Mint. To disable a network interface, use: nmcli -p con down This command effectively disconnects the interface without deleting it, making the operation completely reversible. Once the interface is taken down, a command to check its status is recommended:

nmcli -p dev status

<!– wp:code {"content":"
nmcli -p con show 
“} –>
You will then see that the target connection is listed as "disconnected" or simply missing from the active connections.

To reactivate it, the reverse command comes into play: nmcli -p con up Restarting the connection in this way is often enough to resolve temporary connection issues. However, it is recommended to then check the connection to a network service, for example with a simple ping:

  • ping -c 4 8.8.8.8
  • Google DNS is often used as a reference, guaranteeing a fast response if network conditions are good. These simple steps are frequently used by system administrators to troubleshoot network interfaces.
  • Identify the affected interface.
  • Stop the current connection.

Restart the connection.

Test network connectivity.

This entire procedure can also be automated via a shell script, a significant advantage for server or embedded environments such as those running AlmaLinux or CentOS.

Discover how to use nmcli to manage network connections on Linux. Learn how to configure, monitor, and troubleshoot your connections easily with this powerful command-line tool. Detect and fix common connection problems with nmcli Common errors are related to IP conflicts, incorrect DNS settings, or sleeping interfaces. Nmcli provides tools to inspect the configuration and also to reset damaged profiles. If you have a WPA authentication problem on a Wi-Fi connection, it may be useful to delete and then recreate the profile: Disconnect the profile:nmcli con down

Delete the profile:

<!– wp:code {"content":"
nmcli -p con down 
“} –>
nmcli con delete 

Create a new connection:

<!– wp:code {"content":"
nmcli -p dev status
“} –>
nmcli dev wifi connect  password 

This method avoids tedious searches through configuration files and also applies to VPN or Ethernet connections with corrupted or outdated profiles.

<!– wp:code {"content":"
nmcli -p con up 
“} –>
Configuring a Static IP Address with nmcli for a Linux Server

In a server context, whether running Debian, Ubuntu LTS (Canonical), AlmaLinux, or CentOS, having a static IP address is often necessary. This configuration allows other machines on the network to efficiently locate the server, a fundamental prerequisite for hosting web services, databases, or network applications.

<!– wp:code {"content":"
ping -c 4 8.8.8.8
“} –>
Here's the step-by-step process using nmcli:

Identify the connection name:

  • using the command
  • nmcli -p con show
  • .
  • Modify the connection profile:

Apply a static IPv4 address, specify the gateway and DNS server, and set the method to “manual”: nmcli connection modify “CONNECTION_NAME” ipv4.addresses X.X.X.X/24 ipv4.gateway Y.Y.Y.Yipv4.dns Z.Z.Z.Z

ipv4.method manual

It is important to adapt these settings according to the local network addressing plan. For example, an address of

192.168.1.100

, the gateway

  • 192.168.1.1 and a DNS identical to the gateway work in many home or business networks.
  • Once the modification is applied, you must disable and re-enable the connection to take the changes into account: nmcli conex down "CONNECTION_NAME"
  • nmcli conex up “CONNECTION_NAME” Then verify the new configuration:

nmcli -p con show “CONNECTION_NAME” | grep ipv4.addresses

Finally, a simple network test validates the connection:

ping 8.8.8.8 -c 4

If the commands succeed and the pings return promptly, the static IP configuration is functional. This approach is widely applicable on various GNU/Linux platforms discussed here, including Red Hat derivatives and community distros like Slackware. Discover how to manage your network connections in Linux with nmcli. Learn how to configure, modify, and troubleshoot your network connections with this powerful and flexible command-line tool.Automate Network Management via Shell Scripts with nmcli The repetition of nmcli commands in multiple-machine environments often motivates automation via scripts. Sysadmins and advanced users appreciate this ability to reliably deploy standardized network configurations on Fedora, OpenSUSE, or Arch Linux servers. A simple bash script can: Identify available interfaces. Temporarily disconnect the connection. Apply specific network settings (static IP, DNS). Restart the connection and check its status.Here’s a basic script example:

#!/bin/bash

  1. CONN=”Ethernet connection 1″ nmcli con down “$CONN” nmcli con modify "$CONN" ipv4.addresses 192.168.1.100/24 ​​ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 ipv4.method manualnmcli con up “$CONN”
  2. nmcli -p dev status This script can be extended to include error checking, logging, or email alerts. Integrating nmcli into automated routines is a common practice in enterprise-oriented distributions such as Red Hat and AlmaLinux, as well as in the desktop distribution community such as Linux Mint. Explore alternatives and complementarities to nmcli for network management
<!– wp:code {"content":"
nmcli connection modify "NOM_CONNEXION" nipv4.addresses X.X.X.X/24 nipv4.gateway Y.Y.Y.Y nipv4.dns Z.Z.Z.Z nipv4.method manual
“} –>
While nmcli represents a powerful standard, there are other tools that can complement or replace its functions depending on the context and distribution: 
nmtui 
: A text-based interface (TUI) based on ncurses, more user-friendly for users who prefer a semi-graphical display in the terminal. 
ifconfig 
and

ip : More traditional, low-level tools, often used for fine-grained control of interfaces but do not manage NetworkManager profiles and connections.wpa_supplicant : Dedicated to the fine-grained management of secure Wi-Fi connections, often behind nmcli for wireless connections. systemd-networkd

: An alternative to NetworkManager on certain minimalist systems or servers, with network management via configuration files.

  • Each tool meets specific needs. For example, Debian often favors systemd-networkd or ifupdown in its server installations, while Fedora and Linux Mint desktops recommend nmcli for ease of use and automation. Understanding their complementarities and choosing the right tool for the right context is a valuable skill. For example, a Linux newcomer will quickly discover that nmcli offers the right balance of power, simplicity, and portability across a wide range of distributions, from Arch Linux to CentOS, OpenSUSE, and Slackware.

<!– wp:code {"content":"
nmcli -p con show "NOM_CONNEXION" | grep ipv4.addresses
“} –>

<!– wp:code {"content":"
ping 8.8.8.8 -c 4
“} –>

<!– wp:code {"content":"
#!/bin/bashnCONN="Ethernet connection 1"nnnmcli con down "$CONN"nnmcli con modify "$CONN" ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 ipv4.method manualnnmcli con up "$CONN"nnnmcli -p dev status
“} –>