← Back to Tutorials
28 April 2026·5 min read

Configure a Static IP on Ubuntu 24.04 (Netplan)

Step-by-step: set a static IP on Ubuntu 24.04 with Netplan. YAML config, gateway, DNS, and how to apply changes without breaking your SSH session.

By default, Ubuntu 24.04 LTS servers pull their network configuration from DHCP. That is fine for a laptop, but a server that hosts services, databases, or other machines depends on needs a predictable, permanent address. If the IP changes after a reboot, DNS records break, firewall rules stop matching, and clients lose their connection. This guide walks through setting a static IP on Ubuntu 24.04 using Netplan, the YAML-based network configuration system Ubuntu has shipped since 18.04.

We will cover the exact YAML you need, how to find your interface name and gateway, and—most importantly—how to apply the change safely so you do not lock yourself out of a remote SSH session. Everything here targets Ubuntu Server 24.04 with the default systemd-networkd renderer.

Prerequisites

  • A machine running Ubuntu 24.04 LTS (server or desktop).
  • A user account with sudo privileges.
  • The IP address you want to assign, plus your subnet mask, gateway, and DNS servers. If you are on a typical home or office LAN, the gateway is usually your router (for example 192.168.1.1).

Step 1: Identify your network interface

Netplan needs the exact name of the interface you want to configure. List your interfaces with the ip command:

ip -br link show

You will see output similar to this:

lo               UNKNOWN        00:00:00:00:00:00
ens18            UP             bc:24:11:aa:bb:cc

Ignore lo (the loopback). The physical interface here is ens18. On your system it might be eth0, enp0s3, or similar. Note the name—you will need it shortly.

Step 2: Find your current gateway and subnet

If the host currently works over DHCP, you can reuse its existing gateway. Show the default route:

ip route | grep default
default via 192.168.1.1 dev ens18 proto dhcp src 192.168.1.50 metric 100

Here the gateway is 192.168.1.1. Check the subnet mask in CIDR form:

ip -br addr show ens18

An address like 192.168.1.50/24 tells you the prefix is /24 (a 255.255.255.0 mask), which you will carry into the static config.

Step 3: Locate the Netplan configuration file

Netplan YAML files live in /etc/netplan/. List them:

ls -l /etc/netplan/

On a fresh Ubuntu Server install you will typically find a file such as 50-cloud-init.yaml or 00-installer-config.yaml. Rather than fight cloud-init, create a dedicated file with a higher number so it loads last and wins. We will use /etc/netplan/01-static.yaml.

Step 4: Write the static IP configuration

Open a new Netplan file:

sudo nano /etc/netplan/01-static.yaml

Add the following, substituting your interface name, address, gateway, and DNS servers. Indentation matters in YAML—use spaces, never tabs:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens18:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

A few notes on this config. We set dhcp4: false to stop the interface from also requesting a DHCP lease. The address includes the CIDR prefix (/24). Note that the old gateway4: key is deprecated on Ubuntu 24.04—use the routes block with to: default instead, which is the supported syntax.

Step 5: Lock down file permissions

Netplan warns if your config is world-readable, because it can contain sensitive data such as Wi-Fi passwords. Tighten the permissions:

sudo chmod 600 /etc/netplan/01-static.yaml

Step 6: Apply the change safely with netplan try

This is the step that saves remote admins from disaster. Instead of applying blindly, use netplan try. It applies the new configuration and starts a countdown; if you do not confirm within 120 seconds, it automatically rolls back to the previous working config. If your YAML had a mistake that broke connectivity, the rollback restores your session.

sudo netplan try

You will see:

Do you want to keep these settings?

Press ENTER before the timeout to accept the new configuration

Changes will revert in 120 seconds

If you are connected over SSH and the new IP is different from the one you connected with, your session may freeze here—that is expected. Reconnect on the new IP, confirm it works, and only then press ENTER. If you cannot reconnect, just wait: Netplan reverts automatically.

Once you are confident, finalize with:

sudo netplan apply

Step 7: Verify the configuration

Confirm the interface now holds the static address:

ip -br addr show ens18
ens18            UP             192.168.1.50/24

Check the default route points at your gateway:

ip route | grep default

And verify DNS resolution and outbound connectivity:

resolvectl status
ping -c 3 1.1.1.1
ping -c 3 ubuntu.com

If the IP ping works but the hostname ping fails, your routing is fine but DNS is misconfigured—revisit the nameservers block.

Common pitfalls and troubleshooting

  • YAML indentation errors. Netplan is strict. A misaligned key throws Invalid YAML. Validate before applying with sudo netplan generate, which fails loudly on syntax problems.
  • Tabs instead of spaces. YAML forbids tab characters for indentation. If your editor inserts tabs, switch it to spaces.
  • Forgetting dhcp4: false. Leaving DHCP enabled can result in two addresses on the interface and unpredictable routing.
  • cloud-init overwriting your config. If the address reverts after reboot, cloud-init may be regenerating the network. Disable it for networking by creating /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled}.
  • Deprecated gateway4 key. If you see a deprecation warning, replace gateway4 with the routes block shown above.

Conclusion

With a short Netplan YAML file and the safety net of netplan try, you can give any Ubuntu 24.04 server a stable, permanent address without risking your remote session. Predictable static addressing is the foundation everything else builds on—firewall rules, DNS, reverse proxies, and clustered services all assume the address will not move.

That same principle scales up: a production private cloud needs deterministic networking across dozens of hosts and tenant networks. If you would rather not hand-maintain network configuration across a fleet, clouditiv operates a managed, sovereign on-premise cloud on Ubuntu 24.04 and OpenStack, where addressing, routing, and DNS are provisioned automatically. When you are ready to go beyond a single host, the same fundamentals reappear at the SDN layer—see our tutorial on Linux bridge networking for VMs as the next step.