Configure network with Netplan in Ubuntu

Netplan has been the default network configuration tool ever since Ubuntu 17.10 was released. Earlier Ubuntu releases shipped with ifupdown as the default tool for network configuration. In this article, we cover how to configure the network with Netplan in Ubuntu. Users, who still prefer to use ifupdown tool are advised to read the related article – Switch back to ifupdown – /etc/network/interfaces in Ubuntu.

Netplan configuration tool utilizes YAML – YAML Ain’t Markup Language. It is a human-friendly data serialization language/standard. All we have to do is to provide a YAML description for each of the network interfaces configuration. And, in turn, the Netplan tool will generate the relevant configuration files. We would discuss a couple of Netplans’ basic configurations next.

Note: Following operations would require you to have superuser privileges. In case you don’t have one then contact your System Administrator for assistance.

Configure networking with Netplan in Ubuntu

We need to provide the configuration description in Netplans’ config file. The file can be located in the folder /etc/netplan/

cd /etc/netplan/

Here, you will find the config file – 01-netcfg.yaml

Use a text editor to make necessary changes. We have used the Nano text-editor. Also, before making any changes it is always better to backup the relevant data. So,

cp 01-netcfg.yaml 01-netcfg.yaml.bak

This will create a new file – 01-netcfg.yaml.bak, which is the backup of our original file. Now, open the default config file with a text editor –

sudo nano 01-netcfg.yaml
Basic configuration for connecting Wired Network

For connecting a wired network (i.e. Ethernet) wherein you would want dhcp4 to assign the IP addresses. And, make Netplan override DNS settings as per your requirements. We would have to append the following entries in /etc/netplan/01-netcfg.yaml file –

network:
       version: 2
       renderer: networkd
       ethernets:
            enp0s3:
                 dhcp4: yes
                 dhcp4-overrides:
                      use-dns: no
                 nameservers:
                      addresses: [8.8.8.8,8.8.4.4]

We can check the status of our DNS servers through the command –

resolvectl status enp0s3

where enp0s3 is our Ethernet network peripheral. This would be different for every network interface.

Basic configuration for connecting WPA Personal Wireless Network

Similarly, for wireless connections wherein we use dhcp4 and DNS servers as per our requirements.

network:
          version: 2
          renderer: networkd
          wifis:
               wlo1:
                    dhcp4: yes
                    dhcp4-overrides:
                           use-dns: no
                    nameservers:
                           addresses: [8.8.8.8,8.8.4.4]
                    access-points:
                           "Network_SSID":
                                    password: "****"

where wlo1 is the Wireless network interface.

Next, check the status of our DNS servers through the command –

resolvectl status enp0s3

Once we are finished with either of the configurations, check whether the configuration supplied is as per the defined standards.

sudo netplan try

If everything is in order, the following message would get generated –

Configuration accepted.

Next, we would apply the configuration supplied for use.

sudo netplan apply

Note: The above code for configuration files is indentation-sensitive.

In conclusion, we have cover how to configure networking with Netplan in Ubuntu. We also specified how to override DNS settings as per our requirements.

Similar Posts