Applies to: Ubuntu 24.04 LTS servers (netplan.io 1.1.2)

Ubuntu configures its network with Netplan: YAML files in /etc/netplan/ that Netplan turns into settings for systemd-networkd (on servers) or NetworkManager (on desktops). We checked every example below with netplan generate on Ubuntu 24.04.

Before you start on a remote server: a mistake can cut your connection. Keep console access ready (the VNC console in your VPS panel, or IPMI on a dedicated server) and use netplan try.

1. Look at the current settings

ip -br addr                # interface names and addresses
ip route                   # current gateway
ls -l /etc/netplan/
sudo netplan get           # the merged configuration

2. Write the configuration

Create /etc/netplan/60-static.yaml (replace eth0, the addresses and the gateway with yours):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 203.0.113.10/24
      routes:
        - to: default
          via: 203.0.113.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]

Indent with spaces only, never tabs. For IPv6, add the address to the same list (- 2001:db8:1::10/64) and a second route with to: default and your IPv6 gateway; we confirmed that Netplan creates both default routes.

3. Set the permissions

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

Otherwise Netplan warns: Permissions for /etc/netplan/60-static.yaml are too open. Netplan configuration should NOT be accessible by others.

4. Test, then apply

sudo netplan generate      # checks the syntax, no changes to the network
sudo netplan try           # applies, and rolls back after 120 seconds unless you press Enter
sudo netplan apply         # applies permanently

Messages you may see

  • `gateway4` has been deprecated, use default routes instead. Replace gateway4: 203.0.113.1 with the routes: block shown above.
  • Invalid YAML: inconsistent indentation, with the file, line and column: fix the spaces on that line.

Files from cloud-init

Many VPS images have /etc/netplan/50-cloud-init.yaml, written by cloud-init. Netplan reads all files in alphabetical order, and later files override the same settings in earlier ones. To stop cloud-init from rewriting the network configuration at boot:

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

Then either edit 50-cloud-init.yaml or keep your settings in your own file, and remove conflicting settings from the other file.

Check the result

ip -br addr
ip route
resolvectl status | grep -A2 "DNS Servers"
ping -c 3 1.1.1.1

More IP addresses on one interface: add IPv4 addresses with netplan. Working out masks and prefixes: subnet mask cheat sheet. VLANs and bonding: VLAN tagging and network bonding.

Official documentation: Netplan documentation.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $131.99 a month.

Was this answer helpful?

Still stuck? Open a ticket