Host Reachable Through cURL but Cannot Be Resolved by nslookup

Recently I was doing some weird shit with docker and docker compose that required a weird DNS setup. While debugging a problem with DNS resolution in nginx I came across a strange issue: I could reach a host by curl and ping but wasn't able to resolve it using nslookup and dig.

A quick Google search wasn't really helpful so I decided to run strace on both tools and see if there's an obvious difference in how they handle name resolution. After looking at the trace I finally spotted the difference: curl was opening /etc/hosts and dig wasn't!

Turns out extra_hosts is adding hostnames to the /etc/hosts file which isn't checked by the DNS tools or nginx resolver.


If you've come this far with the article you may want to know a thing or two about me if you don't already. You can also read other blog posts or about stuff I've learned recently.

This website is open source. If you've come across a mistake please let me know there. For other types of feedback you can reach out to me through email or social-media.