DNS Resolution Sequence

March 28, 2018 626 views
DNS CentOS

I have setup multiple domains on my droplet and they cross-reference each other. Currently, when I do a nslookup for these domains from within the droplet, the DNS resolution is handled by 67.207.67.3 which is Digital Ocean's DNS server and it happily points to the same droplet (localhost) via the public IP.

To save on the lookup time and speed up the "page loading time" of the pages cross-referencing these domains, I tried the following steps but I am drawing a complete blank:

  1. Modified the /etc/hosts file so that these domains point to localhost (127.0.0.1), however, that has no effect.

  2. Modified the /etc/cloud/templates/hosts.redhat.tmpl file and inserted the entries there, yet the lookup happens on the DO DNS server.

  3. Ensured that the /etc/nsswitch.conf states that the resolution order is "files" followed by "DNS".

  4. Restarted the networking service post all changes. Tried rebooting as well... Still no luck.

What am I missing? How do I change the name resolution precedence so that it first looks up the hosts file and if an entry is not found, it then looks up the DNS servers?

I do see the nameserver entries in /etc/network/interfaces and /etc/resolv.conf, however, I am not sure if modifying them will yield any results.

Any pointers will be well appreciated. Thanks in advance.

1 comment
1 Answer

It looks like you've done everything right if you've updated your hosts file, cleared your cache, restarted your networking services and updated nsswitch to look at files before dns.

However, nslookup will default to using your nameservers rather than the hosts file and ignores files.

So to check it on the system it's easiest to just issue a ping at the domain. Otherwise for nslookup you need to explicitly need to tell it to look at files.

On the system where you made these changes do a ping at the domain and it should return your local address, if it does, everything is working correctly.

Have another answer? Share your knowledge.