nmcli usage examples

Using nmcli may seem scary at the beginning. Spend a little time with it and you’ll like it. The best feature is that it supports tab-completion. Since nmcli is the default network manager in RHEL and it’s derivatives now, learning it will be beneficial. Some nmcli examples are given below. It’s got a good documentation just in case you need more help or something in particular. Just in case you weren’t aware, you can use nmtui which is a nice little ncurses-based tool which runs in the terminal and does the same job.

Starting and stopping network interfaces

# nmcli device connect <connection-name>
# nmcli device disconnect <connection-name>
VirtualBox screenshot of terminal running nmcli examples

VirtualBox screenshot of terminal running nmcli connect and disconnect examples

Add an Ethernet network connection which gets its IP address information from a DHCP server

Configuring a network connection to receive IP addresses information from a DHCP is pretty easy. Just create a new connection with a name, that’s it!

# nmcli connection add con-name "NAME"

Add an Ethernet network connection with a Static IP address

Split this one into 3 parts:

  1. Create a new connection
  2. Add the DNS info to it
  3. Activate the connection
# nmcli con add con-name "NAME" ifname enp0s3 type ethernet ip4 gw4
# nmcli con mod "NAME" ipv4.dns ","
# nmcli con up "NAME" iface enp0s3

You may skip the gw4 argument if your connection doesn’t support it. It’s to specify a network gateway, which is usually your router’s address.

Create new network interface with nmcli. Check the command completion using the tab key.


Share your views