← Back to Dashboard

Configuring a Static IP with Netplan

This document outlines how to configure a static IPv4 address for a network interface using Netplan. This is standard for modern Linux distributions (Ubuntu 18.04+) using the systemd-networkd renderer.

1. The Configuration File

Netplan configurations are stored in .yaml files within /etc/netplan/. Common filenames include 01-netcfg.yaml or 50-cloud-init.yaml.

2. Standard Configuration Template

Note that in modern Netplan, gateway4 is deprecated in favor of the explicit routes block.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens1:
      dhcp4: false
      addresses:
        - 10.11.17.5/24
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
      routes:
        - to: default
          via: 10.11.17.1

3. Key Parameters Explained

Parameter Description
ens1 Interface name. Use ip link to verify.
dhcp4: false Disables automatic IP assignment.
addresses Static IP in CIDR notation (e.g., /24).
routes Defines the default gateway (via) for external traffic.
nameservers Specifies DNS servers (e.g., Google Public DNS).

4. Applying the Changes

Step A: Test the configuration

This command automatically rolls back if you don't confirm within 120 seconds.

sudo netplan try

Step B: Apply the configuration

sudo netplan apply

Step C: Verify the status

ip addr show ens1
Important Note on YAML Formatting:
Netplan is extremely sensitive to indentation. Always use spaces, never tabs. Ensure each level is indented by exactly two spaces.