How to set custom DNS on Ubuntu based images using netplan

Install OpenSSL and Add Servers

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, 8.8.8.8 and 1.1.1.1 but these could be replaced with any DNS you would like to use.

steps:
- run: sudo apt-get update
- run: sudo apt-get install openssl
- run: sudo sed -i '13 i \ \ \ \ \ \ \ \ \ \ \ \ nameservers:' /etc/netplan/50-cloud-init.yaml
- run: sudo sed -i '14 i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ addresses:' /etc/netplan/50-cloud-init.yaml
- run: sudo sed -i "s/addresses:/ addresses":" [8.8.8.8, 1.1.1.1] /g" /etc/netplan/50-cloud-init.yaml
- run: cat /etc/netplan/50-cloud-init.yaml
- run: sudo netplan apply

NOTE: 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?
3 out of 9 found this helpful

Comments

0 comments

Article is closed for comments.