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:

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: