DNS resolution has stopped working on my Ubuntu 16.04 droplet

September 29, 2019 154 views
DNS

Having some issues with dns resolution on my Ubuntu 16.04 droplet with dns.

$ dig google.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> google.com
;; global options: +cmd
;; connection timed out; no servers could be reached

No changes were made to network configuration before I tried to troubleshoot this issue. I’ve tried changing the nameservers in /etc/network/interfaces.d/50-cloud-init.cfg to no avail.

/etc/resolv.conf is empty (except for some comments). If I manually add a nameserver to /etc/resolv.conf, it does work. Of course this doesn’t solve the issue because changes won’t be persisted over reboot.

$ cat /etc/resolv.conf && dig google.com
# 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
nameserver 1.1.1.1

; <<>> DiG 9.10.3-P4-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39462
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1452
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             221     IN      A       216.58.195.78

;; Query time: 1 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Sun Sep 29 19:31:00 UTC 2019
;; MSG SIZE  rcvd: 55

Anyone have similar issues?

EDIT

50-cloud-init.cfg contents (ip’s redacted):

$ cat /etc/network/interfaces.d/50-cloud-init.cfg 
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
auto lo
iface lo inet loopback
    dns-nameservers 67.207.67.3

auto eth0
iface eth0 inet static
    address XXX.XXX.XXX.XXX/20
    gateway XXX.XXX.XXX.XXX

# control-alias eth0
iface eth0 inet static
    address XXX.XXX.XXX.XXX/16

Originally there was a second nameserver defined (next to 67.207.67.3) but I deleted it when messing around and now don’t remember what it was.

1 Answer

Hello, @joek1010

You can edit “`
/etc/dhcp/dhclient.conf

and remove the comment (the #) before:

prepend domain-name-servers 127.0.0.1;

and use 8.8.8.8 for example or any other DNS server you would like to use.

Before making any changes, please make sure to create a copy of the file in case the change does not make a difference so you can revert everything back.

The other option will be to edit your interface configuration, which is located in: ```/etc/network/interfaces ``` as this is something a lot of people use. I personally have two resolv.conf files in order to prevent any issues with the DNS resolution.

Let me know if you have any questions.
  • Thanks for the reply!

    Changing /etc/dhcp/dhclient.conf as suggested did not seem to work (the droplet has a static ip so I think dhclient shouldn’t be doing any configuration, right?). I did manage to get it working by messing around a bit more with /etc/network/interfaces.d/50-cloud-init.cfg

    $ cat /etc/network/interfaces.d/50-cloud-init.cfg 
    # This file is generated from information provided by
    # the datasource.  Changes to it will not persist across an instance.
    # To disable cloud-init's network configuration capabilities, write a file
    # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
    # network: {config: disabled}
    auto lo
    iface lo inet loopback
        dns-nameservers 67.207.67.3
    
    auto eth0
    iface eth0 inet static
        address XXX.XXX.XXX.XXX/20
        gateway XXX.XXX.XXX.XXX
        dns-nameservers 67.207.67.3
    
    # control-alias eth0
    iface eth0 inet static
        address XXX.XXX.XXX.XXX/16
        dns-nameservers 67.207.67.3
    
    $ cat /etc/resolv.conf
    # 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
    nameserver 67.207.67.3
    

    Not sure exactly why this works, but it works.

    Thanks!

Have another answer? Share your knowledge.