Set a Static IP on Ubuntu with netplan

Configure a fixed IP address, gateway, and DNS for an Ubuntu server by editing a netplan YAML file and applying it.

LinuxconfigurationnetplanubuntunicMedium risk
Edit /etc/netplan/01-static.yaml with your addresses, routes, and nameservers, then run sudo netplan apply.

01Command

Command
$ sudo nano /etc/netplan/01-static.yaml && sudo netplan apply

02What it does

Ubuntu Server configures the network through netplan YAML files in /etc/netplan/. Add an entry for your interface (find its name with ip link) with dhcp4: false, your chosen address in CIDR form such as 192.168.1.50/24, the gateway under routes, and DNS servers under nameservers. Running sudo netplan apply re-renders the configuration immediately. Keep indentation exactly two spaces per level — YAML is whitespace-sensitive and a wrong indent makes netplan fail with a parse error.

03Risk

RiskMedium risk
Requirementsnetplan (default on Ubuntu Server 18.04+); know your interface name from ip link
!Warning: A typo in the YAML or a wrong gateway can take the network down entirely — on a remote server keep a console (or another SSH session) open while you test, and make a backup copy of the original file first.

04Undo

Undo
$ Remove the YAML block you added (or restore /etc/netplan backup) and run sudo netplan apply

05Sources

Last verified: 2026-09-18 · Category: Network