Netplan Configuration Guide on Ubuntu 26.04

Netplan is the default network configuration tool for Ubuntu, providing a unified interface for managing network settings through simple YAML files. This netplan ubuntu 26.04 guide covers the essentials you need to understand and configure networking on Ubuntu Server, from file structure and syntax to applying and validating your configurations.

In this tutorial you will learn:

  • Where Netplan configuration files are located
  • How to write valid YAML syntax for network configuration
  • Common Netplan configuration examples
  • How to safely apply and test configuration changes
  • How to validate and troubleshoot Netplan errors
Netplan configuration guide on Ubuntu 26.04
Guide to configuring network settings with Netplan on Ubuntu 26.04

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software Netplan.io (pre-installed)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

DESKTOP USERS
Ubuntu Desktop uses NetworkManager as the default renderer, which manages network connections through the GUI. If you edit Netplan files directly on desktop systems, NetworkManager may override your settings. For Ubuntu Desktop, use Settings → Network or the nmcli command instead. This guide focuses on Ubuntu Server, which uses systemd-networkd as the backend renderer.

TL;DR
Netplan configuration files are YAML files located in /etc/netplan/. Edit your configuration file, then apply changes safely with sudo netplan try.

Quick Steps to Configure Netplan on Ubuntu 26.04
Step Command/Action
1. List configuration files ls /etc/netplan/
2. Edit configuration sudo nano /etc/netplan/00-installer-config.yaml
3. Test configuration (with rollback) sudo netplan try
4. Apply permanently sudo netplan apply

Netplan File Structure on Ubuntu 26.04

Netplan reads configuration files from three directories, processed in the following order of priority:

  • /run/netplan/ – Runtime configurations (highest priority, temporary)
  • /etc/netplan/ – Administrator configurations (primary location for your changes)
  • /lib/netplan/ – System package defaults (lowest priority)

Files within each directory are processed in lexicographical order, meaning 00-installer-config.yaml is read before 99-custom.yaml. Later files can override settings from earlier ones.

Depending on your Ubuntu installation method, you may encounter different default configuration files in /etc/netplan/:

  • 00-installer-config.yaml – Created by Ubuntu Server installer (subiquity)
  • 01-netcfg.yaml – Generic configuration filename
  • 01-network-manager-all.yaml – Ubuntu Desktop (defers to NetworkManager)
  • 50-cloud-init.yaml – Cloud deployments (AWS, Azure, GCP, OpenStack)

To identify your current configuration file, run:

$ ls -la /etc/netplan/
Terminal output of ls -la /etc/netplan/ showing 00-installer-config.yaml file on Ubuntu 26.04
The /etc/netplan/ directory contains the 00-installer-config.yaml file created by the Ubuntu Server installer

You can create your own configuration file with any name ending in .yaml. Netplan scans all YAML files in the directory regardless of filename. Files are processed alphabetically, so 99-custom.yaml would override settings from 00-installer-config.yaml for the same interface. You can either edit the existing file, create a new one alongside it, or replace it entirely.

When creating a new configuration file, set proper permissions to avoid security warnings:

$ sudo touch /etc/netplan/99-custom.yaml
$ sudo chmod 600 /etc/netplan/99-custom.yaml

PERMISSIONS WARNING
If file permissions are too open, Netplan displays: WARNING: Permissions for /etc/netplan/filename.yaml are too open. Netplan configuration should NOT be accessible by others. The configuration still applies, but you should restrict permissions with chmod 600 to prevent other users from reading network credentials such as Wi-Fi passwords.

YAML Syntax Essentials for Netplan

Netplan uses YAML (YAML Ain’t Markup Language) for configuration. Understanding YAML syntax is critical because even minor formatting errors will prevent your network configuration from applying. Consequently, paying attention to indentation and structure saves significant troubleshooting time.

Key YAML rules for Netplan:

Indentation uses spaces, not tabs. Netplan requires exactly 2 spaces per indentation level. Tabs will cause parsing errors.

