Set a static IP on Ubuntu by writing a Netplan YAML file with dhcp4: no and an addresses: block, then running sudo netplan apply. The right way for a remote box is netplan try, which reverts after 120 seconds if the new config breaks connectivity. The team that uses try on remote boxes has the right safety net.
Table of contents
The right Netplan YAML
The right config:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
Replace enp0s3 with the actual interface name. Replace the IP, gateway, and nameservers with your values.
Applying the config
The right command for a local box:
sudo netplan apply
The right command for a remote box where the wrong config would lock you out:
sudo netplan try
netplan try reverts automatically after 120 seconds if the new config breaks connectivity. The right answer is to use try on remote boxes.
Verifying the change
The right verification is three commands:
ip a show enp0s3
ip route
resolvectl status
Common mistakes
Wrong indentation (use 2-space indents, no tabs). Wrong CIDR (use the actual subnet’s CIDR). Forgetting to disable cloud-init on cloud servers. Forgetting to update the firewall on a cloud server.
FAQ
What if I lose connection after netplan apply?
If you used netplan try, wait 120 seconds. If you used netplan apply and lost connection, use the cloud provider’s console or IPMI to revert the YAML.
Can I have multiple static IPs?
Yes. Add them to the addresses: list. The right answer is to ensure each is in the right subnet.
What about IPv6?
Replace dhcp4 with dhcp6 and add the IPv6 prefix.
What is the difference between networkd and NetworkManager?
networkd is the server default. NetworkManager is the desktop default. Netplan generates configs for whichever is active.
How do I revert to DHCP?
Set dhcp4: yes and remove the addresses:, routes:, and nameservers: blocks.
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: