Netplan in Ubuntu: Modern Network Management Made Simple

Setting up a server often involves getting the network identity right. You might find yourself in a scenario where you have manually set a temporary IP using a legacy command, only to realize the configuration vanished after a simple reboot. Or perhaps you are managing a fleet of cloud instances and need a consistent way to apply DNS settings or bridge interfaces without learning the specific quirks of different background daemons.

These common frustrations are exactly why Netplan was introduced. As the default network configuration utility for modern Ubuntu releases, it provides a centralized, human-readable way to manage your connection state persistently. Whether you are running a simple home lab or a massive data center, mastering Netplan is essential for maintaining a stable and predictable Ubuntu network configuration.

Key Takeaways: Mastering Netplan

  • YAML Syntax → Netplan uses a structured, human-readable format to define network intent.
  • Backend Abstraction → It serves as a high-level tool that generates configuration for either NetworkManager or systemd-networkd.
  • Persistence → Unlike temporary runtime commands, Netplan ensures your IP addresses and routes survive a system restart.
  • Validation → The utility includes a generate command to catch syntax errors before they break your connectivity.

What Problem Does Netplan Solve?

Netplan solves the problem of fragmentation in Linux networking. Before its adoption, administrators had to deal with varying syntax across different tools like ifupdown, NetworkManager, or the iproute2 suite. This made automation difficult because the “language” of network configuration changed depending on whether you were on a desktop or a server.

Netplan provides a distribution-agnostic abstraction layer. You write one unified configuration in a YAML file, and Netplan “renders” those instructions into the correct format for the underlying system backend. This makes it significantly easier to change your IP address in Ubuntu using a standardized workflow regardless of the specific environment.

Common Usage 1: Getting a Network Overview

The first step in any troubleshooting session is seeing what is currently active. While the standard ip addr command shows low-level details, Netplan provides a higher-level summary of your interfaces and correlated information like default routes and DNS servers.

Command: sudo netplan status -a

Expected Output:

Online state: online
DNS Addresses: 127.0.0.53 (stub)
2: enp0s25 ethernet UP (networkd: enp0s25)
   Addresses: 10.102.66.200/24 (dynamic, dhcp)

This output confirms the interface is managed by the networkd backend and has successfully received a dynamic address.

Common Usage 2: Configuring Static vs. DHCP Addresses

One of the most frequent tasks is telling the system how to obtain an IP. Netplan allows you to define this clearly within the configuration files located in /etc/netplan/.

  • For DHCP: Simply set dhcp4: true under your interface name.
  • For Static IPs: You must define an addresses block and a routes section for the gateway.

Configuration Example (Static IP):

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      addresses:
        - 192.168.0.100/24
      routes:
        - to: default
          via: 192.168.0.1

Note: Releases prior to Ubuntu 24.04 (Noble) might use the older gateway4 key instead of the routes block.

Common Usage 3: Overriding DNS and Search Domains

Often, the DNS settings provided by a DHCP server are not sufficient for enterprise needs. Netplan allows you to add a nameservers block to override these defaults or add secondary records.

Configuration Detail: You can specify multiple nameserver addresses and search domains to ensure your system resolves internal resources correctly. This is vital when you need to how to find your IP address in Ubuntu and verify that name resolution is pointing to the correct local mirrors.


Step-by-Step Process: Applying a New Configuration

If you need to update your network settings, follow this verified workflow to avoid losing access to your system:

  1. Navigate to the config directory: Settings are typically stored in /etc/netplan/*.yaml.
  2. Backup your current file: Always keep a copy of a working configuration before making changes.
  3. Edit the YAML file: Use a text editor like vi to modify your IP addresses or routes.
  4. Test for syntax errors: Run sudo netplan generate to ensure the YAML indentation is correct.
  5. Apply the changes: Execute sudo netplan apply to make the new settings effective.
  6. Verify the new state: Use resolvectl status to confirm the DNS resolver was updated correctly.

Summary Tables

Netplan KeywordPrimary PurposeExample Value
rendererDefines the backend daemon.networkd or NetworkManager
dhcp4Enables/disables IPv4 DHCP.true or false
addressesSets fixed IP addresses.[192.168.1.10/24]
viaDefines the default gateway.10.10.10.1
nameserversConfigures DNS resolution.addresses: [8.8.8.8]
CommandActionRecommended Use
netplan generateValidates YAML syntax.Before applying any change.
netplan applyPushes config to backends.To make changes permanent.
netplan status -aShows interface overview.To troubleshoot connectivity.

FAQ

Where are the Netplan configuration files located? They are found in /etc/netplan/. Common names include 01-netcfg.yaml or 99_config.yaml.

Why did I lose connection after running ‘netplan apply’? This usually happens due to a syntax error or an incorrect IP assignment. Be extremely careful when changing network parameters over an SSH connection, as you might lose remote access.

Which backend renderer should I choose? By default, systemd-networkd is recommended for servers, while NetworkManager is typically used for desktop environments.


Related Posts

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 645

Leave a Reply

Your email address will not be published. Required fields are marked *