Modern Ubuntu Server releases (17.10 and later) use Netplan as the default network configuration system.

Instead of editing /etc/network/interfaces, the network settings are now defined in declarative YAML files and applied through systemd-networkd or NetworkManager.

In this post, we’ll walk through the essential Netplan concepts and show how to configure common setups like static IPs, gateways, and routes.



Introduction

Netplan is the default network configuration framework on modern Ubuntu systems. Developed by Canonical, it provides a simple YAML-based configuration format that defines network settings such as IP addresses, gateways, DNS servers, and routes.

During system boot, Netplan reads its configuration files from the /etc/netplan/ directory and generates the appropriate backend configuration for either systemd-networkd or NetworkManager, which then apply the network settings to the system.


Netplan was created by Canonical and is primarily associated with Ubuntu, but it is not exclusive to Ubuntu.

Netplan is used by:

  • Ubuntu Server
  • Ubuntu Desktop
  • Ubuntu Cloud Images
  • Some Ubuntu-based distributions


Most other Linux distributions use different network configuration frameworks:

  • NetworkManager (Fedora, Rocky Linux, AlmaLinux, RHEL desktops)
  • systemd-networkd directly (many minimal/server installations)
  • Wicked (openSUSE/SLES)
  • ifupdown (older Debian systems)
  • Traditional network-scripts (older RHEL/CentOS releases)


Netplan itself does not configure the network. It acts as a frontend that generates configuration for either systemd-networkd or NetworkManager, which then perform the actual network configuration.


About Mastering Linux NetworkManager and its nmcli you can also read my following post.


When NetworkManager is used as the network backend, connection profiles are typically stored as key files in the /etc/NetworkManager/system-connections/ directory. These files contain settings such as IP addresses, gateways, DNS servers, routes, and Wi-Fi credentials in a simple INI-style format.

About directly using these key files to configure the network settings you will also see in my following post.


Alternatively, network connections can be created and managed using the nmcli command-line utility (shown in my post above), which modifies the same connection profiles through the NetworkManager API without requiring direct file editing.


About Wicked for openSUSE/SLES my following post.

Configuring Network Settings (Static and DHCP)

Ubuntu uses Netplan to manage network configuration through YAML files located in the /etc/netplan/ directory.

Before modifying the Netplan configuration, we can use the ip link show command to identify the network interfaces available on the system. In this example, the primary network adapter is named ens192, which is the interface referenced below in the 50-cloud-init.yaml configuration file.

$ ip link show


In this example below, we will modify the 50-cloud-init.yaml configuration file to configure a static IP address, default gateway, DNS server, and DNS search domain, ensuring the system can automatically resolve short hostnames within the matrixpost-lab.net domain.

The version: 2 parameter specifies the Netplan configuration format version and is required in all Netplan configuration files. Currently, version 2 is the standard and only supported configuration schema used by modern Ubuntu releases.

$ sudo nano /etc/netplan/50-cloud-init.yaml

network:
    ethernets:
        ens192:
            addresses:
            - 10.0.0.241/24
            nameservers:
                addresses:
                - 10.0.0.70
                search:
                - matrixpost-lab.net
            routes:
            -   to: default
                via: 10.0.0.1
    version: 2


In addition to the default gateway, Netplan allows you to configure static routes to reach remote networks through specific next-hop routers.

In the example below, traffic destined for the 172.16.0.0/16 network is forwarded to the router at 10.0.0.254, while all other traffic uses the default gateway 10.0.0.1.

        routes:
        -   to: default
            via: 10.0.0.1
        -   to: 172.16.0.0/16
            via: 10.0.0.254


On Ubuntu with Netplan, after editing the YAML file, apply the new configuration with:

$ sudo netplan apply


To obtain network settings automatically from a DHCP server, replace the static configuration with the dhcp4: true directive.

The DHCP server will then provide the IP address, subnet mask, default gateway, DNS servers, and any additional network options configured in the environment.


The ip addr show, ip route show, and /etc/resolv.conf commands can be used to verify the currently active network configuration. In the output below, the dynamic flag on the IP address and the proto dhcp entries for the default route indicate that the network settings were assigned dynamically by a DHCP server, while the proto static entry confirms that the route to 172.16.0.0/16 was configured manually. The DNS search domain can be verified in /etc/resolv.conf, where the search matrixpost-lab.net entry allows short hostnames within the domain to be resolved automatically.

/etc/resolv.conf on modern Ubuntu systems using systemd-resolved only shows the local stub resolver (127.0.0.53) and not the actual upstream DNS servers received from DHCP.


The resolvectl status command displays the actual DNS configuration currently in use by the system. In this example, the DNS server 10.0.0.70 and the DNS search domain matrixpost-lab.net were assigned to the ens192 interface and are used by systemd-resolved to perform name resolution.

$ resolvectl status

or for a specific interface:
$ resolvectl status ens192

Disable IPv6 Persistently

Although disabling IPv6 using sysctl removed the IPv6 addresses temporarily, the settings were not fully preserved during the network initialization process after a reboot. By adding the kernel parameter ipv6.disable=1 to the GRUB configuration, IPv6 is disabled at boot time before any network interfaces are initialized, preventing link-local IPv6 addresses (fe80::/64) from being created in the first place.

Edit /etc/default/grub

$ sudo nano /etc/default/grub

Add "ipv6.disable=1" for GRUB_CMDLINE_LINUX_DEFAULT as shown below.


Next update Grub and reboot the system.

$ sudo update-grub
$ sudo reboot

Links

Canonical Netplan
https://netplan.io/

Netplan documentation
https://netplan.readthedocs.io/en/stable/