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.
Netplan configurations are stored in .yaml files within /etc/netplan/. Common filenames include 01-netcfg.yaml or 50-cloud-init.yaml.
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
| 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). |
This command automatically rolls back if you don't confirm within 120 seconds.
sudo netplan try
sudo netplan apply
ip addr show ens1