How to Set a Static IP Address on Ubuntu Server (Netplan)

Your router hands out IP addresses on a first-come, first-served basis, so after a reboot or two your server might be 192.168.1.50 one day and .73 the next. Every bookmark, SSH shortcut and port forward then breaks. Give it a fixed address and the problem goes away for good.
Quick reference
| Method | Where | Best for |
|---|---|---|
| DHCP reservation | Your router's admin page | Most home servers (easiest) |
| Netplan static config | /etc/netplan/*.yaml on the server | When you can't change the router |
| Apply Netplan changes | sudo netplan try then sudo netplan apply | — |
Option 1: Reserve the address on your router (recommended)
The server keeps using DHCP, but the router always gives it the same address.
- Find the server's MAC address: ip link on the server — it's the link/ether line, like b8:27:eb:12:34:56.
- Log in to your router (usually 192.168.1.1 or 192.168.0.1).
- Look for DHCP reservation, Static lease or Address reservation.
- Pick the server from the list of connected devices (or paste its MAC) and type the address you want.
- Save, then reboot the server.
Nothing to configure on the server, and you can't break the network settings.
Option 2: Set it on the server with Netplan
- Find the network interface name:
ip a
It's something like eth0, enp3s0 or ens18 — the one with your current IP next to it.
- Open the Netplan file:
sudo nano /etc/netplan/50-cloud-init.yaml
(The file name varies — ls /etc/netplan shows what's there.)
- Replace the contents with this, changing the interface name and addresses to suit:
network:
version: 2
ethernets:
enp3s0:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 1.1.1.1]
Spacing matters: two spaces per level, no tabs.
- Test it safely:
sudo netplan try
This applies the change and undoes it after 120 seconds unless you press Enter. If your SSH session is still alive, press Enter to keep it. If it died, wait two minutes and the old settings come back.
- Make it permanent:
sudo netplan apply
Choosing an address
Pick one outside the range your router hands out automatically (check the router's DHCP settings — it's often .100 to .200), so there's no chance of a clash. 192.168.1.50 or .10 are typical.
Troubleshooting
"Permissions for /etc/netplan/... are too open." Run sudo chmod 600 /etc/netplan/*.yaml.
Internet stops working after the change. The via address isn't your router, or nameservers is wrong. Check the router's address with ip route before editing (look for default via).
Error about "cloud-init". Create /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled} so cloud-init stops regenerating the file.
Wi-Fi instead of Ethernet. Netplan can do it (under wifis: with an access-points: block) but a server really should be on a cable.
Wrapping up
Use the router reservation if you can — it's one form and nothing on the server changes. If not, Netplan with netplan try lets you test without risking a trip to the server with a keyboard. Either way, ssh home will always find the right machine.
