Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

closed as not constructive by Zoredache, tylerl, RobM, larsks, mdpc Feb 14 '12 at 23:17

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

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 2:12

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
share|improve this answer
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
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
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 0: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 2:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.