LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 05-23-2005, 01:40 PM   #1
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Question 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.
 
Old 05-23-2005, 01:54 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
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.
 
Old 05-23-2005, 02:09 PM   #3
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Original Poster
Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
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.
 
Old 05-23-2005, 02:19 PM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Well... I'm not gonnay play the linux guru... cause I'm not.
However, I do wanna say that I just tried and the same happens to me. nslookup is not responding to the host names I have at /etc/hosts:
Code:
[antoranz@galileo antoranz]$ cat /etc/hosts
127.0.0.1       galileo
192.168.0.11    exchange
127.0.0.1               localhost
192.168.0.206   linuxserver
192.168.0.40    isaserver
[antoranz@galileo antoranz]$ nslookup isaserver
Server:         200.44.32.12
Address:        200.44.32.12#53

** server can't find isaserver: NXDOMAIN

[antoranz@galileo antoranz]$ nslookup exchange
Server:         200.44.32.12
Address:        200.44.32.12#53

** server can't find exchange: NXDOMAIN

[antoranz@galileo antoranz]$ nslookup galileo
Server:         200.44.32.12
Address:        200.44.32.12#53

** server can't find galileo: NXDOMAIN
Any explanation?
 
Old 05-23-2005, 09:53 PM   #5
scowles
Member
 
Registered: Sep 2004
Location: Texas, USA
Distribution: Fedora
Posts: 620

Rep: Reputation: 31
Well... I'm not gonnay play the linux guru... cause I'm not.
However, I do wanna say that I just tried and the same happens to me. nslookup is not responding to the host names I have at /etc/hosts:


And it never will. As the name implies - nslookup and dig query name servers ONLY.

Although I have never looked at the source code - commands like ping are "probably" compiled to use functions like "gethostbyname", which would honer the order directive. i.e. hosts, bind.

Further reading:

man resolver
man gethostbyname
 
Old 05-23-2005, 10:11 PM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
See? I told you! :-P
 
Old 05-24-2005, 08:46 AM   #7
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Original Poster
Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
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?
 
1 members found this post helpful.
Old 10-24-2012, 06:42 AM   #8
Fravadona
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
"getent ahosts myhost.example.com"
 
Old 10-24-2012, 08:03 AM   #9
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Original Poster
Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Quote:
Originally Posted by Fravadona View Post
"getent ahosts myhost.example.com"
Wow - 7 years later...

Thanks anyway.

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.
 
Old 10-25-2012, 07:44 PM   #10
128
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Rep: Reputation: 0
Omg! waiting 7 years so bad...
 
Old 10-26-2012, 10:11 AM   #11
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Original Poster
Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Quote:
Originally Posted by 128 View Post
Omg! waiting 7 years so bad...
As an FYI I have NOT been waiting 7 years.

My point was that posting responses to a 7 year old thread when there are many "zero reply" threads for current questions seems to be ignoring the main point in this site.

I changed the status of this thread to SOLVED after the recent post and note that marking threads SOLVED wasn't an option 7 years ago.
 
Old 10-26-2012, 10:14 AM   #12
128
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Rep: Reputation: 0
Quote:
Originally Posted by MensaWater View Post
As an FYI I have NOT been waiting 7 years.

My point was that posting responses to a 7 year old thread when there are many "zero reply" threads for current questions seems to be ignoring the main point in this site.

I changed the status of this thread to SOLVED after the recent post and note that marking threads SOLVED wasn't an option 7 years ago.
already
 
Old 11-01-2012, 08:25 AM   #13
Fravadona
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by MensaWater View Post
My point was that posting responses to a 7 year old thread when there are many "zero reply" threads for current questions seems to be ignoring the main point in this site.

I changed the status of this thread to SOLVED after the recent post and note that marking threads SOLVED wasn't an option 7 years ago.
My reply was just for reference; I was having the same interogation than you 7 years ago and google pointed me to your post, which was helpful but incomplete. Now people will get the response from it.

Cheers.
 
Old 07-31-2014, 03:57 AM   #14
YoungFrog
LQ Newbie
 
Registered: Jul 2014
Posts: 1

Rep: Reputation: Disabled
Two years and a half later, I'd like to thank you, Fravadona, for answering to this thread (which means you had to subscribe and all, just to provide an answer for you fellow googlers).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(nslookup) vs (dig and host) emailssent Linux - Networking 7 10-06-2004 08:38 AM
nslookup + dig commands ptreves Linux - General 8 09-10-2004 02:46 AM
dig, nslookup rpm ashley7 Linux - Software 0 04-05-2004 08:27 AM
Dig, host, nslookup? gsibble Arch 1 02-03-2004 01:02 PM
DIG / NSLOOKUP message? matrx88 Linux - Networking 1 08-20-2003 12:15 AM


All times are GMT -5. The time now is 05:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration