VPSGauge

Set a Static IP on Ubuntu Server with Netplan

Updated Nov 21, 2026 · by Kane · how we check

Part of New VPS setup, our guide to this topic

Short answer

To set a static IP on Ubuntu Server, use netplan: create a YAML file in /etc/netplan/ that sets addresses, routes (with - to: default) and nameservers for your interface, then run sudo netplan try and press Enter to keep it (sudo netplan apply does the same without the safety timer). On most VPSs the public IP is already static and handed out by the provider, so the real job is usually adding a second IP — not re-inventing the first.

Time
15 min
Steps
5
Works on
Ubuntu
24.04 LTS
On this page
  1. When to leave a VPS’s IP alone (and when to set one)
  2. Static IP setup on Ubuntu Server: 5 steps
    1. 1Find your interface name and gateway
    2. 2Create the netplan file
    3. 3Test it without locking yourself out
    4. 4Use netplan apply for later changes
    5. 5Check it worked
  3. Key takeaways
  4. A VPS for this guide
  5. Adding a second / additional IP
  6. Disable cloud-init’s network config so your change survives reboot
  7. Ubuntu Server static IP setup problems
  8. A VPS for this guide
  9. Questions

This guide has no affiliate links in the steps.

Netplan is how Ubuntu Server 24.04 configures the network: you describe what you want in YAML, and netplan hands it to systemd-networkd, which applies it to the interface. This is the networking side of a server you can already reach — if you haven’t logged in yet, how to SSH into a VPS comes first, and the new VPS setup checklist covers the users and firewall around it.

A terminal window editing a netplan YAML file beside a server, with the default-route line highlighted: the file is the address book your server reads at boot.

When to leave a VPS’s IP alone (and when to set one)

On most VPSs the public IP is already static, and it’s the provider’s to manage. The provider assigns the address through DHCP or a metadata service, and on Ubuntu cloud images cloud-init writes it into /etc/netplan/50-cloud-init.yaml. The provider routes traffic to that exact address, so if you edit the file to a random address, packets stop reaching you and SSH drops. The network only works with the IP the provider gave you.

You actually want to set a static IP in three situations:

  • You’re adding a second, floating or additional IP you bought from the provider. This is the common real task, and it’s covered below.
  • You’re on hardware you control — a home server or a bare-metal box behind your own router — where DHCP would hand out a different address after a reboot.
  • You’ve disabled cloud-init and taken over network config yourself (see below).

If none of those apply, leave /etc/netplan/50-cloud-init.yaml alone.

ON A VPS, THE PROVIDER OWNS THE PUBLIC IP PROVIDER assigns the public IP via DHCP / metadata cloud-init writes 50-cloud-init.yaml with 203.0.113.10/24 YOUR SERVER answers on 203.0.113.10 edit it to a random IP → the provider stops routing to you → SSH drops
ON A VPS, THE PROVIDER OWNS THE IP PROVIDER assigns the public IP via DHCP / metadata cloud-init writes 50-cloud-init.yaml with 203.0.113.10/24 YOUR SERVER answers on 203.0.113.10 edit to a random IP → routing stops → SSH drops
How to Set Static IP Addresses in Ubuntu 24 Server (Netplan Tutorial) (RealClearComputing) · YouTube (loads when you press play)

Static IP setup on Ubuntu Server: 5 steps

In the commands, eth0 and the IPs are examples. Replace them with your interface name and the addresses from your network.

1

Find your interface name and gateway

serverip -brief address
ip route

Check: ip -brief address lists every interface with its current address; the one holding your public IP is the one to configure (usually eth0 or ens3). ip route shows a line like default via 203.0.113.1 dev eth0 — note both the gateway and the interface.

2

Create the netplan file

serversudo nano /etc/netplan/99-static.yaml
servernetwork:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 203.0.113.10/24
      routes:
        - to: default
          via: 203.0.113.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

version: 2 and renderer: networkd are the standard header. dhcp4: false turns off DHCP for this interface. addresses is the static address plus its prefix length (/24 is a 255.255.255.0 netmask). routes: - to: default with via: is the gateway, and nameservers is DNS.

Older tutorials write gateway4: 203.0.113.1. The netplan YAML reference (read Nov 18, 2026) marks gateway4 and gateway6 as deprecated and points to the routes: default-route form instead, and Ubuntu Server’s networking docs say only the netplan in 18.04 needs the old key. So on 24.04, write routes: - to: default — the old key is on its way out, and the new form is the one the docs use.

Keep the file readable only by root. Netplan warns that a config file’s “permissions are too open” when other users can read it:

serversudo chmod 600 /etc/netplan/99-static.yaml
WHAT YOU WRITE → WHAT THE INTERFACE GETS 99-static.yaml addresses: 203.0.113.10/24 routes: - to: default nameservers: 8.8.8.8 netplan apply eth0 203.0.113.10/24 default via 203.0.113.1 DNS 8.8.8.8 the default route is the part that matters — get it wrong and nothing leaves the box
WHAT YOU WRITE → WHAT THE INTERFACE GETS 99-static.yaml addresses: 203.0.113.10/24 routes: - to: default nameservers: 8.8.8.8 netplan apply eth0 203.0.113.10/24 default via 203.0.113.1 DNS 8.8.8.8 the default route is the part that matters
3

Test it without locking yourself out

serversudo netplan try

netplan try applies your config and starts a countdown — 120 seconds by default, per the netplan try manual (--timeout changes it). If you don’t confirm it, the change reverts automatically — that’s the safety net for a change that can cut your connection.

Check: In a second terminal, your new address is live. Press Enter to keep the config, or do nothing and wait for it to revert.

If it fails: You applied the wrong address and the session froze. Wait the 120 seconds — netplan puts the old config back and the connection returns. If it doesn’t, use the provider’s web console (VNC or serial) to fix the file. It’s the same idea as changing your SSH port safely, which our Ubuntu SSH server guide walks through.

netplan try — TEST FIRST, REVERT AUTOMATICALLY netplan try applies the new config starts a 120-second timer you press Enter config confirmed stays after reboot you lose SSH timer runs out old config auto-reverts if SSH drops, do nothing — the timer reverts it; the provider web console is the backup
netplan try — TEST FIRST, REVERT AUTOMATICALLY netplan try applies the new config 120-second timer you press Enter config confirmed stays after reboot you lose SSH timer runs out old config reverts if SSH drops, do nothing — the timer reverts it; the web console is the backup
4

Use netplan apply for later changes

serversudo netplan apply

If you pressed Enter in step 3, the config is already live and this changes nothing. apply is the same change without the countdown — use it after later edits you’ve already proved with try, or in scripts.

5

Check it worked

serverip addr show eth0
ip route
ping -c 3 1.1.1.1

Check: ip addr shows your static address, ip route shows the default route through your gateway, and ping reaches the internet.

Key takeaways

  1. On Ubuntu Server, a static IP is netplan: a YAML file in /etc/netplan/, then sudo netplan try and sudo netplan apply.
  2. The gateway key is routes: - to: default with via: — not the deprecated gateway4.
  3. On a VPS the provider’s IP is already static and routed; editing 50-cloud-init.yaml to a random address cuts your SSH.
  4. netplan try reverts after 120 seconds if you don’t confirm — that plus the provider’s web console is your safety net.
  5. To keep your own config across reboots on a cloud image, disable cloud-init’s network config.

A VPS for this guide

Everything above runs on any VPS with 1 GB of RAM. The cheapest 1 GB+ plan at each provider whose prices we read every day, IPv4 included:

Plan · providervCPU · RAM · diskYou payVisit
KVM VPS Special 1 GB
RackNerd · Los Angeles +19
1 vCPU·1 GB·20 GB$1.83/mo
VPS pico G11.5s
netcup · Nuremberg
1 vCPU·1 GB·30 GB$2.00/mo
SSD VPS 1
CloudCone · USA
2 vCPU·1 GB·30 GB$2.33/mo
1 slice
InterServer · New York +2
1 vCPU·2 GB·40 GB$3.00/mo
NVMe 2 GB
HostHatch · Amsterdam +15
1 vCPU·2 GB·10 GB$4.00/mo

Prices read Dec 4, 2026. gets that provider's deals on Telegram. Compare every 1 GB plan →

Adding a second / additional IP

The most common real reason to touch netplan on a VPS is a second IP. You buy the extra address in your provider’s panel first; what happens next depends on the provider. Two examples from their own docs (both read Nov 18, 2026):

  • DigitalOcean Reserved IPs: nothing to add in netplan. Traffic to a reserved IP reaches the Droplet through its “anchor IP”, which is already on eth0 — you bind services to the anchor IP rather than adding the reserved address (DigitalOcean anchor IP docs; Droplets created before 20 October 2015 need the anchor IP enabled by hand).
  • Hetzner Cloud Floating IPs: you add them yourself. Hetzner’s guide has you create a separate netplan file with the floating address as a /32 (Hetzner Floating IP configuration).

Check your provider’s own docs before assuming either way. For the “add it in netplan” case, Hetzner’s pattern works well because it leaves the provider’s main file alone:

sudo nano /etc/netplan/60-floating-ip.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 203.0.113.50/32

Then sudo chmod 600 the file and run sudo netplan try as before.

Which providers sell an extra IPv4, from our hand-checked provider notes (each read on the provider’s own page, Nov 14, 2026): IONOS lists $5/month per additional IPv4; InterServer allows up to 5 more when justified, at $3 per IP per month; Kamatera charges $1/month each for up to 3 more; CloudCone charges a one-time $2 admin fee per IP; and a Vultr reserved IP is $3/month. Akamai/Linode wants technical justification and prices extra IPs by region, while OVHcloud and Contabo sell extra IPs without a price on the pages we read. Re-check the current price before you buy.

Disable cloud-init’s network config so your change survives reboot

On a cloud image, 50-cloud-init.yaml belongs to cloud-init. It writes the file from the provider’s data on an instance’s first boot, and on some clouds it is set up to do so on every boot (cloud-init events docs), so a hand-edited static config can get overwritten. If you’ve decided to manage the network yourself, tell cloud-init to stop touching it — the cloud-init network config docs (read Nov 18, 2026) give network: config: disabled in a file under /etc/cloud/cloud.cfg.d/:

sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

This only stops future rewrites; the existing 50-cloud-init.yaml stays in place until you change or replace it. Make your edit, then sudo netplan try. From that point your netplan files are the only thing controlling the network, so a mistake has no cloud-init reset to fall back on — keep the web console handy while you make the change.

Ubuntu Server static IP setup problems

SSH drops after I apply a static IP.You set the wrong address or gateway. If you used netplan try, wait for the 120-second revert; otherwise log in through the provider’s web console and fix the file.

netplan warns about gateway4.It’s deprecated. Use routes: - to: default with via: instead, and mind the indentation — YAML is whitespace-sensitive and tabs are not allowed.

The config reverts after a reboot.cloud-init is rewriting 50-cloud-init.yaml. Disable its network config (section above), or put your changes in a file it doesn’t own.

My interface isn’t called eth0.Find the real name with ip -brief address — ens3, enp1s0 and similar are common on cloud images.

netplan apply says the configuration is not valid.Check that every key under ethernets: and the interface is indented exactly as shown, with two spaces per level and no tabs.

A VPS for this guide

Setting a static IP needs almost nothing from the machine — any size works, and the smallest plan at each provider runs it fine. The table at the end lists the cheapest 1 GB plan at each provider we read daily.

Questions

Does Ubuntu Server use DHCP or a static IP by default?

On a VPS it’s whatever the provider’s cloud-init config says — often DHCP, sometimes the provider’s address written in as static. Look at /etc/netplan/50-cloud-init.yaml to see which. If cloud-init finds no network config at all, its docs say it falls back to DHCP on the first interface.

What is netplan?

Ubuntu’s network configuration tool. You describe the network in YAML files under /etc/netplan/, and netplan renders them into config for systemd-networkd (the default backend), which applies them to the interface.

Should I still use gateway4 on Ubuntu 24.04?

It’s deprecated: the netplan YAML reference marks gateway4 and gateway6 as deprecated and points to the routes: default-route form. Write routes: - to: default with via: instead.

How do I find my interface name?

Run ip -brief address and look for the interface holding your IP — typically eth0, ens3 or enp1s0.

Will my static IP survive a reboot?

Yes, if netplan apply succeeded. On a cloud image the provider’s cloud-init config can overwrite yours on boot, so disable its network config if you want your own file to win.

How do I undo a static IP?

Set dhcp4: true (and remove addresses/routes/nameservers), then sudo netplan apply. If you only just changed it, netplan try already reverted for you.

How we checked: The YAML keys and commands follow the netplan YAML reference, the netplan try manual and Ubuntu Server’s networking documentation; the cloud-init step follows its network-configuration docs; the second-IP section follows DigitalOcean’s and Hetzner’s own docs — all read on 2026-11-18. The file-permissions warning is quoted from netplan’s source code. The provider extra-IPv4 prices come from our hand-checked provider notes, each with its own source page and check date. We did not run the steps on every provider’s image; a provider that manages the network its own way may differ. How we check.

Keep reading