Ubuntu Netplan Configuration

Overview


Netplan is a utility for easy configuration of network settings in Linux, adopted in Ubuntu since version 18.04.
Network settings can be described concisely using YAML.




Overview

1. Load the YAML file in the /etc/netplan directory.

2. If there are multiple YAML files, the last file takes precedence.

3. Generate backend configuration files in /run based on YAML files and delegate control to specific network daemons.

Important Point

After OS installation, files such as /etc/netplan/50-cloud-init.yaml exist. Since such files may be overwritten by updates, it is better to create individual files (such as 99-config.yaml) to describe network settings.


Configuration Example

The following is examples of a configuration that is likely to be used frequently: YAML is described in Mapping format (Sequence format or a mixture of the two is also acceptable).


Backend Configuration

The backend is specified by renderer. NetworManager and Systemd-networkd are supported. Systemd-networkd is default. If specified explicitly, NetworkManager or networkd must be specified.
Example:

1network:
2    version: 2
3    renderer: NetworkManager

DHCP Configuration

IPv4 address is specified by dhcp4 and IPv6 address by dhcp6. DHCP setting is disabled by default. To specify explicitly, use true or false to enable/disable.
Example:

1network:
2  version: 2
3  ethernets:
4    eno1:
5      dhcp4: true
6      dhcp6: true

Static IP address Configuration

Static IP addresses are specified by addresses with a prefix. Default Gateway is specified by gateway4 for IPv4 address and gateway6 for IPv6 address.
Example:

1network:
2  version: 2
3  ethernets:
4    eno1:
5      addresses: [10.0.0.100/24, 2400:1:2:3::100/64]
6      gateway4: 10.0.0.1
7      gateway6: 2400:1:2:3::1

Static Routes Configuration

Static routes are specified by routes, to, and via.
Example:

1network:
2  version: 2
3  ethernets:
4    eno1:
5      addresses: [10.0.0.100/24]
6      gateway4: 10.0.0.1
7      routes:
8      - to: 10.254.0.0/24
9        via: 10.0.0.2

DNS Resolver Configuration

DNS resolver are specified by nameservers. Domain search is specified by search and DNS servers are specified by addresses.
Example:

1network:
2  version: 2
3  ethernets:
4    eno1:
5      nameservers:
6        search: [local, intra]
7        addresses: [10.0.0.200, 2400:1:2:3::200]

Interface name change

In some environments, interface names may be cumbersome. By using match and set-name, the interface name can be changed. In the example, the interface name is changed based on the MAC address.
Example:

1network:
2  version: 2
3  ethernets:
4    eno1:
5      match:
6        macaddress: 00:ab:cd:33:44:55
7      set-name: eth0

Bonding Configuration

Multiple interfaces can be grouped together to create a virtual interface. Configure using bonds, interfaces and parameters.
Example:

1network:
2  version: 2
3  bonds:
4    bond0:
5      interfaces: [eth0, eth1]
6      addresses: 10.0.0.100/24
7      parameters:
8        mode: active-backup
9        primary: eth0

dhcp-identifier

Ubuntu, for example, uses DUID for DHCP. If you want to use MAC address for some reason, use dhcp-identifier to set it. Either mac or duid can be specified. Works only if renderer is networkd.
Example:

1network:
2  version: 2
3  renderer: networkd
4  ethernets:
5    dhcp4: true
6    dhcp-identifier: mac

Apply and confirm configuration

To apply the settings, execute the following command.

1$ sudo netplan apply

To confirm the settings, execute the following command.

1$ ip addr show

Reference


Translations: