How to set custom DNS on Ubuntu based images using netplan

Overview

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 '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":" [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
- run: systemd-resolve --status | grep 'DNS Servers' -A2

Notes

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

Comments

0 comments

Article is closed for comments.