ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

nmcli: static IP, DNS, gateway

Lesson 7.18 minIntermediateDecember 1, 2026
Open

This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.

Key points

  • A device (ens18) is a physical interface, a connection is the settings profile applied to it.
  • nmcli con mod ens18 ipv4.method manual ipv4.addresses 10.20.0.15/24 ipv4.gateway 10.20.0.1 ipv4.dns 10.20.0.1 — a static IP.
  • The change is written to the profile; nmcli con up ens18 is needed to apply it.
  • +ipv4.addresses adds a second address; connection.autoconnect yes makes it come up at boot.
  • On RHEL 9 profiles live in /etc/NetworkManager/system-connections/*.nmconnection; nmtui is a text menu.

Device and connection

srv-db01
[ali@srv-db01 ~]$ nmcli dev status
DEVICE  TYPE      STATE                   CONNECTION
ens18   ethernet  connected               ens18
lo      loopback  connected (externally)  lo
[ali@srv-db01 ~]$ nmcli con show
NAME   UUID                                  TYPE      DEVICE
ens18  3c8a1f2e-7b4d-4e6a-9c1b-2d3e4f5a6b7c  ethernet  ens18
lo     9f8e7d6c-5b4a-4392-8170-6f5e4d3c2b1a  loopback  lo
TermWhat it isExample
DeviceA physical or virtual interfaceens18
ConnectionA settings profile: IP, DNS, routesens18 (the name may or may not match the device)

One device can have several profiles (for example "office" and "lab"), but only one is active at a time. All nmcli con mod commands apply to the profile.

Current settings

srv-db01
[ali@srv-db01 ~]$ nmcli -f ipv4.method,ipv4.addresses,ipv4.gateway,ipv4.dns,connection.autoconnect con show ens18
ipv4.method:                            auto
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.dns:                               --
connection.autoconnect:                 yes
[ali@srv-db01 ~]$ ip -br a show ens18
ens18            UP             10.20.0.20/24 fe80::be24:11ff:fe5e:19a3/64

method: auto — DHCP. The server got its address from DHCP.

A static IP

srv-db01
[ali@srv-db01 ~]$ sudo nmcli con mod ens18 \
    ipv4.method manual \
    ipv4.addresses 10.20.0.20/24 \
    ipv4.gateway 10.20.0.1 \
    ipv4.dns "10.20.0.1 1.1.1.1" \
    ipv4.dns-search itnuvo.local \
    connection.autoconnect yes
[ali@srv-db01 ~]$ sudo nmcli con up ens18
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[ali@srv-db01 ~]$ ip route show default
default via 10.20.0.1 dev ens18 proto static metric 100
[ali@srv-db01 ~]$ grep nameserver /etc/resolv.conf
nameserver 10.20.0.1
nameserver 1.1.1.1
ParameterMeaning
ipv4.method manualStatic IP (auto — DHCP)
ipv4.addressesIP/mask; several separated by commas
ipv4.gatewayDefault gateway
ipv4.dnsDNS servers, separated by spaces
ipv4.dns-searchSearch domain
connection.autoconnect yesCome up automatically at boot

Careful: if you write ipv4.method manual without giving ipv4.addresses, con up fails. Also on RHEL (unlike Ubuntu) NetworkManager writes /etc/resolv.conf itself — do not edit it by hand, use ipv4.dns.

When changing remotely over SSH: after changing the IP, con up drops the connection. Be ready to connect to the new address, or run nmcli con mod ... && nmcli con up ... on one line inside tmux.

A second address and removing it

srv-db01
[ali@srv-db01 ~]$ sudo nmcli con mod ens18 +ipv4.addresses 10.20.0.21/24
[ali@srv-db01 ~]$ sudo nmcli con up ens18
[ali@srv-db01 ~]$ ip -br a show ens18
ens18            UP             10.20.0.20/24 10.20.0.21/24 fe80::be24:11ff:fe5e:19a3/64
[ali@srv-db01 ~]$ sudo nmcli con mod ens18 -ipv4.addresses 10.20.0.21/24

+ adds, - removes, and without a sign it replaces. The same rule applies to ipv4.dns and ipv4.routes. A static route: nmcli con mod ens18 +ipv4.routes "10.30.5.0/24 10.20.0.254".

Creating a new connection

A second network card (ens19) was added — for the management network:

srv-db01
[ali@srv-db01 ~]$ sudo nmcli con add type ethernet con-name mgmt ifname ens19 \
    ipv4.method manual ipv4.addresses 192.168.100.20/24
Connection 'mgmt' (a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7) successfully added.
[ali@srv-db01 ~]$ nmcli con show
NAME   UUID                                  TYPE      DEVICE
ens18  3c8a1f2e-7b4d-4e6a-9c1b-2d3e4f5a6b7c  ethernet  ens18
mgmt   a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7  ethernet  ens19
lo     9f8e7d6c-5b4a-4392-8170-6f5e4d3c2b1a  loopback  lo

No gateway is set on the management network — the default route must be on one interface only.

CommandWhat it does
nmcli con add ...A new profile
nmcli con mod name ...Change it
nmcli con up name / down nameActivate / deactivate
nmcli con del nameDelete
nmcli con reloadRe-read files if you edited them by hand
nmcli dev disconnect ens19Disconnect a device
nmtuiA text menu interface — handy in the exam too

The settings file

srv-db01
[ali@srv-db01 ~]$ sudo cat /etc/NetworkManager/system-connections/ens18.nmconnection
[connection]
id=ens18
uuid=3c8a1f2e-7b4d-4e6a-9c1b-2d3e4f5a6b7c
type=ethernet
interface-name=ens18

[ipv4]
address1=10.20.0.20/24,10.20.0.1
dns=10.20.0.1;1.1.1.1;
dns-search=itnuvo.local;
method=manual

On RHEL 9 profiles use this keyfile format (RHEL 8's /etc/sysconfig/network-scripts/ifcfg-* is deprecated). If you edit the file by hand: mode 600, then nmcli con reload and nmcli con up.

Lab: a static IP

In the Red Hat simulator, on srv-db01 (the simulator supports nmcli con show, con mod, con up):

  1. Look at the current profile and address.
  2. Set a static IP: 10.20.0.20/24, gateway 10.20.0.1, DNS 10.20.0.1.
  3. Run con up and check with ip -br a and ip route.
  4. Check connectivity with ping srv-db01 from srv-web01.
srv-db01
[ali@srv-db01 ~]$ nmcli con show
[ali@srv-db01 ~]$ sudo nmcli con mod ens18 ipv4.method manual ipv4.addresses 10.20.0.20/24 ipv4.gateway 10.20.0.1 ipv4.dns 10.20.0.1
[ali@srv-db01 ~]$ sudo nmcli con up ens18
[ali@srv-db01 ~]$ ip -br a show ens18
[ali@srv-db01 ~]$ ip route
  1. (On your own VM) add a second address with +ipv4.addresses, then remove it. Check the settings survive a reboot.

Check: nmcli -f ipv4.method con show ens18 → manual; ping works.

Check yourself

5 questions · answers are shown instantly · 3 correct answers complete the lesson

1What is the difference between a "device" and a "connection" in nmcli?

con mod changes the profile.

2After nmcli con mod, when is the change applied?

RHEL 9 has no network.service.

3How do you add a second IP without removing the existing one?

Without a sign it replaces; ip addr is temporary.

4How do you correctly set DNS servers on RHEL?

NetworkManager writes resolv.conf.

5Where are NetworkManager profiles stored on RHEL 9?

The format is the .nmconnection keyfile.
Was this lesson useful?

Comments

Sign in to comment.