# Correct - 2 spaces per level
network:
  version: 2
  ethernets:
    ens18:
      dhcp4: true

Colons must be followed by a space. When assigning values, always include a space after the colon.

# Correct
dhcp4: true

# Wrong - missing space
dhcp4:true

Lists use hyphens with consistent indentation. Each list item starts with a hyphen and space.

# Correct list format
addresses:
  - 172.16.1.170/24
  - 172.16.1.171/24
nameservers:
  addresses:
    - 8.8.8.8
    - 8.8.4.4

Boolean values are lowercase. Use true and false, not True, TRUE, yes, or no.

Netplan Configuration Examples on Ubuntu 26.04

The following examples demonstrate common netplan ubuntu 26.04 configurations. Each example shows a complete, working configuration file that you can adapt to your environment.

INTERFACE NAME
All examples below use ens18 as the network interface name. Your interface name will likely differ. To determine your interface name, run:

$ ip link

Common interface names include ens18, enp0s3, ens33, or eth0 depending on your hardware and virtualization platform. Replace ens18 with your actual interface name in all configurations.

  1. DHCP Configuration (Default): The simplest configuration obtains network settings automatically from a DHCP server.
    network:
      version: 2
      ethernets:
        ens18:
          dhcp4: true
          dhcp6: true

    This configuration enables IPv4 and IPv6 DHCP on the specified interface. This matches the default Ubuntu Server installer configuration.

  2. Static IP Configuration: For servers requiring a fixed IP address, disable DHCP and specify network parameters manually.
    network:
      version: 2
      ethernets:
        ens18:
          dhcp4: false
          addresses:
            - 172.16.1.170/24
          routes:
            - to: default
              via: 172.16.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 8.8.4.4

    This assigns IP 172.16.1.170 with a /24 subnet mask, sets the default gateway to 172.16.1.1, and configures Google’s DNS servers. For a detailed walkthrough, see how to configure static IP with Netplan.

  3. Custom DNS Servers: You can configure DNS servers independently of your IP configuration method.
    network:
      version: 2
      ethernets:
        ens18:
          dhcp4: true
          nameservers:
            addresses:
              - 1.1.1.1
              - 9.9.9.9
            search:
              - example.com
              - internal.local

    This uses DHCP for IP addressing but overrides DNS with Cloudflare (1.1.1.1) and Quad9 (9.9.9.9). The search directive appends these domains when resolving short hostnames.

  4. Static Route Configuration: Adding a static route directs traffic for specific networks through a designated gateway.
    network:
      version: 2
      ethernets:
        ens18:
          dhcp4: true
          routes:
            - to: 10.10.0.0/16
              via: 172.16.1.254

    This configuration uses DHCP for the default network settings but adds a static route directing all traffic destined for 10.10.0.0/16 through gateway 172.16.1.254. This is useful for reaching networks behind a secondary router or VPN gateway.

OPTIONAL PARAMETERS
Your default configuration may include additional parameters like match: and set-name: which the Ubuntu installer uses for interface matching. These are optional for basic configurations and can be safely omitted in custom configurations.

Applying Netplan Configuration on Ubuntu 26.04

After modifying your Netplan configuration files, you must apply the changes for them to take effect. Netplan provides three commands for this purpose, each serving a different role in the configuration workflow.

  1. netplan try (Recommended for Testing): This command applies configuration changes temporarily with an automatic rollback safety net.
    $ sudo netplan try

    After applying, Netplan waits for confirmation. If you don’t press ENTER within 120 seconds (or if you lose network connectivity), it automatically reverts to the previous working configuration. This is invaluable when configuring remote servers where a misconfiguration could lock you out.

  2. netplan apply (Permanent Application): Once you’ve verified your configuration works correctly, apply it permanently.
    $ sudo netplan apply

    This command applies the configuration immediately without a rollback timer. Use this only after testing with netplan try or when you have physical/console access to the machine.

  3. netplan generate (Debug Backend Configuration): This command generates backend-specific configuration files without applying them.
    $ sudo netplan generate

    Netplan translates YAML configurations into files for the underlying renderer (systemd-networkd or NetworkManager). The generated files are placed in /run/systemd/network/ for systemd-networkd. This is useful for debugging or understanding what Netplan creates.

