/etc/netplan/, set dhcp4: false, list your address under addresses (for example 203.0.113.10/24), add a default route with routes: - to: default via: 203.0.113.1 and your DNS under nameservers. Run sudo netplan try to test with automatic rollback, then press Enter to keep it.
Before you start
- Netplan is Ubuntu’s network configuration tool: you describe the network in a YAML file and Netplan hands it to
systemd-networkdor NetworkManager. - Get your address, prefix length, gateway and DNS servers. On a VPS they’re on the Network tab of the VPS Panel. A netmask of
255.255.255.0is prefix/24. - Open the VNC console before you start. If the network breaks, you can still log in there.
- On AlmaLinux and Rocky Linux, NetworkManager is used instead: see add IP addresses on Linux for
nmclicommands.
How to set a static IP with Netplan
1
Find the interface name
UP, for example eth0, ens3 or enp1s0.2
Find and back up the Netplan file
/etc/netplan/, because Netplan reads every .yaml file in that folder.3
Edit the file
4
Set safe permissions
5
Test the configuration
Press ENTER before the timeout to accept the new configuration. Open a new SSH session to the server. If it works, press Enter in the first one. If you can’t connect, do nothing: the old configuration comes back after 120 seconds.6
Apply permanently (if needed)
If you accepted in
netplan try, the change is already active. After editing the file again later, you can apply directly with:How to check it worked
ping -c 3 1.1.1.1 and ping -c 3 ubuntu.com.
What if the gateway is outside my subnet?
Some networks give a single address (/32) or a gateway that isn’t inside your address range. Netplan then needs on-link: true on the route so the server knows the gateway is directly reachable:
Why does Netplan say gateway4 is deprecated?
Older guides use gateway4: 203.0.113.1. Current Netplan still reads it but warns: “gateway4 has been deprecated, use default routes instead”. Replace it with the routes: - to: default block shown above. Don’t use both: Netplan then reports conflicting default routes and refuses the file.
Will cloud-init overwrite my changes?
If the file is called50-cloud-init.yaml and starts with a comment saying it was generated by cloud-init, cloud-init may write it again. To stop cloud-init from managing the network, create a file in /etc/cloud/cloud.cfg.d/ with this content, as described in the cloud-init network documentation:
Frequently asked questions
Where is the Netplan config file on Ubuntu?
In/etc/netplan/. The name varies, for example 50-cloud-init.yaml, 00-installer-config.yaml or 01-netcfg.yaml. Netplan reads all .yaml files there in alphabetical order.
What is the difference between netplan try and netplan apply?
netplan try applies the change and reverts it automatically unless you confirm within the timeout (120 seconds by default; change it with --timeout). netplan apply applies it immediately with no rollback.
How do I add IPv6 or a second IP?
Add more lines underaddresses, for example - 203.0.113.11/24 or - "2001:db8::10/64". See add IP addresses on Linux and configure IPv6 on Linux.
Netplan gives “Invalid YAML”. What’s wrong?
Usually indentation. YAML needs consistent spaces (no tabs), and each level indented further than its parent. Compare with the example above, or runsudo netplan generate to see the line with the error.
Related guides
VPS and dedicated server guides
Every guide in this section.
Add more IP addresses
Netplan, NetworkManager and ifupdown.
Configure IPv6
Add an IPv6 address and route.
Change DNS resolvers
Set the nameservers your server uses.
VNC console
Log in when the network is down.
Checked against the official Netplan documentation and Ubuntu Server networking guide on 4 November 2026; the YAML examples were validated with
netplan generate (Netplan 1.1.2) on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026