host versus nslookup
Fajar A. Nugraha
work at fajar.net
Thu Oct 13 07:24:06 UTC 2011
On Thu, Oct 13, 2011 at 1:05 PM, listmail <listmail at entertech.com> 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,
Yes, it can be improved :)
> all it does is lookups
> in local files, not name resolution.
> I can see how this would be useful if you were not using DNS, but....????
If your purpose is to diagnose "can the DNS server used as resolver
for my server resolve a particular FQDN", then either host or nslookup
will usually suffice, with "dig" giving more detailed output.
However, if your concern is "can my program find the IP address for a
particular FQDN", then getent will give more accurate info as it also
takes into consideration the content of nsswitch.conf and the sources
listed on that file. So getent might search for local files, DNS, NIS,
or whatever source listed for "hosts" database in nsswitch.conf.
> What am I missing here?
>From the man page:
The getent program gathers entries from the specified administrative
database using the specified search keys. Where database is
one of passwd, group, hosts, services, protocols, or networks.
In this particular case we're only interested in hosts.
I found more detailed explanation in a Solaris reference, which
basically say getent asks the database source in order specified in
/etc/nsswitch.conf. So for example if your /etc/nsswitch.conf has
something like this:
hosts: files dns
and your /etc/hosts has this entry
then getent and host will give different results for
archive.ubuntu.com, since getent will search /etc/hosts first.
$ host archive.ubuntu.com
archive.ubuntu.com has address 184.108.40.206
archive.ubuntu.com has address 220.127.116.11
archive.ubuntu.com has address 18.104.22.168
archive.ubuntu.com has address 22.214.171.124
archive.ubuntu.com has address 126.96.36.199
archive.ubuntu.com has address 188.8.131.52
archive.ubuntu.com has address 184.108.40.206
archive.ubuntu.com has address 220.127.116.11
archive.ubuntu.com has address 18.104.22.168
archive.ubuntu.com has address 22.214.171.124
archive.ubuntu.com has address 126.96.36.199
archive.ubuntu.com has address 188.8.131.52
archive.ubuntu.com has address 184.108.40.206
$ getent hosts archive.ubuntu.com
on the other hand both will give same result for google.com (which is
not in /etc/hosts)
www.google.com is an alias for www.l.google.com.
www.l.google.com has address 220.127.116.11
www.l.google.com has address 18.104.22.168
www.l.google.com has address 22.214.171.124
www.l.google.com has address 126.96.36.199
www.l.google.com has address 188.8.131.52
www.l.google.com has address 184.108.40.206
$ getent hosts www.google.com
220.127.116.11 www.l.google.com www.google.com
18.104.22.168 www.l.google.com www.google.com
22.214.171.124 www.l.google.com www.google.com
126.96.36.199 www.l.google.com www.google.com
188.8.131.52 www.l.google.com www.google.com
184.108.40.206 www.l.google.com www.google.com
More information about the bind-users