Terminal showing sudo netplan try command with 120-second countdown and configuration accepted message on Ubuntu 26.04
The netplan try command applies changes temporarily with a 120-second countdown, automatically reverting if not confirmed

Validating and Troubleshooting Netplan on Ubuntu 26.04

When your netplan ubuntu 26.04 configuration doesn’t work as expected, follow these steps to identify and resolve issues.

  1. Validate YAML syntax: Before applying, check your configuration file for syntax errors.
    $ sudo netplan generate

    If there are YAML errors, Netplan outputs specific line numbers and error descriptions. Common errors include incorrect indentation, missing colons, or tabs instead of spaces.

    COMMON ERROR
    Error in network definition: unknown key 'adresses' – This typically indicates a typo. Check spelling carefully (addresses, not adresses).

  2. View generated configuration: Examine what Netplan creates for the backend renderer.
    $ cat /run/systemd/network/10-netplan-ens18.network

    This shows the actual systemd-networkd configuration generated from your YAML file. If settings appear incorrect here, the issue is in your Netplan YAML.

  3. Check network interface status: Verify your interface has the expected configuration applied.
    $ ip addr show ens18
    $ ip route show

    The first command displays IP addresses assigned to the interface. The second shows the routing table, including your default gateway and any static routes.

  4. Test connectivity: Verify network functionality after applying changes.
    $ ping -c 3 172.16.1.1      # Test gateway
    $ ping -c 3 8.8.8.8         # Test internet
    $ ping -c 3 example.com     # Test DNS resolution

    If gateway ping fails, check your IP and gateway configuration. If internet works but DNS fails, verify your nameserver settings.

  5. Review system logs: For persistent issues, check systemd-networkd logs.
    $ journalctl -u systemd-networkd --since "10 minutes ago"

    This reveals detailed information about network interface initialization and any errors encountered by the network daemon.

For additional troubleshooting, consult the official Netplan documentation.

Conclusion

This guide covered the essential aspects of netplan ubuntu 26.04 configuration, including file locations, YAML syntax requirements, common configuration examples, and methods for applying and validating changes. Understanding these fundamentals enables you to confidently configure Netplan for static IPs, custom DNS, and routing on Ubuntu Server.

For more specific configurations, refer to our detailed guides on setting static IP with Netplan, configuring DHCP with Netplan, and applying Netplan changes.

Frequently Asked Questions

  1. What is the difference between netplan try and netplan apply? The netplan try command applies your configuration temporarily and automatically reverts after 120 seconds unless you confirm. This provides a safety net when making changes remotely. The netplan apply command applies changes permanently without any rollback mechanism.
  2. Why does Netplan show “Error in network definition” when my YAML looks correct? YAML is sensitive to indentation. Ensure you use exactly 2 spaces (not tabs) per indentation level. Also verify colons have a space after them and check for typos in key names like addresses or nameservers.
  3. Which Netplan configuration file should I edit? Edit the file in /etc/netplan/ that exists on your system. On Ubuntu Server, this is typically 00-installer-config.yaml. You can create additional files with higher numbers (like 99-custom.yaml) to override specific settings without modifying the original file.
  4. Can I have multiple IP addresses on a single interface with Netplan? Yes, add multiple entries under the addresses key as a YAML list. Each address should include its CIDR notation, for example - 172.16.1.170/24 and - 172.16.1.171/24.
  5. How do I find my network interface name for Netplan configuration? Run ip link or ip addr to list all network interfaces. Modern Ubuntu uses predictable interface names like ens18, enp0s3, or eth0 depending on your hardware and virtualization platform.