The Wayback Machine - https://web.archive.org/web/20240827175019/https://www.geeksforgeeks.org/nmcli-command-in-linux-with-examples/
Open In App

Manage Network Connections From the Linux Command Line with nmcli

Last Updated : 05 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Network connectivity is a critical aspect of modern computing, and Linux provides a robust command-line tool for managing network connections: nmcli. Network Manager Command-Line Interface (nmcli) is a powerful and versatile utility that allows users to control and configure network settings directly from the terminal. In this article, we will delve into the syntax, usage, and various capabilities of nmcli for efficient network management on Linux.

What is nmcli

nmcli is a command-line tool which is used for controlling NetworkManager. nmcli command can also be used to display network device status, create, edit, activate/deactivate, and delete network connections. 

Typical Uses:  

  • Scripts: Instead of manually managing the network connections it utilize NetworkManager via nmcli.
  • Servers, headless machine and terminals: Can be used to control NetworkManager with no GUI and control system-wide connections.

Syntax of nmcli

The nmcli command follows a specific syntax, enabling users to interact with Network Manager through the command line. The general syntax for nmcli is as follows: 

nmcli [OPTIONS] OBJECT { COMMAND | help }

Here,

  • OPTIONS: Additional options that modify the behavior of nmcli.
  • OBJECT: Specifies the target of the operation (e.g., connection, device, etc.).
  • COMMAND: Defines the action to be performed on the specified object.

Where the OBJECT can be any one of the following:  

  • nm: NetworkManager’s status.
  • connection/cn: NetworkManager’s connection.
  • d[evice]: devices managed by NetworkManager.

Practical Implementation of nmcli Command in linux

1. How to View Connections using nmcli

nmcli connection show

This command lists all the available network connections on your system. It provides details such as the connection name, UUID, device, type, and status.

Viewing connections

Viewing connections

2. How to Check the Device Status using nmcli

To check the device status using nmcli command. 

nmcli dev status

check device status

check device status

This command displays the current status of all network devices on your system. It shows whether each device is connected or disconnected, along with additional information like the device type and the connection type it is associated with.The output might vary with different machines. 

3. How to Display Device Details using nmcli

Syntax:

nmcli device show <device_name>

Example:

nmcli device show eno1

Replace “eno1” with the actual name of your network device. This command provides detailed information about the specified network device, including its IP address, MAC address, driver details, and more.

Display Device Details

Display Device Details

4. How to Add a New Ethernet Connection using nmcli

To add a new connection, you can use the following command:

Syntax:

nmcli connection add type <connection_type> ifname <interface_name> con-name <connection_name>

Here,

  • connection_type: Specifies the type of connection (e.g., ethernet, wifi).
  • interface_name: The name of the network interface.
  • connection_name: A user-defined name for the new connection.

Example:

nmcli connection add type ethernet ifname eth1 con-name my_eth_connection

This command creates a new Ethernet connection named “my_eth_connection” associated with the network interface “eth1”. Adjust the interface name and connection name as needed.

202Adding new ethernet connection4-01-11_17-11

Adding new ethernet connection

To verify we can use this command “nmcli connection show”

nmcli connection show

nmcli connection show

5. How to Adjust Connection Settings using nmcli

To modify connection settings, you can use the following command:

Syntax:

nmcli connection modify <connection_name> <setting_name> <setting_value>

Here,

  • connection_name: The name of the connection to be modified.
  • setting_name: The specific setting to be adjusted.
  • setting_value: The new value for the setting.

Example:

nmcli connection modify my_eth_connection ipv4.addresses "192.168.1.2/24" ipv4.gateway "192.168.1.1"

This example modifies the IPv4 settings of the “my_eth_connection” connection, setting a static IP address of “192.168.1.2” with a subnet mask of “/24” and a gateway of “192.168.1.1”.

Options Available in nmcli Command in Linux

Options

Description

-t, –terse

Terse output suitable for script processing.

-p, –pretty

Prints organized and human-readable output.

-m, –mode

Switches between tabular and multiline output. Defaults to tabular if not specified.

-f, –fields

Specifies fields to print as output. Use ‘all’ for all fields or ‘common’ for common fields.

-e, –escape

Escapes column separators in values.

-v, –version

Displays version information.

-h, –help

Prints help-related information.

1. -t, –terse option

This option is used to terse the output i.e. when we want the output to be very brief and in very few words. It is suitable for script processing. 

Example: 

nmcli -t device list

 Input: 

Output: 

2. -p, –pretty option

This option prints the output in an organized format which is convenient and easily readable to humans. 

Example: 

Input: 

Output: 

3. -m, –mode {tabular|multiline} option

Used to switch the output mode between tabular and multiline. If the option is not used, nmcli will print the output in tabular form by default.

4. -f, –fields {fields1, fields2…. |all|common} option

