I recently had DNS issues on a Google Cloud VM: it was causing sporadic failures with my site monitor. I thought maybe Cloudflare’s 184.108.40.206 could help. The official Cloudflare DNS instructions for linux do not work with Google Cloud VM’s, because Google reloads the
resolv.conf file every 24 hours when DHCP is renewed.
Preload custom configurations with the
There are various methods for applying custom configurations into
resolv.conf. I had success using the
resolvconf package. First install that package
sudo apt install resolvconf. Now run
sudo nano /etc/resolvconf/resolv.conf.d/head. This is where we add Cloudflare’s 220.127.116.11 configurations which will be added at the top of the
nameserver 18.104.22.168 nameserver 22.214.171.124
This won’t trigger until the next DHCP renew. We can manually trigger that by restarting the VM’s network
sudo systemctl restart systemd-networkd. Now check to see the newly generated
resolve.conf file by running
cat /etc/resolv.conf. Should look like this.
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN # 127.0.0.53 is the systemd-resolved stub resolver. # run "systemd-resolve --status" to see details about the actual nameservers. nameserver 126.96.36.199 nameserver 188.8.131.52 nameserver 127.0.0.53 search x.xxxxxxxxx.internal google.internal options edns0
To verify it’s working do a DNS lookup with DIG from the VM, example:
dig anchor.host. In the bottom of the response you should see the following.
;; Query time: 8 msec ;; SERVER: 184.108.40.206#53(220.127.116.11) ;; WHEN: Thu Aug 22 08:18:42 EDT 2019 ;; MSG SIZE rcvd: 56
If the server line matches 18.104.22.168 or 22.214.171.124 then your Google Cloud VM is now using Cloudflare for DNS lookups. Success! 👏