Assign a static IP on Linux with ip addr add for one-off (not persistent), Netplan YAML on Ubuntu 18.04+, ifcfg-eth0 files on RHEL family, or NetworkManager nmcli on desktop distros. The team that uses the persistent config tool matching their distro has the IP surviving reboots. The team that uses ip addr add only has the IP until the next reboot.
Table of contents
- One-off with ip command
- Persistent on Ubuntu (Netplan)
- Persistent on RHEL family (NetworkManager / ifcfg)
- Persistent on NetworkManager (nmcli)
- Verify the config
- FAQ
One-off with ip command
sudo ip addr add 192.0.2.10/24 dev eth0
sudo ip route add default via 192.0.2.1
sudo ip link set eth0 up
For DNS, edit /etc/resolv.conf (or use systemd-resolved). The team that uses this for testing or temporary config has it working in seconds. The team that wants it permanent uses the distro’s persistent config.
Persistent on Ubuntu (Netplan)
Edit /etc/netplan/01-netcfg.yaml:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- 192.0.2.10/24
routes:
- to: default
via: 192.0.2.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
Apply:
sudo netplan try
sudo netplan apply
The team that uses netplan try first catches YAML errors before locking out the SSH session.
Persistent on RHEL family (NetworkManager / ifcfg)
Edit /etc/sysconfig/network-scripts/ifcfg-eth0:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.0.2.10
PREFIX=24
GATEWAY=192.0.2.1
DNS1=1.1.1.1
DNS2=8.8.8.8
Apply:
sudo nmcli connection reload
sudo nmcli connection up eth0
The team that uses NetworkManager’s ifcfg files has the right persistent config for RHEL/CentOS/Fedora.
Persistent on NetworkManager (nmcli)
sudo nmcli connection modify "Wired connection 1" \
ipv4.addresses 192.0.2.10/24 \
ipv4.gateway 192.0.2.1 \
ipv4.dns "1.1.1.1 8.8.8.8" \
ipv4.method manual
sudo nmcli connection up "Wired connection 1"
The team that uses nmcli on desktops (Ubuntu Desktop, Fedora Workstation, etc.) has the right tool for the GUI-managed network.
Verify the config
ip -br addr show eth0
ip route show default
cat /etc/resolv.conf
The team that sees the new IP, the right default route, and the right DNS servers has it working. The team that sees the old DHCP IP needs to verify the config was applied (Netplan try, nmcli up).
FAQ
Why does my static IP not stick after reboot?
You used ip addr add instead of the persistent config (Netplan, ifcfg, nmcli). The ip command only sets the running state. The team that wants persistent config uses the distro’s tool.
What is the difference between static IP and reserved DHCP?
Both give the same IP to the same MAC. Static IP is configured on the host. Reserved DHCP is configured on the DHCP server (router, DHCP daemon). The team that manages many hosts uses DHCP reservations; the team that manages few hosts uses static IP.
Should I use Netplan or NetworkManager?
On Ubuntu Server: Netplan. On Ubuntu Desktop: NetworkManager (Netplan renders to it). On RHEL Server: NetworkManager (ifcfg files or nmcli). On RHEL Workstation: NetworkManager.
What about cloud-init overrides?
Cloud instances may have cloud-init that rewrites network config on boot. The fix is to disable cloud-init’s network management (network: { config: disabled } in /etc/cloud/cloud.cfg.d/).
How do I set IPv6 static IP?
Same tools, different config fields. Netplan: addresses: [2001:db8::10/64]. ifcfg: IPV6ADDR=2001:db8::10/64. nmcli: ipv6.addresses 2001:db8::10/64. The team that needs IPv6 static uses the same persistent config tool with IPv6 fields.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: