There is something terribly wrong with my current Debian install. Most programs like firefox, nslookup, dig etc. are ignoring entries in /etc/hosts file, actually I use this file for Ad-blocking.

an example

a line in /etc/hosts file www.winaproduct.com

when I do dig +short www.winaproduct.com it returns the respective IP address of the server, not

Open www.winaproduct.com on firefox, it shows the respective website, but this is not expected.

But there is no problem with ping, busybox nslookup, busybox ping, resolveip etc.

So, what is the problem ? And how to fix it ?I think the problem is with the DNS resolving library.

A temporary fix-up, setup dnsmasq and change nameserver to in /etc/resolv.conf .


problem magically solved after installing libnss3, as a dependency of google-chrome

default /etc/nsswitch.conf looks like hosts: files dns

how to tell nslookup, dig etc. ask /etc/hosts file first instead asking directly to the DNS ?

but why busybox nslookup, wget, resolveip etc. are working differently than nslookup , dig etc. ?

  • what does the hosts: entry in /etc/nsswitch.conf look like? – casey Jun 29 '15 at 16:13
  • @ casey, /etc/nsswitch.conf looks like hosts: files dns – Arnab Jun 29 '15 at 16:28
  • Please add this key information within your OQ. – dan Jun 30 '15 at 7:04
  • This is clearly not a DNS problem. Please look at this very similar question: unix.stackexchange.com/q/158419/31707 . – dan Jun 30 '15 at 7:05

nslookup, dig, and host are tools for querying DNS name servers.

If your configuration is not provided by a name server (like the information given in /etc/hosts) those tools will not show them, because they directly ask the name server.

If you want to check that the "usual" resolution is working (i.e. the way specified in /etc/nsswitch.conf) you can use getent:

getent hosts www.winaproduct.com
  • getent hosts www.winaproduct.com is working perfectly, but nslookup, dig, host etc. are only as example, I want it on firefox. – Arnab Jun 29 '15 at 17:20
  • 1
    If it works with getent it should also work with firefox. (Both use the same resoltution mechanism.) If it really does not work check for "unusual" configuration in firefox. Maybe you set some kind of proxy or something like this. – michas Jun 29 '15 at 17:23
  • thanks for the comment, I dont use any unusual firefox configuration, no it is not working with firefox(38.0.1) . – Arnab Jun 29 '15 at 17:27
  • 3
    I'm very sure it is some browser issue. Try wget or some other browser like chrome. If getent gives the expected result all of them should. – michas Jun 29 '15 at 17:29
  • 1
    @daniel Azuelos, there is nothing wrong with firefox settings, it's already using No Proxy. So how to tell nslookup, dig etc. ask /etc/hosts file first instead asking directly to the DNS ?. Thank you for your valuable comment. – Arnab Jun 30 '15 at 2:19

You can install DNSmasq which will read your /etc/hosts entries and import them into its DNS cache. Then, all your DNS tools and DNS querying applications such as dig, host and nslookup will receive answers that originate from the /etc/hosts file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.