How to Configure Networking in Ubuntu 20.04 with NetPlan


In this tutorial, you will learn how to configure networking in Ubuntu 20.04 with Netplan. You will learn how to set static IP addresses, DHCP addresses, as well as how to configure DNS and Wifi.

Introduced back in 18.04, April 2018, networking was redone using a new system called Netplan – a YAML based configuration network configuration system for NetworkManager and SystemD.

NetPlan Files

Network interfaces in Ubuntu 20.04 are configured in NetPlan YAML files, which are stored under /etc/netplan. The default file networking interfaces for a new Ubuntu 20.04 install is /etc/netplan/00-installer-config.yaml.

To edit the default netplan file, use the following command.

sudo vi /etc/netplan/00-installer-config.yaml

Alternatively, a simpler text editor by the name of nano can be used instead of vim.

sudo nano /etc/netplan/00-install-config.yaml

How to Set Static IP Address

The following is an example Netplan file with a network interface that has a static IP address. The interface’s name is en01 and it has been assigned static IP addresses for IPv4, and 2001:1::1/64 for IPv6.

As both IPv4 and IPv6 have been assigned static IP addresses, each has a gateway set too.

DNS Name servers are also defined in this file. We’ll cover DNS a little further down in this tutorial.

  version: 2
  renderer: networkd
      - "2001:1::1/64"
      gateway6: "2001:1::2"

To apply changes to netplan you will need to reload your Netplan network configurations.

sudo netplan apply

How to set DHCP Addresses

Dynamically addressed can be assigned for IPv4 and IPv6, provided your network has a DHCP server.

The following example shows how to enable DHCP for both IPv4 and IPv6. To enabled just one, you would remove the network IP version not needed.

  version: 2
  renderer: networkd
      dhcp4: true
      dhcp6: true

To update your netplan configurations, run the netplan apply command.

sudo netplan apply

How to Set DNS

The following is an example of a network interface id0 with nameservers configured.

      search: [lab, home]
      addresses: [, "FEDC::1"]
  • search is a list of search domains, which are used when a non-fully qualified hostname is given. For example, if you were to ping server1 rather than server1.lab.
  • addresses is a list of IPv4 or IPv6 ip addresses for the DNS name servers. IPv6 must be quoted.

How to set WiFi Authentication

While WiFi is not something you would commonly configure Ubuntu server for, it it is prevalent enough you may consider using it in some use cases. To the following with walk you through configuring WPA and EAP wifi modes.

Systemd does not have native wifi support. In order for your network device to work with wifi you will need wpasupplicant installed.

Configuring WPA and EAP WiFi Connections

The most common home wifi configurations use mode WPA or EAP, while EAP is more common in enterprise. These two modes use a basic form of authentication using a password or shared-key.

For home users, the WPA mode is the simplest to use with a compatible wifi device. Devices that support WPA can automatically join wifi networks by pressing the WPA button on a compatible wifi router.

To configure WPA or EAP on Ubuntu using Netplan, you would add the auth scalar to your netplan configuration file. In the example below, we’ve added it to a ethernet interface named id0.

      mode: infrastructure
      bssid: mywifi
      band: 5GHz
      channel: 5
      key-management: none | psk | eap 
      password: my-password-string

The access-points scalar sets how the wifi connection will be established.

  • mode set the mode type for your wifi network interface. For connecting to access points the value should be set to infrastructure, which is the default.
  • bassid is the name of your wifi connection, as configured on your access point.
  • band is used to set the wireless band. It accepts two values: 5GHz and 2.4GHz. If left unset, the wifi endpoint and your network device will automatically establish the best band. By setting this value you will force the connection to use a specific band.
  • channel is used to set your wifi channel, and only takes affect if the band property is set.

WPA and EAP connection modes accept the following configurations.

  • key-management sets how the supported key management mode.
    • none to disable key management
    • psk for WPA with pre-shared key, common for home wifi.
    • eap for WPA with EAP, which is common for enterprise wifi networks.
  • password sets the pre-shared key or password for your wifi network, when the mode is set to either psk or eap.