Netplan on Ubuntu Server: Static IPs Without Fighting the YAML
The abstraction layer between you and systemd-networkd, and the indentation rules that decide whether it works

Contents
Netplan has a reputation for being the thing that stands between you and a static IP on Ubuntu Server, and the reputation is mostly earned by YAML’s own quirks rather than anything Netplan does wrong. I’ve set static addresses on more Ubuntu boxes than I can count at this point, and the failures are almost never conceptual — they’re a two-space indent where Netplan wanted four, a tab character an editor silently inserted, or a dhcp4: no sitting under the wrong key. Once you know what Netplan actually is and how it renders, the YAML stops being scary and becomes just another config format with a couple of sharp edges to remember.
What Netplan actually is
Netplan is a configuration renderer: you write a small YAML description of how you want interfaces configured, and Netplan translates that into config files for a backend that does the actual work, either systemd-networkd or NetworkManager. On Ubuntu Server the default backend is systemd-networkd (see the comparison piece on why that’s usually the right choice for a headless box); on Ubuntu Desktop it’s NetworkManager, because desktops need the roaming and VPN-toggle behaviour that NetworkManager is built for. That split is the source of a lot of confusion online — advice written for a desktop install often doesn’t apply cleanly to a server, because it’s targeting a different backend under the same YAML syntax.
The YAML files live in /etc/netplan/, usually as a single 00-installer-config.yaml left by the Ubuntu installer or a numbered file you add yourself. netplan apply reads every .yaml file in that directory, merges them, generates the backend-specific config, and applies it live — no reboot required, which is both convenient and occasionally the reason a bad change locks you out of a remote box before you’ve had a chance to undo it.

