How to use Google DNS in Ubuntu/Debian permanently

Few weeks ago in one of the servers we faces strange issue: The website couldn’t send emails using remote SMTP.

First i thought it was related to SMTP port, credentials etc. – but everything was OK there. So then i tries to ping google.com and got surprised. It wasn’t worked. Simple ping didn’t work.

So it was obviously corrupted DNS issue.

First i tried the easier way, which is recommended by developers.google.com, adding Google DNS IP addresses to resolv.conf file

sudo vi /etc/resolv.conf

But it didn’t help.

So i decided to go into deeper and solving it using netplan.

Solving DNS issue in Ubuntu/Debian servers:

Step 1: Open netplan file.

sudo nano /etc/netplan

Step 2: Add the following code under ens* block (following YAML syntax is required)

nameservers:
addresses: [8.8.8.8, 8.8.4.4]

It should look like this:

Step 3: Apply the rules:

sudo netplan apply

Step 4: Check if it works:

systemd-resolve --status | grep 'DNS Servers' -A2

It should show something like this

That’s all.

If you see 8.8.8.8 and 8.8.4.4 there, then the problem should be resolved now.

Get more useful WP tricks and snippets by subscribing to my mailclub.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.