Updated: 11 October 2026 · Applies to: NetworkManager 1.58 (CentOS Stream 10) and 1.54 (AlmaLinux 9.8), the same nmcli commands on AlmaLinux, Rocky Linux and RHEL 9 and 10 and Fedora; netplan 1.1 and 1.2 (Ubuntu 24.04 and 26.04)
To set a static IP address from the Linux command line on CentOS Stream, AlmaLinux, Rocky Linux, RHEL or Fedora, change the NetworkManager connection with nmcli and re-activate it:
nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns "1.1.1.1 8.8.8.8" nmcli connection up eth1
Replace eth1 with your connection name and the example addresses with yours. On Ubuntu, use netplan set and netplan apply (section below). The ip addr add command also assigns an address, but only until the next reconnect or reboot.
Before you start: you need the IP address, the prefix length (/24 is netmask 255.255.255.0), the gateway and DNS servers. Work from a console, not only over SSH, because a typo cuts the connection. On a Ucartz VPS, use the addresses, netmask and gateway shown in your client area, and keep the VNC console of the VPS (client area, Services, My Services, your VPS) open while you work.
CentOS Stream, AlmaLinux, Rocky Linux, RHEL and Fedora (nmcli)
We ran these steps on CentOS Stream 10; the test network card is called eth1.
- Find the device and the name of its connection:
$ nmcli device status DEVICE TYPE STATE CONNECTION eth1 ethernet connecting (getting IP configuration) eth1 lo loopback connected (externally) lo
The CONNECTION column is what you change. It is often the device name (eth0,ens18),System eth0orWired connection 1; put names with spaces in quotes. - Set the address, gateway and DNS in one command. Setting
ipv4.method manualon its own fails, because a manual profile needs an address:Error: Failed to modify connection 'eth1': ipv4.method: method 'manual' requires at least an address, a route, or CLAT set to 'force'
So give everything together:nmcli connection modify eth1 ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns "1.1.1.1 8.8.8.8"
- Activate it:
$ nmcli connection up eth1 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
- Check:
$ ip -4 addr show dev eth1 4: eth1@eth1-peer: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 inet 192.0.2.10/24 brd 192.0.2.255 scope global noprefixroute eth1 $ nmcli -g ipv4.method,ipv4.addresses,ipv4.gateway,ipv4.dns connection show eth1 manual 192.0.2.10/24 192.0.2.1 1.1.1.1,8.8.8.8(The@eth1-peerpart appears only because our test card was a virtual pair.) Then test the gateway and DNS withping -c 3 192.0.2.1andping -c 3 example.com.
NetworkManager saves the setting at once, so it survives a reboot. On CentOS Stream 10 the profile file was /etc/NetworkManager/system-connections/eth1.nmconnection (mode 600), with this IPv4 part:
[ipv4] address1=192.0.2.10/24 dns=1.1.1.1;8.8.8.8; gateway=192.0.2.1 method=manual
If you edit such a file by hand, run nmcli connection reload and then nmcli connection up eth1. For a menu instead of commands, install NetworkManager-tui and run nmtui.
Add or remove a second IP, or go back to DHCP
nmcli connection modify eth1 +ipv4.addresses 192.0.2.11/24 # add nmcli connection modify eth1 -ipv4.addresses 192.0.2.11/24 # remove nmcli connection up eth1
To return to DHCP, clear the static values in the same command:
nmcli connection modify eth1 ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns "" nmcli connection up eth1
For a server with several ordered IPs or a whole subnet, see How to add additional IPv4 addresses on AlmaLinux or Rocky Linux with nmcli?.
CentOS 7 and 8, ifcfg files and RHEL 10
CentOS Linux 7 and 8 are end of life; CentOS Stream 9 and 10, AlmaLinux, Rocky Linux and RHEL are the current releases. The nmcli commands above are the same everywhere; what changed is where profiles are stored:
- CentOS 7 and 8: NetworkManager wrote
ifcfg-eth0files in/etc/sysconfig/network-scripts/. - RHEL, AlmaLinux and Rocky Linux 9: new profiles are keyfiles in
/etc/NetworkManager/system-connections/. Old ifcfg files still load, but the readme NetworkManager leaves in that folder says the format is deprecated and suggestsnmcli connection migrateto convert them. - Version 10 (CentOS Stream 10, AlmaLinux 10): the ifcfg support is gone; there was no
/etc/sysconfig/network-scriptsfolder and no ifcfg plugin in our tests. Migrate any ifcfg files before you upgrade.
To change the IP of a RHEL server that is already set up, or to use the ip link and old ifconfig commands, see How to Change the IP Address on RHEL, AlmaLinux and Rocky Linux (nmcli, nmtui, ip and ifconfig).
Ubuntu 24.04 and 26.04 (netplan set)
Ubuntu servers use netplan. netplan set writes the YAML for you from the command line:
netplan set ethernets.eth0.dhcp4=false
netplan set "ethernets.eth0.addresses=[192.0.2.10/24]"
netplan set "ethernets.eth0.routes=[{to: default, via: 192.0.2.1}]"
netplan set "ethernets.eth0.nameservers.addresses=[1.1.1.1, 8.8.8.8]"
netplan get ethernets.eth0
In our test, where eth0 was already defined in /etc/netplan/50-cloud-init.yaml, netplan updated that file, and netplan get printed:
addresses: - "192.0.2.10/24" nameservers: addresses: - 1.1.1.1 - 8.8.8.8 dhcp4: false routes: - to: "default" via: "192.0.2.1"
Apply it with netplan try, which rolls back by itself if you lose the connection and do not confirm, or netplan apply. On cloud images, cloud-init can rewrite 50-cloud-init.yaml; How to Set a Static IP on Ubuntu with Netplan (Ubuntu 24.04) covers that and editing the YAML by hand.
Debian 13
A standard Debian 13 server uses ifupdown: set iface eth0 inet static with address 192.0.2.10/24 and gateway 192.0.2.1 in /etc/network/interfaces. How to Set a Static IP Address on Debian 13 with ifupdown has the full steps, including DNS.
Temporary IP with the ip command
ip addr add 192.0.2.20/24 dev eth1
This is useful for a quick test, but nothing is saved. In our test, running nmcli connection up eth1 afterwards removed the address again, and a reboot does the same. Use nmcli or netplan for a permanent change. For more ip commands, see ip Command Cheat Sheet for Linux: Addresses, Interfaces, Routes and ARP with Examples.
Official documentation: nmcli (NetworkManager) and netplan set.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
