Home UbuntuHow to Configure a Static IP Address on Ubuntu Server with Netplan

How to Configure a Static IP Address on Ubuntu Server with Netplan

by Knowledge Base Linux
How to Configure a Static IP — How to Configure a Static IP Address on Ubuntu Server with Netplan

A static IP on Ubuntu Server is essential whenever the machine provides a service other systems depend on: a file server, a hypervisor host, a monitoring box or an internal web application. With DHCP, the address can change after a lease renewal or a reboot, silently breaking port forwarding, firewall rules and bookmarks. Ubuntu Server does not use the old /etc/network/interfaces file anymore; since 18.04, networking is described by Netplan YAML files. This guide shows how to configure a static IP on Ubuntu with Netplan safely, including the rollback feature that saves you when you manage the server remotely.

Why Servers Need a Static IP on Ubuntu – How to Configure a Static IP

A static IP on Ubuntu gives the machine a permanent identity on your network. Your router’s port-forwarding rules keep pointing at the right host, DNS records stay valid, other servers can whitelist the address, and monitoring systems stop reporting the machine as “missing” after every DHCP renewal. The small trade-off is bookkeeping: you must pick an address outside the router’s DHCP pool and make sure no other device already uses it.

Prerequisites – How to Configure a Static IP

  • An Ubuntu Server 20.04, 22.04 or 24.04 with sudo access.
  • The address you want to assign, plus your network’s gateway and DNS servers.
  • Console or out-of-band access if possible, in case the network drops (Netplan’s rollback, covered below, largely removes this risk).

Step 1: Find Your Interface Name and Current Settings

List the network interfaces and note the name of the wired or wireless adapter, commonly ens33, enp3s0 or eth0:

ip -br link
ip -br addr

Also record the current gateway so you can reuse it in the static configuration:

ip route | grep default

Step 2: Locate and Back Up the Netplan File

Netplan configuration lives in /etc/netplan/, usually as 50-cloud-init.yaml on cloud images or 00-installer-config.yaml from the Ubuntu installer:

ls -l /etc/netplan/
sudo cp /etc/netplan/50-cloud-init.yaml /root/50-cloud-init.yaml.bak

On cloud instances, cloud-init can regenerate this file at boot. If that happens on your server, create /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled} so your manual file survives reboots.

Network map for a static IP on Ubuntu with Netplan

Step 3: Write the Static IP Configuration

Edit the YAML file with your values. YAML is whitespace-sensitive, so use spaces, never tabs, and keep the indentation exactly aligned:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      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

Replace the interface name, address, prefix and gateway with your own network’s values. Note the modern routes syntax: the older gateway4 key is deprecated in current Netplan versions and produces a warning on Ubuntu 24.04. On Ubuntu 24.04 the file also needs restrictive permissions:

sudo chmod 600 /etc/netplan/50-cloud-init.yaml

Step 4: Apply Safely with netplan try

Never apply blindly on a remote machine. netplan try applies the configuration but automatically reverts it after 120 seconds unless you press Enter to confirm, which is a lifesaver if the new settings cut your SSH connection:

sudo netplan try

Open a second SSH session to the new address and confirm everything works. Then return to the first terminal and press Enter to keep the change. Once confirmed, generate and apply the final configuration:

sudo netplan generate
sudo netplan apply

Step 5: Verify the Static IP on Ubuntu

ip -br addr show ens33
ip route
ping -c 3 192.168.1.1
ping -c 3 1.1.1.1
resolvectl status

You should see the new address on the interface, a default route through your gateway, successful pings and the DNS servers you configured. From another machine on the network, connect to a service on the server, for example a shared folder from our NFS on Ubuntu guide, to prove end-to-end reachability.

Finally, reboot the server once and repeat the address check after it comes back up. A configuration that only works until the next reboot is a common trap on cloud images, and the reboot test proves your static address, gateway and DNS settings are stored in the right file and survive a cold start.

Troubleshooting

“Permissions are too open” warning. Netplan on 24.04 warns when the YAML file is world-readable because it may later contain Wi-Fi passwords. Run the chmod 600 command from Step 3.

Configuration is ignored. Check for YAML syntax errors with sudo netplan apply and read its output carefully; a single misaligned line silently invalidates a section. Validate the file with python3 -c "import yaml,sys; yaml.safe_load(open('/etc/netplan/50-cloud-init.yaml'))".

The address works but DNS does not. The nameservers block must sit under the interface, at the same indentation level as addresses. Verify with resolvectl status and re-apply.

Lost connection after applying. If you skipped netplan try, use the server’s console, restore the backup file from Step 2 and run sudo netplan apply again.

Conclusion

Configuring a static IP on Ubuntu with Netplan takes five minutes once you know the file layout: find the interface, back up the YAML, declare the address, gateway and DNS, then apply with netplan try so a mistake cannot lock you out. Your server now has the stable address that the rest of your infrastructure can rely on. For every directive and renderer option, consult the official Netplan documentation.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.