This option is used to specify the fields to print as output. Where the field is the column that we want to print as output. all is used when we want all the value field to be displayed. 

To print device list with field GENERAL. 
 

5. -v, –version option

Show the version information version. 

Example: 

6. -help option

Print help related information. 

Example: 

Conclusion

In this article we discussed nmcli which is a powerful command-line tool for managing network connections in Linux. With a structured syntax, it enables users to control and configure network settings efficiently. This article covered practical examples, including viewing connections, checking device status, displaying device details, adding new Ethernet connections, and adjusting settings. Key options such as terse, pretty, mode, fields, escape, version, and help were highlighted, showcasing the versatility of nmcli for diverse network administration tasks. Whether used in scripts or on headless machines, nmcli proves essential for streamlined and efficient network connectivity on Linux systems.



Previous Article
Next Article

Similar Reads

Interface (NICs) Bonding in Linux using nmcli
A network interface card (NIC) is a hardware component that connects computers over a network. This is a circuit board attached to your computer that provides a dedicated network connection for your computer. Also called a network interface controller, network adapter, or LAN adapter. A NIC provides a computer with a dedicated, permanent connection
5 min read
How to Manage KVM Virtual Environment using Command Line Tools in Linux
KVM, short for Kernel-based Virtual Machine, is a complete virtualization solution for Linux running on x86 hardware (Intel VT or AMD-V). Since version 2.6.20, the mainline Linux kernel has featured KVM, a complete virtualization solution for Linux running on Intel 64 and AMD 64 hardware that is fast and stable for the majority of workloads. It con
8 min read
Command-Line Tools and Utilities For Network Management in Linux
If you are thinking of becoming a system administrator, or you are already a system admin, then this article is for you. As a system admin, your daily routine will include configuring, maintaining, troubleshooting, monitoring, securing networks, and managing servers within data centers. Network configuration and troubleshooting are some important t
8 min read
How to Compare Files Line by Line in Linux | diff Command
In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process is the diff command. In this article, we will explo
9 min read
How to Manage System Services in Linux | systemctl Command
Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool for managing services. In this article, we will ex
8 min read
How To Use IPRoute2 Tools to Manage Network Configuration on a Linux
In computer networking, the iproute2 command line utility tool is a versatile and powerful tool for users. it provides beginner-friendly functionality to manage and configure the network. In this article, we are going to discuss each and every part of the iproute2 tool and how to implement it in our system. By the end of this article, you'll have s
4 min read
Disconnecting Inactive SSH Connections in Linux
SSH or Secure Shell is a cryptographic network protocol that establishes a secure connection between systems remotely. Any user can use this protocol to manage the system remotely but mainly system administrators use it because it transmits data over encrypted channels, which increases its security at a high level. SSH can be used to manage the sys
2 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
Iperf Command to Test Speed, Performance and Bandwidth of Network in Linux
There is a great degree of flex in how the packets are delivered and overall bit rate and packet payload size can be controlled. iperf is a tool that is used to perform network performance measurement and tuning. iperf is an open-source software which is written in C language. Jperf is a GUI version for doing the same job. The core concept work beh
2 min read
How to Check Network Connectivity in Linux | ping Command
Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we will explore how to use the ping command in Linux t
7 min read
How to Download YouTube Videos in Linux Command Line?
The videos can be downloaded from the online source through the Linux terminal using the youtube-dl tool. youtube-dl is a Python-based small command-line tool that makes it possible to download the videos from Youtube, Facebook, Dailymotion, and few more similar sites. It is written in PyGTK and requires Python interpreter to run this program, it’s
2 min read
Connecting to the Internet Using Command Line in Linux
Many of the times you may use a Linux system that does not have a GUI after install and it needs an internet connection to set up a desktop environment, also you may use Linux servers without a GUI and you need to connect over a wireless network using the command line. Below you will see Steps to connect to a wireless network using the command line
3 min read
Kali Linux - Command Line Essentials
Command-line plays a vital role while working with Kali Linux as most of its tools don't have a Graphical User Interface and if you are performing ethical hacking or penetration testing then most of the time you will have to work with command Line Interface itself. While executing a command in Kali Linux we enter a command on the terminal emulator
3 min read
Deepl - Command Line Language Translator Tool for Linux
Deepl is the best language translator command-line tool that detects the language of input text and translates it into the desired language using advanced machine learning and neural networking algorithms. It is open source and powered by a German tech Company under the MIT license. It supports the following languages English (EN)Italian (IT)Spanis
3 min read
How to Convert PDF to Image in Linux Command Line?
Pdftoppm is a tool that converts PDF document files into .PNG format and many other formats. We can use this tool on Linux to convert the PDF into images. It also provides the features like the cropping image, set resolution, and scale, and many more. Now let's see how to install the pdftoppm Installation of pdftoppm: To install the pdftoppm, we ne
3 min read
How to Install and Use Sysdig from Linux Command Line?
Sysdig is a tool that provides administrators and developers with unparalleled insight into their systems' behavior. The team behind it hopes to enhance system-level monitoring and troubleshooting by providing a centralized, coherent, and granular view of the storage, transmission, network, and memory subsystems, as well as the ability to generate
2 min read
Aria2 - Multi-Protocol Command-Line Download Tool for Linux
Aria2 is an open-source lightweight multi-protocol, multi-server &amp; multi-source command-line utility that is used for downloading files in Windows, Linux, and Mac. Aria2 is used to download a file at a good speed by utilizing your maximum download bandwidth from multiple sources/protocols such as HTTP(S), FTP, SFTP, Bittorrent, and Metalink. Yo
4 min read
How to Create a Text File Using the Command Line in Linux
There are a couple of quick ways to create a text file from the Linux Command Line or Terminal. Some of them have been explained in the following article. 1) touch commandThis is the most standard command to quickly create an empty text file. The command is quite simple to type and makes it quite easier to create several text files at once. The com
6 min read
Optimize and Compress JPEG or PNG Images in Linux Command line
Today there are many GUI tools that compress and optimize the images, which are very useful. But if you are terminal addicted and want to compress and optimize the images in the terminal before uploading to the cloud, then you can do it. There are two tools by using which we can compress and optimize images. These are - jpegoptimOptiPNGjpegoptim jp
4 min read
Top Linux Command Line Tips and Tricks
Linux is a great OS that offers multiple options for simplifying tasks. It has everything you need for working more efficiently, whether a command-line or a GUI. However, many people don't know the Linux command line's short tricks and end up being stuck in complex tasks. An interface (text-based) through which you communicate with your system's OS
5 min read
How to Pass Command Line Arguments to GDB in a Linux Environment?
The GNU Debugger, commonly known as GDB, is a powerful tool used for debugging and analyzing programs in Linux and other Unix-like operating systems. While GDB is commonly used to debug programs, it can also be used to launch programs with specific command line arguments. This article will walk you through the process of passing command line argume
6 min read
Open Google Chrome From The Linux Command Line
Google Chrome is known as the most used and widely popular web browser because of its fast and better performance. In this article we will learn how we can open the Google Chrome application by using the terminal in Linux along with this we will also look at some you should command line switches to help you to start using the Google Chrome browser
6 min read
MySQL in Kali Linux Command Line
Below is a comprehensive MySQL Command Line tutorial for Kali Linux, starting from beginner to advanced levels. MySQL is a popular open-source relational database management system, and Kali Linux is a Debian-based Linux distribution often used for penetration testing and ethical hacking. Make sure you have MySQL installed on your Kali Linux system
10 min read
Uninstall Node.JS Using Linux Command Line
To uninstall Node.js from your Linux system using the command line, you can follow these steps. The specific commands may vary depending on your Linux distribution, so I'll provide instructions for a few common package managers: APT (Debian/Ubuntu), YUM (Red Hat/CentOS), and DNF (Fedora). Check if Node is Already Installed or NotEnter the following
3 min read
How to Convert DOS line endings to Linux line endings using Vim
DOS and Unix/Linux file formats differ slightly such that the ASCII characters used at the line endings are different. Unix file format uses an LF character to end a line, LF stands for LineFeed, which means moving the cursor down. Unix-based systems and Mac OS X &amp; later use this format. While the DOS file format uses a CR character before the
2 min read
Linux - Installing PIP to Manage Python Packages
Python is the most popular language for a decade, and we all know that python had a huge support of libraries that are used in different sectors of Software Engineering. Meanwhile, PIP also getting its fame along with python in Linux and developers community.PIP is a package manager for python in handling the software packages that are developed us
2 min read
Most Useful Commands to Manage Apache Web Server in Linux
Prerequisite: How do Web Servers work? Apache is one of the most widely used free, open-source Web Server applications in the world, mostly used in Unix-like operating systems but can also be used in windows. As a developer or system administrator, it will be very helpful for you to know about the Apache webserver. It has many notable features amon
3 min read
How to Manage Linux Containers using LXC
LXC is a technology for creating light weighted containers on your system. This technology is able to run on more than one Linux host. It is just like its counterparts i.e the other hypervisors like KVM and Xen. Unlike complete virtualization, containerization does not provide the user with complete isolation but the amount of load that is exerted
4 min read
How to Manage Debian Packages in Linux?
Debian, one of the oldest and most respected Linux distributions, is renowned for its stability, security, and robust package management system. Managing Debian packages effectively is crucial for maintaining a healthy and well-functioning Linux system. In this comprehensive guide, we will explore every aspect of Debian package management, from ins
9 min read