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>
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:
- Create a new connection
- Add the DNS info to it
- Activate the connection
# nmcli con add con-name "NAME" ifname enp0s3 type ethernet ip4 192.168.20.10/24 gw4 192.168.20.1 # nmcli con mod "NAME" ipv4.dns "192.168.20.1,18.104.22.168" # 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.