nslookup, dig, firefox ignoring /etc/hosts file entries
Solution 1
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
Solution 2
Configure Unbound package (installed by default on Linux these days) or install it on Windows. Then your resolver will look to this little lightweight service for all DNS queries. Unbound will read in your /etc/hosts
entries and import them into the resolvers DNS cache.
For everything else, it will proxy your system's DNS queries to your machine's up-stream DNS servers.
Now, all your applications as well as your DNS tools such as dig
, host
and nslookup
can receive answers that originated from your local /etc/hosts
file.
As an alternative on Linux, you can use DNSmasq if you prefer however, when I last looked, it doesn't install on Windows yet.
Related videos on Youtube
Comments
-
Arnab almost 2 years
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
file127.0.0.1 www.winaproduct.com
when I do
dig +short www.winaproduct.com
it returns the respective IP address of the server, not127.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 changenameserver
to127.0.0.1
in/etc/resolv.conf
.update
problem magically solved after installing
libnss3
, as a dependency ofgoogle-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 thannslookup
,dig
etc. ? -
Arnab almost 9 years
getent hosts www.winaproduct.com
is working perfectly, butnslookup
,dig
,host
etc. are only as example, I want it on firefox. -
michas almost 9 yearsIf 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.
-
Arnab almost 9 yearsthanks for the comment, I dont use any unusual firefox configuration, no it is not working with firefox(38.0.1) .
-
michas almost 9 yearsI'm very sure it is some browser issue. Try
wget
or some other browser like chrome. Ifgetent
gives the expected result all of them should. -
Arnab almost 9 yearsawesome, working perfectly with
wget
, so what is wrong with firefox , nslookup , dig etc ? I have tried afterrm -rf .mozilla
, remove any user set configuration, still not working. -
dan almost 9 years→ Arnab: As @michas correctly explained it, there is nothing wrong with
nslookup
,dig
andhost
because they just ask directly to the DNS. There is something wrong just within yourFirefox
. CheckPreferences > Advanced > Connection Settings...
, you should be onNo proxy
. -
Arnab almost 9 years@daniel Azuelos, there is nothing wrong with firefox settings, it's already using
No Proxy
. So how to tellnslookup
,dig
etc. ask/etc/hosts
file first instead asking directly to the DNS ?. Thank you for your valuable comment.