How to Set a Static IP Address on Ubuntu Server with Netplan Print

  • 0

Servers should not change addresses. Whether it is an office file server, a home-lab VM or a machine behind a load balancer, a static IP on Ubuntu is configured through Netplan — the YAML-based network configuration system Ubuntu has used since 18.04. It looks intimidating the first time; it is actually three keys and a safety command that makes lockouts nearly impossible.

Warning: On a public cloud VPS, your provider usually assigns the IP via DHCP and expects it to stay that way — check their documentation before changing anything. This guide is for LANs, VMs, dedicated servers and providers that explicitly require static configuration.

Step 1 — Find your interface and current settings

ip -br addr
ip route | grep default
ls /etc/netplan/

Note the interface name (eth0, ens3, enp1s0…), your current gateway, and which YAML files exist.

Step 2 — Write the Netplan configuration

sudo nano /etc/netplan/01-static.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
Netplan YAML configuration for a static IP address on Ubuntu server

Adjust interface name, address (with CIDR suffix — /24 means netmask 255.255.255.0), gateway and DNS servers. YAML is whitespace-sensitive: two spaces per level, never tabs. Secure the file or Netplan will warn about permissions:

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

Step 3 — Test with netplan try (not apply!)

sudo netplan try

netplan try applies the config and automatically reverts after 120 seconds unless you press Enter — so a typo cannot permanently cut off a remote machine. Only when it works, confirm; netplan apply makes it permanent without the safety net.

Applying a static IP safely with netplan try and verifying connectivity

Step 4 — Verify

ip -br addr show eth0
ip route
resolvectl status | grep "DNS Servers"
ping -c 3 ubuntu.com

Cloud-init keeps overwriting my config

On cloud images, 50-cloud-init.yaml regenerates at every boot. Disable network management by cloud-init once:

echo 'network: {config: disabled}' | sudo tee \
  /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

DHCP with a reserved address: often the better answer

On a LAN, the cleanest setup is frequently a DHCP reservation on the router — the server keeps dhcp4: true and the router always hands it the same address. One place to manage all addressing, zero risk of conflicts.

Related Ubuntu guides

Prefer to have experts handle it?

LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.


Was this answer helpful?

« Back