Static IP using Netplan

How to setup static IP using netplan on ubuntu 22.04 and above

Setting a static IP address on Ubuntu 22.04 and higher using netplan

Netplan basically acts as a translation layer, it takes configuration files, and creates the right systemd-networkd or Networkmanager configuration.

First disable the cloud-init networking.

Create a file, sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following contents:

network: {config: disabled}

Then, edit the existing netplan configuration file, for me this was sudo nano /etc/netplan/50-cloud-init.yaml, which originally looked like this:

network:
    ethernets:
        enp1s0:
            dhcp4: true
    version: 2
    wifis: {}

What it’s basically doing is setting the network interface enp1s0 to use DHCP (and is not static).

Change it to make it look like this:

network:
    ethernets:
        enp1s0:
            dhcp4: false
            dhcp6: false
            addresses:
              - 192.168.50.111/24
            routes:
              - to: default
                via: 192.168.50.1
            nameservers:
                addresses: [1.1.1.1, 8.8.8.8]
    version: 2
    wifis: {}

  • dhcp4: false and dhcp6: false are disabling DHCP for both IPv4 and IPv6.

  • addresses is setting the static IP address.

  • routes is setting the default gateway and pointing at my router, 192.168.50.1

  • nameservers is setting the DNS servers to use, I’ve chosen one Cloudflare and one Google DNS.

Apply changes using:

sudo netplan apply

Check status using:

sudo netplan status enp1s0

Last updated