A server whose IP address changes every reboot is a server nobody can reliably reach. If you run SSH, a website, or any self-hosted service on an Ubuntu machine, give it a static IP address and be done with it.
On Ubuntu 20.04 (and every release since 17.10), network configuration is handled by Netplan — a YAML file instead of the old /etc/network/interfaces. Here's how to set a static address, plus the DHCP-reservation alternative that's often the smarter choice.
Step 1: Find your interface name and current network details
ip a
ip route | grep default
Look for your active interface — typically eth0, ens33, enp0s3, or wlan0 for Wi-Fi. The default route line shows your gateway (usually your router, e.g. 192.168.1.1).
Pick an address outside your router's DHCP pool to avoid handing out a duplicate later. For example, if the router hands out .100–.200, choose 192.168.1.50.
Step 2: Edit the Netplan config
List the existing files first — the name varies:
ls /etc/netplan/
sudo nano /etc/netplan/00-installer-config.yaml
For a wired connection, make it look like this (indentation matters — spaces only, no tabs):
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.1.50/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
Replace eth0 with your interface, and the IPs with your own. /24 is the subnet mask (255.255.255.0); our subnet calculator translates CIDR to plain numbers if you need it.
On Ubuntu Server the renderer is networkd; on desktop it's NetworkManager — keep whichever was already in the file.
Step 3: Test before applying
sudo netplan try
netplan try applies the config but rolls back automatically after 120 seconds unless you confirm. If you typo the address and lock yourself out of SSH, just wait two minutes and the old settings return. This is the safest way to change networking remotely.
Happy with the result? Confirm, or apply permanently later:
sudo netplan apply
Verify:
ip a show eth0
ping -c 3 192.168.1.1
ping -c 3 example.com
The alternative: DHCP reservation on your router
Instead of hardcoding the address on the server, you can tell the router "always give this MAC address the same IP." Find the MAC with ip link show eth0, then add a reservation (sometimes called "static lease") in your router's DHCP settings.
This is often the better option: no config on the server to break, and the address survives reinstalls. Use a Netplan static IP when you don't control the router; use a reservation when you do.
If it goes wrong
-
netplan applythrows a YAML error — you used a tab or broke indentation. YAML is unforgiving; two spaces per level. -
No internet after applying — the gateway or DNS is wrong. Check
ip routeand thenameserversline. - Two machines with the same IP — you picked an address inside the DHCP pool. Move it outside, or reserve it on the router.
Once it's set, write the address down in your server notes — future-you will thank present-you.
Top comments (0)