nmcli command in Linux with Examples
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 NetworkMaager via nmcli.
- Servers, headless machine and terminals: Can be used to control NetworkManager with no GUI and control system-wide connections.
Syntax:
nmcli [OPTIONS] OBJECT { COMMAND | help }
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.
Example 1: To check the device status using nmcli command.
We can see that the output is shown in various columns that include the device name, its type and connection status. The output might vary with different machines.
Example 2: To check active connection on the device.
In the above output, we can see that there is one connection which is active. The number of connection, it’s UUID(universally unique identifier) and type might vary from machine to machine.
Example 3: To list all the available device.
Options:
- -t, –terse: 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:
- -p, –pretty: This option prints the output in an organized format which is convenient and easily readable to humans.
Example:
Input:
Output:
- -m, –mode {tabular|multiline}: 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.
- -f, –fields {fields1, fields2…. |all|common}: 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.
Example 1: To print device list with field DHCP4.
Example 2: To print device list with field GENERAL.
- -e, –escape {yes | no}: This option is used to escape columns separators(“:”, “\”) in values.
- -v, –version: Show the version information version.
Example:
- -h[elp]: Print help related information.
Example:
Please Login to comment...