Nslookup, dig, firefox ignoring /etc/hosts file entries

dnsnsswitch

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

127.0.0.1 www.winaproduct.com

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

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 127.0.0.1 in /etc/resolv.conf .

update

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. ?

Best Answer

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
Related Question