Preventing Remote Lockouts: Mastering Netplan Configuration in Ubuntu Server
Avoid remote lockouts on Ubuntu Server by using Netplan's 'try' mechanism. Learn how to safely implement static IPs and understand the abstraction between YAML and systemd-networkd.
11 Jun 2026, 05:58 UTC

The Danger of the 'Apply' Command
Updating network settings on a remote Ubuntu server via SSH is a high-risk operation. A single typo in a YAML file or an incorrect gateway address can instantly sever your connection, leaving you with no way to access the machine without physical or console access. The problem isn't just the mistake, but the immediacy of netplan apply, which pushes changes to the system renderer without a safety net.
The solution is a declarative workflow using netplan try. Instead of forcing a configuration, this command implements a timed rollback mechanism that protects your remote access.
How Netplan Abstraction Works
Netplan is not a network manager itself; it is an abstraction layer. You define your desired state in YAML files located in /etc/netplan/, and Netplan translates those instructions for a "renderer." On Ubuntu Server, the default renderer is typically systemd-networkd, while Ubuntu Desktop uses NetworkManager.
Because Netplan manages the renderer, you must avoid editing the backend configuration files directly (such as those in /run/systemd/network/). Any manual changes to the renderer are overwritten the moment Netplan generates a new configuration.
Implementing a Static IP with Safety Checks
To configure a static IP, you need to modify the YAML file in /etc/netplan/. Since YAML is whitespace-sensitive, use spaces—never tabs—for indentation.
Example Configuration
Below is a standard configuration for a server with a single Ethernet interface (e.g., enp0s3) using systemd-networkd.
# /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Applying the Changes Safely
To apply this without risking a lockout, run the following command as a user with sudo privileges on the server terminal:
sudo netplan try
What happens next: Netplan applies the configuration and starts a countdown (usually 120 seconds). If you lose your SSH connection due to a configuration error, you simply wait. Once the timer expires, Netplan automatically rolls back to the previous working configuration, restoring your access.
If the connection remains stable and you verify the settings, press Enter to accept the changes permanently.
Verification and Diagnostics
After accepting a configuration, you should verify that the renderer has correctly implemented the settings. You can check the status of the backend service with:
systemctl status systemd-networkd
To confirm the IP address is active on the interface, use the ip addr command. Look for the inet line under the specific interface name (e.g., enp0s3) to ensure it matches your YAML definition.
Limitations and Trade-offs
While netplan try is a powerful safety tool, it has limitations. It cannot protect you if the underlying hardware interface name changes (e.g., after a kernel update or hardware swap) or if the network switch port is disabled. Additionally, because Netplan relies on YAML, a single indentation error will cause the entire configuration to fail validation before it is even applied, which can be frustrating to debug without a strict text editor.
Actionable Summary
- Never use
netplan applyon a remote server unless you have an out-of-band management console (like IPMI or VNC). - Always use
netplan tryto ensure an automatic rollback on connectivity loss. - Verify your interface names using
ip linkbefore writing your YAML file to avoid referencing non-existent hardware.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.