DNS Resolution Sequence

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 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 (, 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.


Adding a snapshot of the page load time for better clarity.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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.