host versus nslookup

Phil Mayers p.mayers at imperial.ac.uk
Thu Oct 13 08:39:31 UTC 2011


On 10/13/2011 07:05 AM, listmail wrote:
> On Thu, 13 Oct 2011 03:33:30 +0700, Fajar A. Nugraha wrote
>> If you're concern about what address programs gets when they resolve
>> host names, then getent is a better choice as it also respects
>> nsswitch.conf and hosts file.
>>
> According to the (almost useless) manpage for getent, all it does is lookups
> in local files, not name resolution.

It uses whatever "hosts" database plugins for nsswitch are enabled. In 
most cases, this is:

hosts:      files dns

At least under recent versions of glibc, there are actually several 
modes you can use it in:

getent hosts - list all static hosts entries
getent hosts key - calls gethostbyname2(key)
getent ahosts key - calls getaddrinfo(AF_UNSPEC, key)
getent ahostsv4 key - calls getaddrinfo(AF_INET, key)
getent ahostsv6 key - calls getaddrinfo(AF_INET6, key)

There's no question in my mind that "getent hosts key" or "getent ahosts 
key" are the appropriate tools to duplicate "normal" app name 
resolution, because the utility mirrors the API most apps will call.

But you usually need to run "dig" to compare raw DNS and find the different.

nslookup should be taken out into the woods and left there... it's a 
horrible program.



More information about the bind-users mailing list