How to set custom DNS on Ubuntu based images using netplan


This guide will allow you to set custom DNS to help with networking issues.

Commands to run

Below is a block of code which will install OpenSSL and add the following DNS servers, and but these could be replaced with any DNS you would like to use.

- run: sudo apt-get update
- run: sudo apt-get install openssl
- run: sudo sed -i '12 i \ \ \ \ \ \ \ \ nameservers:' /etc/netplan/50-cloud-init.yaml
- run: sudo sed -i '13 i \ \ \ \ \ \ \ \ \ \ \ \ addresses:' /etc/netplan/50-cloud-init.yaml
- run: sudo sed -i "s/addresses:/ addresses":" [,] /g" /etc/netplan/50-cloud-init.yaml
- run: cat /etc/netplan/50-cloud-init.yaml
- run: sudo netplan apply
- run: systemd-resolve --status | grep 'DNS Servers' -A2


When setting this the original DNS server will also be set so you will have three DNS servers defined that can be used.

Was this article helpful?
0 out of 0 found this helpful



Article is closed for comments.