LinuxCommandLibrary

netplan

Configure network interfaces on Linux systems

TLDR

Apply a network configuration and make it persistent

$ sudo netplan apply
copy

Generate backend configuration files
$ sudo netplan generate
copy

Configure a network interface to use DHCP
$ sudo netplan set ethernets.[interface_name].dhcp4=true
copy

Try configuration changes without applying them permanently
$ sudo netplan try --timeout [seconds]
copy

Return to previous working configuration after failed apply
$ sudo netplan --debug apply
copy

Display the current netplan configuration status
$ netplan status
copy

SYNOPSIS

netplan [--debug] COMMAND [OPTIONS] [ARGUMENTS]

Common Commands:
netplan generate [--config-file <path>]
netplan apply [--config-file <path>] [--dry-run] [--force]
netplan try [--config-file <path>] [--timeout <seconds>]
netplan status
netplan info

PARAMETERS

--debug
    Enables verbose debugging output for netplan operations, showing more details about parsing and backend configuration generation.

--config-file <path>
    (Used by generate, apply, try, revert, info) Specifies an alternative YAML configuration file or directory to process instead of the default locations (e.g., /etc/netplan/). This is useful for testing or specific deployments.

--timeout <seconds>
    (Used by try) Sets the timeout in seconds for the 'netplan try' command. If the network is not usable within this period, changes are automatically reverted to the previous working configuration, providing a safety net.

--dry-run
    (Used by apply) Shows what changes would be made by 'netplan apply' without actually applying them to the system. This allows for a preview of the configuration impact.

--force
    (Used by apply) Forces the activation of the network configuration, even if errors or warnings are detected during the process. Use with caution as it might lead to unexpected network behavior.

DESCRIPTION

The netplan command provides a declarative way to configure network interfaces on Linux systems. It uses YAML files to define network settings, including IP addresses, DNS servers, routes, and more. Rather than directly interacting with low-level network tools, netplan acts as an abstraction layer, generating appropriate configuration files for different backend network renderers, such as systemd-networkd or NetworkManager.

This approach simplifies network setup and ensures consistent configuration across various Linux distributions and environments. Users define their desired network state in human-readable YAML, and netplan handles the intricate details of applying those settings. Key subcommands include generate (to create backend configs), apply (to activate configurations), and try (to test changes with a revert mechanism).

CAVEATS

  • YAML Syntax Sensitivity: netplan configurations are highly sensitive to YAML syntax, including indentation and spacing. Incorrect formatting can prevent the configuration from being parsed correctly.
  • Backend Dependency: netplan relies on an underlying network renderer (like systemd-networkd or NetworkManager) to apply configurations. Ensure one of these is installed and active on your system for netplan to function correctly.
  • Root Privileges: All netplan commands that modify or apply network configurations (e.g., generate, apply, try) require root privileges (e.g., using sudo).
  • Limited Scope: While powerful for network interface configuration, netplan does not directly manage advanced networking features like firewall rules (e.g., iptables, ufw) or VPN connections, which are typically handled by other dedicated tools.

CONFIGURATION FILES

netplan configuration files are written in YAML format and are typically located in /etc/netplan/. Other locations like /run/netplan/ (for runtime configurations) and /lib/netplan/ (for vendor-provided configurations) are also processed. Files are read in lexical order, with later files (e.g., 99-custom.yaml) overriding earlier ones for conflicting settings, allowing for easy customization.

NETWORK RENDERERS

netplan does not directly manage the network interfaces; instead, it generates configuration files for a specified backend 'renderer'. The two primary renderers supported are systemd-networkd (often the default for server installations and headless systems due to its lightweight nature) and NetworkManager (common for desktop environments due to its extensive GUI and Wi-Fi support). The chosen renderer is specified within the netplan YAML configuration file (e.g., renderer: networkd or renderer: NetworkManager).

TYPICAL WORKFLOW

The typical workflow for configuring network with netplan involves a few straightforward steps:
1. Edit: Create or modify YAML configuration files in /etc/netplan/ using a text editor.
2. Validate (Optional): Run netplan generate to check for syntax errors and compile the YAML into backend-specific configuration files (e.g., for systemd-networkd or NetworkManager).
3. Apply/Try: Use netplan apply to immediately activate the new configuration, or for safer changes, use netplan try which applies the configuration but reverts it after a timeout if network connectivity is lost, providing an automatic rollback mechanism.

HISTORY

netplan was developed by Canonical, the creators of Ubuntu, and was first introduced with Ubuntu 17.10 (Artful Aardvark) in October 2017. Its primary goal was to provide a unified and consistent method for network configuration across various Ubuntu releases and server environments, abstracting away the differences between underlying network management daemons like systemd-networkd and NetworkManager. This declarative approach aimed to simplify network management for administrators and cloud deployments, providing a single YAML-based configuration format.

SEE ALSO

networkd(8), systemd-networkd(8), NetworkManager(8), ip(8), nmcli(1)

Copied to clipboard