How to Configure Netplan for Static IP Addressing on Ubuntu Server

In older versions of Ubuntu, network interfaces were configured by editing the /etc/network/interfaces file. Starting with Ubuntu 17.10, Canonical introduced Netplan as the default network management tool. Netplan uses YAML files to describe the network configuration, which it then translates into configurations for either NetworkManager (typically used on Desktop) or systemd-networkd (typically used on Server). Configuring a static IP address is one of the first and most critical tasks when provisioning a new server.

Step 1: Identify Your Network Interface

Before writing the configuration, you need to know the logical name of your network interface (e.g., eth0, ens33, enp0s3).

Run the following command to list all network interfaces:

ip link show

Identify the interface that connects to your local network (ignore the lo loopback interface).

Step 2: Locate the Netplan Configuration File

Netplan configuration files are stored in the /etc/netplan/ directory. They usually end in .yaml. To find the exact filename, run:

ls /etc/netplan/

The file might be named 00-installer-config.yaml, 01-netcfg.yaml, or something similar.

Step 3: Edit the YAML Configuration

Open the file using a text editor like nano (requires root privileges):

sudo nano /etc/netplan/00-installer-config.yaml

By default, if the server was installed using DHCP, the file will look something like this:

network:
  ethernets:
    ens33:
      dhcp4: true
  version: 2

Modify the file to disable DHCP and assign a static IP. Important: YAML relies strictly on indentation (spaces, not tabs). Ensure your spacing is correct.

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

In this example, we assigned the IP 192.168.1.50 with a subnet mask of /24 (255.255.255.0). The gateway is 192.168.1.1, and we specified Google and Cloudflare DNS servers.

Step 4: Apply the Configuration

Before applying the changes, you can test the configuration to ensure there are no syntax errors:

sudo netplan try

If the configuration is valid, Netplan will apply it temporarily and ask for confirmation. If you lose connection, it will automatically revert after 120 seconds. If you are confident the configuration is correct, you can apply it permanently:

sudo netplan apply

Your Ubuntu server is now securely configured with a static IP address, ready to host reliable services on your network.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.