Netplan has been the default network configuration tool ever since Ubuntu 17.10 was released. Earlier Ubuntu releases shipped with ifupdown as default tool for network configuration. In this article, we would discuss how to configure network with Netplan in Ubuntu. For 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 YAML description for each of the network interfaces configuration. And, in turn the Netplan tool will generate the relevant configuration files. We would discuss 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 network with Netplan
We need to provide the configuration description in Netplans’ config file. The file can be located in folder
Here, you will find the config file – 01-netcfg.yaml
Use a text-editor to make necessary changes. We have used 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 wired network (i.e. Ethernet) wherein you would want dhcp4 to assign the IP addresses. And, make Netplan to 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: [188.8.131.52,184.108.40.206]
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: [220.127.116.11,18.104.22.168] access-points: "Network_SSID": password: "****"
where, wlo1 is 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 defined standards.
sudo netplan try
If everything is in order, following message would get generated –
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 discussed two of the most basic configurations to connect network with Netplan. We also specified how to override dns settings as per our requirements.