How to Configure Networking in Ubuntu 20.04 with NetPlan

Overview

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 192.168.1.25/24 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.

network:
  version: 2
  renderer: networkd
  ethernets:
    en01:
      addresses:
      - 192.168.1.25/24
      - "2001:1::1/64"
      gateway4: 192.168.1.1
      gateway6: "2001:1::2"
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4

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.

network:
  version: 2
  renderer: networkd
  ethernets:
    en01:
      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.

ethernets:
  en01:
    [...]
    nameservers:
      search: [lab, home]
      addresses: [8.8.8.8, "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.

ethernets:
  id0:
    [...]
    access-points:
      mode: infrastructure
      bssid: mywifi
      band: 5GHz
      channel: 5
    auth:
      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.

Similar Posts

  • Configure redhat remote printers

    On system connected to printer In system-config-settings under server settings check Share published printers connected to this system. On system connecting to remote printer Using makePrinter, create a printer using the same printer name as server. Also, hostname of server must be in /etc/hosts.  The UIR(port) should be ipp-1. Using system-config-printers, modify Device URI to read ipp//host-IP:631/printers/printer-name This allows for remote printing using the internet printer protocol.

  • RHEL 6 NFS

    Ensuring NFS Services are running on RHEL 6 The first task is to verify that the NFS services are installed and running on your RHEL 6 system. This can be achieved either from the command line, or using the graphical services tool. Begin by confirming that the NFS service is installed by running the following command from a…

  • Mount NTFS on RHEL

    ElRepo repository has kmod-fuse package that does not need dkms system. Since kmod installation uses module aliases (something like symlinks on filesystems), it works on all installed and future kernels without the need to recompile/install even automatic one with dkms. Get started Import the public key:rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org Detailed info on the GPG key used by the…

  • Mount Windows Share on RHEL

    In CLI    mount -t cifs //ntserver/dir -o username=user,password=pass /mnt/ntserver    In /etc/fstab    //ntserver/dir   /mnt/ntserver   cifs   credentials=/root/.smbpasswd,file_mode=0777,dir_mode=0777   0   0 Then create a file /root/.smbpasswd  with permissions set to 600    username=user    password=pass In /etc/hosts add IP address of ntserver.