What is Netplan in Ubuntu networking?
Netplan is the default network configuration utility in modern Ubuntu releases, serving as an abstraction layer that simplifies how administrators manage network interfaces. Instead of directly modifying traditional, complex configuration files, users write declarative network settings in YAML format. Netplan then processes these files and generates the necessary configurations for the underlying network rendering engines—either systemd-networkd for servers or NetworkManager for desktops. This approach provides a unified, efficient, and human-readable way to manage everything from basic IP assignments to complex bridging and bonding.
The Shift to Declarative Networking
Prior to Ubuntu 17.10, network configuration was primarily handled
through the /etc/network/interfaces file or via
desktop-specific GUI tools. This often led to fragmentation, especially
when moving configurations between headless server environments and
desktop setups.
Netplan resolved this fragmentation by introducing a centralized
directory located at /etc/netplan/. By utilizing YAML (Yet
Another Markup Language), Netplan allows administrators to define the
intended state of the network. You describe what the network
should look like, and Netplan handles the intricate details of
implementing that state.
How Netplan Works: Renderers
Netplan does not actually configure the network interfaces directly. Instead, it acts as a front-end compiler that translates YAML code into configuration files for one of two backend daemons, known as renderers:
- systemd-networkd: The default renderer for Ubuntu Server environments. It is lightweight, efficient, and ideal for cloud instances, containers, and data center deployments where a graphical user interface is absent.
- NetworkManager: The default renderer for Ubuntu Desktop. It excels at managing dynamic network environments, such as switching between Wi-Fi networks, handling VPN connections, and interacting with desktop GUI widgets.
By specifying the renderer key in the YAML file, you
dictate which system service will ultimately execute the network
commands.
Key Benefits of Using Netplan
1. Human-Readable Configuration
YAML’s clean, indentation-based structure makes network configurations easy to read, write, and audit. This reduces the syntax errors commonly associated with older, more esoteric configuration formats.
2. Safeguards Against Lockouts
One of Netplan’s most valuable features for remote administrators is
the netplan try command. When you apply a new configuration
using this command, Netplan applies the settings but requires a visual
confirmation from the user within a specific timeframe (usually 120
seconds). If the user does not confirm—perhaps because they lost SSH
access due to a misconfiguration—Netplan automatically rolls back to the
previous working state.
3. Consistency Across Deployments
Because Netplan abstracts the underlying renderer, the same YAML configuration structure can be used to configure a local physical server, a cloud instance on AWS, or a virtual machine. This uniformity is highly beneficial for automation tools like Ansible, Terraform, and cloud-init.
Basic Syntax Example
A typical Netplan configuration file specifies the network topology logically. Below is an example of a basic static IP configuration for a wired interface using the systemd-networkd renderer:
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: [8.8.8.8, 1.1.1.1]Essential Netplan Commands
To manage networking through Netplan, administrators primarily use three core commands:
sudo netplan generate: Converts the YAML files into the configuration formats required by the chosen renderer.sudo netplan apply: Generates the configurations and immediately applies them to the system running state.sudo netplan try: Applies the configuration with an automatic rollback safety net to prevent permanent loss of network connectivity.