This guide shows Ubuntu server admins how to configure networking with Netplan, the tool Ubuntu uses to manage network settings. You write YAML files in /etc/netplan/, and Netplan turns them into settings for the backend that does the work: systemd-networkd on servers, or NetworkManager on desktops. Three things cause most of the frustration. The gateway4: key that most tutorials have used since 2018 is deprecated, so Netplan now prints a warning each time it reads it. Indentation mistakes are rejected with error messages that point at the wrong line. And running netplan apply with a bad config on a remote server can drop your SSH session with no way back in. This guide covers static IPv4 and IPv6 addresses with proper routes: entries, plus DNS through systemd-resolved, Ubuntu’s built-in name-resolution service. It also covers 802.1Q VLANs (tagged virtual networks that share one physical link) on an LACP bond, which combines several network ports into one faster, redundant link. Finally, you will use the netplan try rollback timer, so a mistake costs you 120 seconds instead of a trip to the datacentre.
What you’ll accomplish
- Replace DHCP or a half-migrated config with one readable Netplan file that owns the whole host network.
- Assign static IPv4 and IPv6 addresses with a default route written the modern way:
routes:withto: default. - Bond two physical NICs into an LACP aggregate and carry two tagged VLANs over it.
- Set per-link DNS servers and a search domain that systemd-resolved actually honours.
- Apply every change with an automatic rollback in place, and know the recovery path for when it still goes wrong.
Prerequisites
- Ubuntu 18.04 or newer. This is written against Netplan 0.106 and later, which ships from Ubuntu 22.04 onward;
netplan statusdoes not exist on older releases. Check withdpkg -s netplan.io. rootorsudo, and — this matters more than anything else here — a way back in that does not use the network you are about to change: serial console, hypervisor console, IPMI or iDRAC, or a cloud provider’s web console.- Two physical NICs on the same switch for the bond section, plus a switch-side port-channel with LACP enabled and the VLANs trunked to those ports. Linux cannot compensate for an unconfigured switch.
- Honest version differences. Ubuntu Server defaults to the
networkdrenderer; Desktop toNetworkManager.gateway4:andgateway6:have been deprecated since Netplan 0.103, still warn on current releases, and are being removed — do not write new configs with them. On cloud images,cloud-initrewrites/etc/netplan/50-cloud-init.yaml, covered in step 8.
How it works
Netplan is not a network manager. It is a translator that runs once, reads every *.yaml in /etc/netplan/ in lexical filename order, merges them into one model, and writes native configuration for the backend named by renderer:. For networkd that means .network, .netdev and .link files under /run/systemd/network/; for NetworkManager, .nmconnection files under /run/NetworkManager/system-connections/. Both paths live on tmpfs and are regenerated from scratch on every run, so hand-editing them is pointless.
Merging is per key, not per file. A 99-static.yaml defining dhcp4: false on enp3s0f0 overrides that key in 50-cloud-init.yaml but leaves every other key in that file intact — which is how people end up with an interface holding both a static address and a DHCP lease. netplan get all prints the merged result.
The three commands map onto three levels of risk. netplan generate validates the YAML and writes backend files, changing nothing on the running system. netplan apply does that and reloads the backend, taking changes live with no safety net. netplan try applies the config, prints a prompt, and if you do not press Enter within 120 seconds it restores the previous /etc/netplan contents and re-applies them. On a remote host, netplan try is the command; netplan apply is for when you are at a console.
Bonds and VLANs stack. The physical NICs get no addresses and exist only to be enslaved. The bond aggregates them and, in 802.3ad mode, negotiates LACP with the switch. The VLAN interfaces hang off the bond, each tagged with its 802.1Q ID, and carry the addresses, routes and DNS.
Step-by-step
-
Record the current state. You will want it if something goes sideways, and interface names are not guessable.
ip -br link show ip -br address show ip route showExpected: one line per interface —
enp3s0f0 DOWN a0:36:9f:1a:2b:3c <BROADCAST,MULTICAST>. Note the exact predictable names; a typo here produces a config that validates cleanly and does nothing.ip route showshould contain adefault via ...line. Copy all of it to your laptop, not the server. -
Back up the config and arm a dead-man rollback.
netplan tryis the primary safety net, but it does not protect against a config that stays reachable for 20 seconds and then falls over. A scheduled restore does.sudo cp -a /etc/netplan /root/netplan-backup sudo systemd-run --on-active=15min --unit=netplan-rollback \ /bin/sh -c 'cp -a /root/netplan-backup/. /etc/netplan/ && netplan apply'Expected:
systemd-runprintsRunning timer as unit: netplan-rollback.timerandWill run service as unit: netplan-rollback.service. You now have 15 minutes; lose the session and the box restores its old networking on its own. Step 7 cancels it. -
Clear the ground. Move old config aside so exactly one file defines this host’s network. Keeping
50-cloud-init.yamlnext to a hand-written file is the most common source of “my static address keeps picking up a DHCP lease”.sudo mv /etc/netplan/50-cloud-init.yaml /root/netplan-backup/ ls -l /etc/netplan/Expected:
lsshows an empty directory, or only files you deliberately kept. Move00-installer-config.yamlfrom the Ubuntu installer too, if it is there. -
Write the config. One file, mode
0600, a name that sorts last so nothing overrides it. Note the two-space indentation, the absence of tabs, andto: defaultin place ofgateway4:.sudo tee /etc/netplan/99-corp-net.yaml >/dev/null <<'EOF' network: version: 2 renderer: networkd ethernets: # physical ports carry no addresses; they only feed the bond enp3s0f0: dhcp4: false dhcp6: false enp3s0f1: dhcp4: false dhcp6: false bonds: bond0: interfaces: [enp3s0f0, enp3s0f1] parameters: mode: 802.3ad lacp-rate: fast mii-monitor-interval: 100 transmit-hash-policy: layer3+4 vlans: vlan100: id: 100 link: bond0 # static v6 means router advertisements must not also configure us accept-ra: false addresses: - 10.20.100.11/24 - 2001:db8:100::11/64 routes: - to: default via: 10.20.100.1 - to: default via: 2001:db8:100::1 nameservers: addresses: [10.20.100.53, 2001:db8:100::53] search: [corp.example.com] vlan200: id: 200 link: bond0 # storage VLAN: no gateway, and the boot must not wait for it optional: true addresses: - 10.20.200.11/24 EOF sudo chmod 600 /etc/netplan/99-corp-net.yamlExpected: both commands return silently, and
ls -lshows-rw-------. Skip thechmodand current releases printPermissions for /etc/netplan/99-corp-net.yaml are too open.on every invocation.Two keys deserve a note.
optional: truestopssystemd-networkd-wait-onlineblocking boot on that interface — without it a disconnected storage NIC adds two minutes to every reboot. And if your gateway sits outside your own subnet, as some hosting providers arrange deliberately, addon-link: trueto that route entry. -
Validate the YAML without touching the network. This is free and catches most mistakes.
sudo netplan generateExpected: complete silence and exit status 0. Anything else must be fixed first — a message like
Error in network definition //etc/netplan/99-corp-net.yaml line 14 column 8: expected mappingmeans indentation, and the reported line is where the parser gave up, often past the real mistake. Then confirm what Netplan built:ls /run/systemd/network/ netplan get allExpected:
lsshows a10-netplan-<device>.networkfile per device plus a.netdevfor each virtual one —10-netplan-bond0.netdev,10-netplan-vlan100.netdevand so on.netplan get allprints the merged model; read it and check no stray keys survived from a file you thought you had removed. -
Apply it with the rollback timer. Never
netplan applya change like this over SSH.sudo netplan try --timeout 120Expected: the config goes live and you get
Do you want to keep these settings?, thenPress ENTER before the timeout to accept the new configurationandChanges will revert in 120 seconds. Open a second SSH session to the new address before pressing anything. If it connects, press Enter in the first one and you getConfiguration accepted.If it does not, do nothing — the countdown expires and the old config is restored and re-applied. -
Disarm the dead-man switch, once a fresh connection is confirmed working.
sudo systemctl stop netplan-rollback.timer systemctl list-timers netplan-rollback.timerExpected: the second command prints a header and
0 timers listed.Forget this and your config silently reverts mid-afternoon. -
Stop cloud-init from rewriting your work. On any cloud or MAAS-provisioned image, cloud-init regenerates
/etc/netplan/50-cloud-init.yamlon boot. You deleted the file; cloud-init will put it back.echo 'network: {config: disabled}' | \ sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfgExpected: the file is echoed back. On bare metal there is no cloud-init and this is a no-op — check with
command -v cloud-init, which prints nothing if absent. -
Reboot and confirm it survives. A config that works after
netplan trybut not after a reboot will fail at the worst moment.sudo rebootOnce it is back, run the verification below. If it does not come back, that is what the console is for.
Validate it works
Start with addressing and routes, both families:
ip -br address show
ip route show
ip -6 route show
Expected: bond0 shows UP with no address, vlan100@bond0 shows UP 10.20.100.11/24 2001:db8:100::11/64, vlan200@bond0 its storage address. ip route show contains default via 10.20.100.1 dev vlan100 proto static, and ip -6 route show contains default via 2001:db8:100::1 dev vlan100 proto static metric 1024 pref medium. A missing default line means the routes: block is indented under the wrong device.
Confirm the bond negotiated LACP rather than quietly running on one link:
cat /proc/net/bonding/bond0
Expected, abridged:
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer3+4 (1)
MII Status: up
802.3ad info
LACP active: on
LACP rate: fast
Active Aggregator Info:
Number of ports: 2
Partner Mac Address: 00:23:04:ee:be:64
Number of ports: 2 and a non-zero Partner Mac Address prove the switch is talking LACP back to you. Number of ports: 1, or a partner address of 00:00:00:00:00:00, means the switch side is not configured and you are running on a single link.
Check the VLAN tagging is real, not just a naming convention:
ip -d link show vlan100
Expected: the output contains vlan protocol 802.1Q id 100 <REORDER_HDR>. If id is wrong, traffic leaves the host tagged for a VLAN the switch is not trunking, and simply disappears.
Verify DNS is bound to the link, not just written into a file:
resolvectl status vlan100
resolvectl query db.corp.example.com
Expected: Current Scopes: DNS, +DefaultRoute in the protocol line, DNS Servers: 10.20.100.53 2001:db8:100::53 and DNS Domain: corp.example.com. The query should resolve and report -- Information acquired via protocol DNS. A stub resolver that is not wired up correctly is its own topic — see our systemd-resolved configuration guide.
Finally, Netplan’s own summary, on 22.04 and newer:
netplan status --all
Expected: Online state: online, the DNS addresses and search domain at the top, then a block per interface — bond0 bond UP (networkd: bond0), vlan100 vlan UP (networkd: vlan100) with its addresses. Anything marked (unmanaged) that you expected Netplan to own never made it into the YAML.
Troubleshooting
-
The YAML is rejected and the line number is useless. Netplan reports where the parser failed, not where you erred, so an error at line 22 is frequently an indentation slip at line 19. Three causes cover nearly all of it: a literal tab anywhere in the file (YAML forbids them — find them with
grep -Pn '\t' /etc/netplan/*.yaml), a list written without the leading-, and a key indented one level off so it attaches to the parent instead of the device. -
gateway4produces a warning and no default route. A config copied from an older tutorial gives youWARNING:root:gateway4 has been deprecated, use default routes instead.and, on current releases, no default route. Replace the key with aroutes:list containing- to: defaultandvia:set to your gateway. Same forgateway6:. There is no compatibility shim worth relying on. -
You applied a bad config and lost the session. This is why step 2 exists, but if you are here without it: get on the console — hypervisor, IPMI, serial or cloud web console — log in locally and restore.
sudo mv /etc/netplan/99-corp-net.yaml /root/thensudo netplan applyputs you back on whatever the remaining files describe. If/etc/netplan/is now empty, the fastest route to a reachable shell is a temporary DHCP config:sudo netplan set ethernets.enp3s0f0.dhcp4=truethensudo netplan apply, which writes a valid file and brings the interface up. If the console is unavailable too, boot the recovery kernel from GRUB, pickroot, runmount -o remount,rw /, and fix the file there. -
The bond comes up but throughput is stuck at one link’s worth. Almost always the switch, not Linux.
Number of ports: 1in/proc/net/bonding/bond0means only one member joined the aggregator; a partner MAC of all zeros means no LACP frames are coming back. Get the port-channel configured for both ports. Once LACP is up, remember thattransmit-hash-policydistributes flows, not packets — a single TCP stream never exceeds one member link’s bandwidth, so test with parallel connections. -
DNS settings are ignored. Two causes. Either
nameservers:sits on a device with no default route — systemd-resolved only promotes a link’s DNS servers to global use when that link owns the default route, which is why the block belongs onvlan100— or/etc/resolv.confis a real file rather than a symlink to/run/systemd/resolve/stub-resolv.conf. Check withls -l /etc/resolv.confand restore the symlink if another tool replaced it.
When this is the wrong approach
Netplan owns the host’s static topology and is the wrong tool for anything that changes at runtime. On a laptop that roams between networks, use NetworkManager directly; putting Netplan in front makes nmcli results confusing for no gain. Inside a container, networking belongs to the runtime. On Kubernetes nodes the CNI plugin owns pod networking — Netplan configures the node’s uplinks and stops there.
It is also the wrong layer for dynamic routing. Netplan handles static routes and, through routing-policy:, source-based policy routing, but BGP or OSPF calls for FRRouting on top of a Netplan-configured interface. Provider images that expect DHCP plus metadata-driven configuration are best left alone; fighting cloud-init on an autoscaled instance creates failures that only appear when the instance is replaced.
One more boundary: a new VLAN interface is new attack surface, and Netplan has no opinion about filtering. See UFW firewall basics for the per-interface rules that belong alongside this config.
The authoritative references are the Netplan documentation, which carries the full YAML schema for every device type, and the Ubuntu Server documentation.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.