It’s worth being explicit about the renderer even when it matches the distro default, because a config file copied from a desktop guide often carries renderer: NetworkManager at the top without saying so out loud, and that one line silently changes which backend Netplan targets on generate. Setting renderer: networkd explicitly in every server file, even redundantly, means a copy-pasted snippet can’t quietly swap your backend out from under you.
A working static-IP config
| |
Two things trip people up in exactly this file. First, indentation is semantically meaningful in YAML and Netplan expects two spaces per level, consistently — mixing tabs and spaces, or using three spaces at one level and two at another, produces a parse error that often points at the wrong line, sending you hunting through the file for a typo that isn’t where the error says it is. Second, the older single-line gateway4: 192.168.1.1 key still works on some Netplan versions but is deprecated in favour of the routes block above; mixing the two styles in the same file, or copying an old gateway4 example into a newer install, is a common source of “it parses fine but the route never appears” bugs.
Validate before applying, always:
| |
netplan try is the single most useful safety net in the whole tool. It applies your change, waits for you to press Enter to confirm it’s still reachable, and reverts automatically if you don’t respond in time — built specifically for the “I just netplan applied a change over SSH and now I can’t get back in” scenario. Use it every time you’re changing a remote box’s addressing, no exceptions.
Bonds and VLANs
Netplan’s YAML gets genuinely nicer than hand-writing the equivalent systemd-networkd files once you’re dealing with bonds or VLANs, because it expresses the relationship in one place instead of three separate files:
| |
That’s a bonded pair of NICs with a tagged VLAN interface riding on top, in about fifteen lines. The equivalent hand-written systemd-networkd .netdev/.network files run to four or five separate files — Netplan is doing real work collapsing that into one readable document, which is the strongest case for using it even on a server where you’re otherwise happy hand-editing systemd-networkd directly.
Multiple files and merge order
Netplan merges every .yaml file in /etc/netplan/ alphabetically, and later files can override keys set by earlier ones for the same interface. This is genuinely useful — a base 00-installer-config.yaml from the Ubuntu installer plus a 01-lan.yaml you add yourself for the actual static config — but it’s also a common source of “why is my config being ignored” bugs when two files both claim the same interface with conflicting settings. netplan generate will happily merge conflicting keys without warning you which file won; if in doubt, cat every file in the directory before assuming there’s only one source of truth.
| |
I’ve had a leftover cloud-init-generated file in /etc/netplan/50-cloud-init.yaml silently override a manually written 01-lan.yaml on a VM template, because cloud-init’s default network config runs dhcp4: yes and sorts after my file alphabetically. Renaming my file to sort after cloud-init’s (or disabling cloud-init’s network config generation entirely, which is the more permanent fix — see the piece on configuring a fresh VM with cloud-init for the right way to do that) both work; the point is to check what else is in the directory before assuming your file is the only thing Netplan is reading.
Wi-Fi, DHCP reservations and other renderer quirks
Servers are usually wired, but Netplan handles Wi-Fi the same declarative way if a box needs it — a Raspberry Pi tucked somewhere without an Ethernet run, say:
| |
The catch is that Wi-Fi under the networkd renderer requires wpa_supplicant installed and running, which Ubuntu Server images don’t always ship by default — netplan apply will accept the config without complaint and then simply never associate, because the piece that actually speaks to the radio isn’t present. systemctl status systemd-networkd-wait-online.service and checking for wpa_supplicant in ps aux is the fastest way to confirm that’s the failure before assuming the YAML itself is wrong.
For DHCP rather than static addressing, but still wanting a predictable address, the better pattern is usually a reservation on the DHCP server tied to the interface’s MAC address (see the piece on Kea DHCP for how that works) rather than fighting Netplan’s YAML for something DHCP already does well. Reserve it once at the server and every device that boots with that MAC gets the same address indefinitely, without a local static-IP file to keep in sync if the box is ever reimaged.
Backing up and versioning your config
Because /etc/netplan/*.yaml is plain text and small, it’s one of the easiest things in a homelab to keep in version control — a private git repo with one directory per host, each holding that host’s Netplan files, gives you a diff-able history of every addressing change and a fast recovery path if a host needs reimaging. I keep mine alongside the rest of my Ansible inventory rather than as a separate thing to remember, so a fresh install is one playbook run away from having its real network config back rather than a rebuild-from-memory exercise.
| |
It’s a small habit that pays for itself the first time a netplan apply locks you out and you need to know exactly what the file looked like before the change, rather than reconstructing it from memory over a console session.
Netplan on cloud images and VM templates
Cloud-provisioned Ubuntu images add a wrinkle worth knowing about before it costs you a debugging session: cloud-init generates its own Netplan file, usually /etc/netplan/50-cloud-init.yaml, on every boot where cloud-init’s networking stage runs, and it will happily overwrite a hand-edited file at that exact path if you’ve reused the name. The safe pattern is to never edit 50-cloud-init.yaml directly — treat it as generated, disposable output — and instead add your own static config in a separate file that sorts after it, or disable cloud-init’s network configuration stage entirely on a template where you always want manual control:
| |
That one file stops cloud-init from touching Netplan at all on subsequent boots, leaving your own 01-lan.yaml as the sole source of truth. It’s the cleaner fix for a VM template you’ll clone repeatedly, versus fighting the alphabetical sort order every time a fresh clone regenerates the cloud-init file and clobbers a same-named override.
Comparing to a hand-written systemd-networkd file
It’s worth seeing the two side by side once, because the gap in verbosity is a big part of why Netplan earns its keep. The static-IP example from earlier, as a raw systemd-networkd .network file instead of Netplan YAML:
| |
Comparable length for a single flat interface — Netplan’s advantage shows up once bonds, VLANs or multiple interfaces enter the picture, where the raw systemd-networkd approach needs a proliferating set of separate .netdev/.network files and Netplan collapses the same relationships into one YAML document. For a single static interface, either approach is fine; the choice mostly comes down to whether you’re also managing Wi-Fi or want the one-command netplan try safety net, in which case Netplan wins outright.
Troubleshooting
“Invalid YAML” with a line number that looks wrong. Netplan’s YAML parser reports the line where it noticed the problem, which because of how YAML parsing works is often a few lines after the actual mistake — a missing colon or wrong indent on line 12 might get reported as an error on line 15. Read a few lines above the reported number, especially around list items (-) and nested maps.
netplan apply succeeds but the address never appears. Check which renderer actually owns the interface with networkctl status eth0 (for the networkd backend) or nmcli device show eth0 (for the NetworkManager backend). A stray renderer: NetworkManager line at the top of a different .yaml file in the directory silently changes the backend for interfaces it covers, and mixed renderers across files in the same directory produce genuinely confusing partial states.
A dhcp4: no interface still gets a DHCP address. This almost always means a second Netplan file, or a systemd-networkd .network file outside Netplan’s management entirely, also matches the interface and wins the race. networkctl list shows which .network file (Netplan-generated or otherwise) actually matched, which narrows it down fast.
Permissions error on /etc/netplan/*.yaml. Netplan refuses to apply a config file that’s world-readable if it contains no secrets flag issue, but more commonly the actual failure is the reverse — a file with mode 600 owned by a non-root user that netplan apply (running as root) can technically still read but that a netplan generate run by a less privileged tool cannot. Keep Netplan files at the default 600 root:root and don’t second-guess it; Netplan set that permission deliberately because these files can contain Wi-Fi passphrases.
Two more habits worth adopting alongside the backup itself. Comment every non-obvious line — a routes block with a metric override, or a VLAN ID chosen for a reason that made sense six months ago, is exactly the kind of thing you’ll forget by the time you’re touching the file again. And keep one canonical “known good” copy outside /etc/netplan/ entirely, timestamped, so a bad netplan apply has a fast known-working file to restore from /root/netplan-backup-* rather than reconstructing the addressing scheme from a half-remembered subnet plan at 1am.
The verdict
Netplan earns its place even on a server where you’re comfortable with raw systemd-networkd files, purely on the strength of collapsing bonds and VLANs into one readable document and giving you netplan try as a safety net for remote changes. The YAML frustration people report is almost always an indentation or merge-order issue rather than a real limitation of the tool — read every file in /etc/netplan/ before debugging a single one, validate with netplan generate before applying, and use netplan try on anything remote. Do those three things and the format stops being the enemy.




