Modern Ubuntu installations utilize Netplan as the default declarative network configuration abstraction layer. Instead of directly editing legacy Debian /etc/network/interfaces or scattering configurations across conflicting daemon directories, Netplan uses structured YAML files stored in /etc/netplan/. At boot or execution time, Netplan generates the requisite backend configuration files for either systemd-networkd (standard for headless servers, cloud instances, and virtualization hosts) or NetworkManager (the default for desktop workstations and mobile Wi-Fi setups).
Understanding Netplan Configuration Architecture
Netplan functions strictly as a parser and generator, never maintaining persistent socket listeners or network links itself. When you run Netplan commands, it reads YAML files in alphabetical order from three standard paths:
/run/netplan/*.yaml: Ephemeral configurations generated by cloud-init or DHCP leases./etc/netplan/*.yaml: Persistent administrator-defined configurations (primary editing location)./lib/netplan/*.yaml: Distribution-level defaults.
Files discovered in /etc/netplan/ take precedence over lower tiers, and settings defined in later alphabetical files override matching keys in earlier files.
Configuring Static IP Addressing for systemd-networkd
On Ubuntu Server environments, systemd-networkd provides a lightweight, deterministic backend without GUI overhead. To assign a static IP address, gateway, and DNS servers to an Ethernet interface (e.g., eth0 or enp3s0):
- Open or create a custom configuration file:
sudo nano /etc/netplan/01-netcfg.yaml - Insert the following structured YAML definition (ensure strict 2-space indentation without tabs):
network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: no addresses: - 192.168.1.150/24 routes: - to: default via: 192.168.1.1 nameservers: addresses: - 1.1.1.1 - 8.8.8.8 search: - lan.local
Configuring Desktop Interfaces for NetworkManager
On Ubuntu Desktop machines, delegating interface management to NetworkManager allows system tray applets and user VPN profiles to interact seamlessly with hardware:
network:
version: 2
renderer: NetworkManager
When the renderer is set to NetworkManager, Netplan hands off link monitoring, Wi-Fi authentication (WPA-Personal/Enterprise), and roaming to the NetworkManager daemon while maintaining declarative baseline profiles.
Testing and Applying Netplan Configurations Safely
Applying an erroneous network configuration on remote servers over SSH can instantly sever your connection. Netplan provides an essential safeguard command called netplan try:
- Test your YAML file with automated rollback protection:
sudo netplan try - Netplan parses the YAML syntax, generates temporary renderer configurations, and applies them while initiating a 120-second countdown timer.
- If the new configuration successfully maintains your network session, press Enter to confirm and lock in the changes. If your connection drops or no key is pressed within two minutes, Netplan automatically reverts to the previous working configuration.
- To forcefully generate backend files and apply changes immediately on local consoles:
sudo netplan generate sudo netplan apply - Verify active IP addressing and link state:
ip addr show enp3s0 networkctl status enp3s0