Last Updated : 05 Aug, 2024
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 nmclinmcli 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:
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,
Where the OBJECT can be any one of the following:
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 2. How to Check the Device Status using nmcliTo check the device status using nmcli command.
nmcli dev statuscheck 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.
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 4. How to Add a New Ethernet Connection using nmcliTo 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,
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.
Adding new ethernet connectionTo verify we can use this command "nmcli connection show"
nmcli connection show 5. How to Adjust Connection Settings using nmcliTo modify connection settings, you can use the following command:
Syntax:
nmcli connection modify <connection_name> <setting_name> <setting_value>
Here,
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 LinuxOptions
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 optionThis 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 optionThis option prints the output in an organized format which is convenient and easily readable to humans.
Example:
Input:
Output:
3. -m, --mode {tabular|multiline} optionUsed 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} optionThis 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.
Show the version information version.
Example:
6. -help optionPrint help related information.
Example:
ConclusionIn 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4