Skip to content
Commitpedia
Log in Join & edit

Set a static IP address: nmcli on RHEL vs netplan on Ubuntu

RHEL, Rocky and AlmaLinux configure networking with NetworkManager (nmcli); Ubuntu Server uses netplan YAML. Here is the same static IP setup in both.

Not checked by a trusted editor yet Last edited Outdated?

Edit history of Set a static IP address: nmcli on RHEL vs netplan on Ubuntu: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

Servers usually need a fixed address. How you set it depends on the distribution: RHEL and its rebuilds manage interfaces with NetworkManager, controlled by nmcli. Ubuntu Server uses netplan: you describe the network in a YAML file and netplan hands it to a backend (systemd-networkd on servers, NetworkManager on desktops). Debian without netplan often still uses /etc/network/interfaces, which is not covered here.

The examples use interface enp1s0, address 192.0.2.10/24, gateway 192.0.2.1 and DNS server 192.0.2.53. Replace them with your values.

Warning: changing the address of the interface you are connected through will cut your SSH session if anything is wrong. Use the server console (hypervisor, IPMI, cloud serial console) when possible, or netplan’s try mode described below.

Step 0: find the interface name

ip -br address
ip route show default

RHEL, Rocky, AlmaLinux: nmcli

NetworkManager stores settings in connection profiles. First find the profile that belongs to the interface:

nmcli device status
nmcli connection show

Then switch that profile from DHCP to a static address (the profile is often named like the interface, but not always):

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo nmcli connection modify enp1s0 \
  ipv4.method manual \
  ipv4.addresses 192.0.2.10/24 \
  ipv4.gateway 192.0.2.1 \
  ipv4.dns 192.0.2.53 \
  ipv4.dns-search example.com
sudo nmcli connection up enp1s0

modify only changes the saved profile; connection up applies it. The profile is stored on disk and survives reboots. To go back to DHCP: sudo nmcli connection modify enp1s0 ipv4.method auto ipv4.addresses '' ipv4.gateway '', then connection up again.

If you prefer a menu, nmtui offers the same settings in the terminal.

Ubuntu Server: netplan

Netplan reads YAML files from /etc/netplan/ (also /run/netplan/ and /lib/netplan/) in alphabetical order; later files override earlier ones. The installer or cloud-init usually creates one already. Look at what is there, back it up, and edit that file rather than adding a conflicting one:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
ls /etc/netplan/
sudo cp /etc/netplan/50-cloud-init.yaml /root/netplan-backup.yaml   # use your file name
sudo nano /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: false
      addresses:
        - 192.0.2.10/24
      routes:
        - to: default
          via: 192.0.2.1
      nameservers:
        addresses: [192.0.2.53]
        search: [example.com]

YAML is indentation-sensitive: use spaces, never tabs. Older guides use a gateway4: key; current netplan uses a routes: entry with to: default instead.

If a file was written by cloud-init, cloud-init may regenerate it on the next boot. Its header comment explains how to disable that; follow it, or your change may be overwritten.

Apply safely with netplan try. It applies the new config and rolls it back automatically after 120 seconds unless you confirm, so a mistake does not lock you out:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo netplan generate     # syntax check, writes backend config only
sudo netplan try          # apply, press Enter to keep it
sudo netplan apply        # apply without the safety net

Verify (both distributions)

ip address show enp1s0
ip route show default
resolvectl status enp1s0     # on systems using systemd-resolved
cat /etc/resolv.conf
ping -c 3 192.0.2.1

Then reboot once during a maintenance window to be sure the address comes back on its own.

Do not mix tools

Pick the tool your distribution uses and stick with it. Commands like ip address add change the running state only and are lost at reboot; editing files that NetworkManager or netplan generate is overwritten the next time those tools run.

Official documentation

See also

  • 0103 Proxmox VE networking: Linux bridges (vmbr0) and VLANs Guests reach the network through Linux bridges such as vmbr0, defined in /etc/network/interfaces. Learn the default setup, VLAN-aware bridges, VLAN tags for… Intermediate · How-to · Linux Article Installation & first steps · Networking & firewalls 15 Oct 2026
  • 0167 Fix: Job for nginx.service failed because the control process exited with error code systemctl prints this when a service's start command exits with an error. The real reason is in journalctl; for nginx it is… Intermediate · Fix · Linux Article Networking & firewalls · Services & systemd 15 Oct 2026
  • 0174 Network and DNS troubleshooting commands: ip, ss, dig, resolvectl A layer-by-layer cheat sheet for "the server cannot reach X": interfaces and routes with ip, listening ports with ss, and name resolution… Beginner · Reference · Linux Article Networking & firewalls 15 Oct 2026
  • 0175 Open ports with firewalld and ufw firewalld (RHEL, Rocky, AlmaLinux) and ufw (Ubuntu) are friendly front ends to the kernel firewall. Allow SSH first, then open only the… Intermediate · How-to · Linux Article Networking & firewalls 15 Oct 2026
  • 0249 Set up and harden a fresh Linux server in one afternoon Take a new Ubuntu, Debian or Rocky/Alma server from first login to a safer baseline: sudo admin, SSH keys only, firewall, automatic… Beginner · Tutorial · Linux Article Networking & firewalls · Packages & updates · Users, sudo & hardening 15 Oct 2026

Repos in the wild

  • firewalld: zone-based firewall daemon firewalld/firewalld Upstream source of firewalld, the default firewall manager on RHEL, Rocky Linux, AlmaLinux and Fedora, including firewall-cmd and its service definitions. GitHub

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Commitpedia +3,812 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?