[SOLVED] nslookup, host, dig not resolving entries in /etc/hosts
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
nslookup, host, dig not resolving entries in /etc/hosts
Entries in my /etc/hosts file on a RedHat AS 3.0 installation are not being resolved when I use nslookup. (Also when I use "dig" or "host" utilities.)
The entries DO get resolved when I use ping though.
Does anyone have a clue as to why this should be?
I've spent the morning looking through the web and the forums here but can't see this problem. The closest I saw was someone who had the opposite problem (ping didn't resolve but nslookup did). The details there didn't help. The info about /etc/host.info and libnss* was new to me but have both been checked.
Already checked based on my reading:
/etc/hosts - Yes it has the entries for which I'm looking.
/etc/resolv.conf - Yes it has my DNS servers correctly defined. (DNS queries are resolving correctly.)
/etc/nsswitch.conf - Yes it has "files" BEFORE "dns" for the "hosts:" line.
/etc/host.conf - Yes it has "hosts" before "bind" for the "order" line.
/lib/libnss_files.so.1 & /lib/libnss_files.so.2 do exist.
All the above files are world readable and the libnss* ones are world executable.
I know that nslookup is deprecated but as noted above I can't resolve with either the host command or the dig command.
Using the above commands I successfully resolve entries from my DNS servers. The problem appears to be that it is ignoring the /etc/hosts entries only.
This started out as a search for how to force reverse lookup to use the domain name specified for the host itself from its own /etc/hosts file. This was because it appears it was getting the reverse lookup from DNS instead. However on testing by adding a bogus remote host I found even a regular lookup doesn't seem to read /etc/hosts. Since ping works I'm assuming gethostbyname is working fine.
On checking my Debian Linux workstation I found I'm having the same problem.
On testing my HP-UX servers using exactly the same /etc/hosts entries there are no problems.
Since I'm relatively new to Linux administration I suspect it is some simple configuration item I'm missing. However everything read today suggests that the things I've mentioned as having checked above are the only things necessary to have this work.
My guess is that nslookup and dig and so on are made to query dns servers... and so will use the dns servers that you have set up at /etc/resolv.conf.... or the server you tell them to use... and so, they won't take a look at /etc/hosts.
Your guess doesn't seem likely. It certainly isn't true for Unix so I wouldn't expect it to be for Linux. From my (albeit somewhat limited) Linux experience most Linux utilitilies have enhanced functionality over their Unix counterparts.
Well - I can see that it does NOT resolve however IHMO this is a flaw (read bug) in Linux.
As to what the "name implies" I'll say it implies only "name server" NOT "Dynamic Name Server". DESPITE this nslookup in all Unix flavors I've worked on (AT&T, NCR, SCO, Solaris, HP-UX, AIX) has always resolved from /etc/hosts so long as "files" was specified in the appropriate entry in /etc/nsswitch.conf. Note that NIS is also a "name server". The names of "dig" and "host" don't imply anything though I'll admit the man pages for all in Linux mention only DNS.
Perhaps the reason nslookup is being deprecated in favor of dig and host is due to the confusion caused by this basic funtionality difference between Unix and Linux. Just because people have learned to live with this inadequacy in Linux doesn't mean its the way it should be. Common troubleshooting for insuring one is resolving correctly in Unix has always been to use nslookup to see what it returned then check the /etc/hosts, /etc/resolv.conf and /etc/nsswich.conf files.
As an FYI: I DID read the man page for gethostbyaddr before posting. It clearly states it parses /etc/hosts. Telling me to read it was pointless since you say nslookup doesn't use it.
Anyway enough of that - lets change the question to:
Is there a pebuilt utility that allows one to resolve names or IP addresses whether they come from /etc/hosts, DNS or NIS in Linux?
If you want to help you might want to help folks with more current questions: Zero Reply Threads
Anyway just to finish out this thread:
It turned out that HP-UX had a specific version of nslookup written to check /etc/hosts AND name servers whereas most other commercial UNIX variants and Linux do NOT.
Also nslookup is deprecated by ISC the makers of BIND. You should use the "host" command where available instead. You should use "dig" for troubleshooting DNS lookups. Neither of those will interrogate /etc/hosts though.