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.
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 apply02What 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
!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 apply05Sources
- netplan reference — Ubuntu DiscourseEvidence: Canonical reference for netplan configuration files, static addressing, and applying changes to the renderer.
- netplan.yaml reference — Static addressingEvidence: Documents the YAML schema including dhcp4: false and addresses with CIDR notation for configuring a static IP.
Last verified: 2026-09-18 · Category: Network