2

I was struggling trying to find out the reason why the linux host utility was ignoring my /etc/hosts file until I find the answer to my question here: hosts file seems to be ignored:

With this configuration, most applications will happily work with your entry from /etc/hosts. However host doesn't look at /etc/nsswitch.conf. That is by design, not by accident, since host is specifically a DNS lookup program. /etc/hosts is not DNS, it's (mostly) what we used before we had DNS.

However, as far as I'm concerned, the utility didn't use to behave like this back in the not-so-old days.

I'm pretty sure host DID check the /etc/hosts file...

Am I just going crazy after a very tough day or am I correct?

If I'm correct, does anyone know why and when they changed it?

I noticed it on CentOS 5.6 and 6.0 servers.

Luis Fernando Alen
  • 540
  • 1
  • 5
  • 11
  • AFAIK, since always. I have seen this behavior on Debian at least for the last decade. – Zoredache Feb 14 '12 at 22:39
  • Weird... I think that's not what I noticed on some Debian distributions I administered 3 years ago. I know, it's hard to recall precisely, but something makes me think it did check the hosts file. – Luis Fernando Alen Feb 15 '12 at 02:12

1 Answers1

5

This sounds like a complaint, not a question.

host does a DNS lookup and is distributed as part of the bind DNS system. It doesn't resolve a name, which could involve not only /etc/hosts and DNS, but could also involve YP, LDAP, NMB (samba), and any other nss plugin.

If you're interested in a "normal" host resolution, you can use the getent utility (which you won't be surprised to learn is part of coreutils, along with libnss).

getent hosts google.com
tylerl
  • 14,885
  • 7
  • 49
  • 71
  • Sorry if it sounded like a complaint. That was not my intention although I was intrigued enough to strace the utility. And yes, I know it's part of the bind-utils package. I just wanted to know if it's changed because I'm pretty sure it used to check the hosts file before... – Luis Fernando Alen Feb 14 '12 at 23:04
  • 1
    nope. checking /etc/hosts is part of libnss, which is a resolution path independent of DNS (and which might not involve DNS at all!) – tylerl Feb 14 '12 at 23:08
  • 1
    There are a few different utilities that I have seen with the name host. Perhaps one of them acts differently. – Zoredache Feb 15 '12 at 00:41
  • Yeah, good point. I'll start digging and try to find out. Thanks for the tip, Zoredache. – Luis Fernando Alen Feb 15 '12 at 02:19