Set a static IP with netplan (Ubuntu / Debian)
Configure a static IP address on Ubuntu or Debian using netplan. Includes a dry-run safety step so you can't accidentally lock yourself out of a remote server.
bash# 1. Find your interface name and current IP
ip -brief addr show
ip route show default
# 2. Create a netplan config (adjust INTERFACE, ADDRESS, GATEWAY, DNS)
sudo tee /etc/netplan/99-static.yaml > /dev/null <<'EOF'
network:
version: 2
ethernets:
eth0: # Replace with your interface name (e.g. ens18, enp3s0)
dhcp4: false
addresses:
- 192.168.1.100/24 # Your desired static IP and subnet mask
routes:
- to: default
via: 192.168.1.1 # Your router or gateway IP
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
EOF
# Set correct permissions (netplan warns if world-readable)
sudo chmod 600 /etc/netplan/99-static.yaml
# 3. Dry run — applies for 120 seconds then reverts if you don't confirm
# Press ENTER to accept, or wait for automatic rollback
sudo netplan try
# 4. Apply permanently (only run after confirming connectivity in step 3)
sudo netplan apply
What this does
Creates a netplan configuration file that assigns a static IP to a network interface. The critical safety step is netplan try, which applies the new config for 120 seconds and automatically rolls back if you don’t confirm — preventing permanent lockout on remote servers.
Why this approach
DHCP is convenient for workstations, but self-hosted services need predictable addresses. If your Plex server’s IP changes because the DHCP lease expired and a different device grabbed the address first, nothing that points to it works — not your firewall rules, not the hostnames in your Arr stack, not the URLs you bookmarked. A static IP on a service host means it’s always at the same address, and you can plan network access around it.
The netplan YAML approach is the right method on Ubuntu and modern Debian because it’s what the distro expects: the config is declarative, version-controllable, and applied cleanly by either networkd or NetworkManager depending on the system type. Manual ifupdown config (/etc/network/interfaces) still works on older Debian, but it’s a dead-end on Ubuntu — netplan replaced it.
The netplan try command is the safety net that makes this safe to run on a remote server. It applies the new config and starts a 120-second countdown. If you don’t confirm within the window (which you can’t do if you accidentally broke connectivity), it rolls back to the previous config automatically. Without this step — if you just ran netplan apply — a misconfigured IP would lock you out until you could access the console or get hands-on with the machine.
Prerequisites
- Ubuntu 18.04+ or Debian 12+ (netplan is standard on Ubuntu; Debian may need it installed)
- Root or sudo access
- Know your desired IP, subnet mask, gateway, and interface name
Find your interface name and current network settings
# List interfaces and their IPs
ip -brief addr show
# Show current default gateway
ip route show default
# Example output:
# lo UNKNOWN 127.0.0.1/8
# eth0 UP 192.168.1.50/24 ← interface is 'eth0'
# default via 192.168.1.1 dev eth0 ← gateway is 192.168.1.1
Common interface names: eth0, ens18 (VMware/Proxmox), enp3s0 (bare metal), ens3 (KVM).
Check for existing netplan files
ls /etc/netplan/
If there’s an existing file (e.g. 00-installer-config.yaml from Ubuntu’s installer), either edit it directly or disable DHCP in it and add your static config in 99-static.yaml. Higher-numbered files take precedence.
Disable an existing DHCP file
If you have a 00-installer-config.yaml that sets dhcp4: true, edit it:
sudo nano /etc/netplan/00-installer-config.yaml
Change dhcp4: true to dhcp4: false and remove any existing dhcp4-overrides blocks, then add your static config to 99-static.yaml.
The netplan try safety window
When you run sudo netplan try, the new config is applied immediately and a 120-second countdown begins. If you close your SSH session or the new IP is wrong:
- Automatic rollback: the old config is restored after the timeout — you reconnect on the original IP
- Manual accept: if connectivity works, press Enter before the countdown expires to make it permanent
This is the correct way to change network settings on a remote server.
Multiple IPs on one interface
addresses:
- 192.168.1.100/24
- 192.168.1.101/24
VLAN interface
network:
version: 2
vlans:
vlan10:
id: 10
link: eth0
dhcp4: false
addresses:
- 10.0.10.5/24
Debian: install netplan
Netplan is not installed by default on Debian. Install it and disable ifupdown:
sudo apt-get install -y netplan.io
sudo systemctl disable networking
Notes
- Netplan is a YAML front-end; it generates and applies config for either
networkd(servers) orNetworkManager(desktops) depending on therenderer:key (default isnetworkd) chmod 600on the YAML file prevents a netplan warning about world-readable credentials- After
netplan apply, verify:ip addr show eth0andping 1.1.1.1