• 4
name Punditsdkoslkdosdkoskdo

Why does the host command not to resolve entries in /etc/hosts?

I have the following /etc/hosts file on a ubuntu 12.04 machine localhost puppetmaster

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

However the host command does not resolve the name puppetmaster correctly, while the telnet command is does

root@ip-10-248-34-162:/home/ubuntu# host puppetmaster
Host puppetmaster not found: 3(NXDOMAIN)

root@ip-10-248-34-162:/home/ubuntu# telnet puppetmaster 8140
Connected to
Escape character is '^]'.

Why does the host command not resolve entries in /etc/hosts?

The host program uses libresolv to perform a DNS query directly, i.e., does not use gethostbyname.

Most programs, when attempting to connect to another host, invoke the gethostbynamesystem call or a similar function. This function obeys the configuration of /etc/nsswitch.conf. This file has a line which in Ubuntu 12.04 defaults to the following:

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

which means that it will first use /etc/hosts, then fall back to DNS queries.

If you want to perform a host lookup this way, you can do this with getent hosts. For example:

$ getent hosts

I hope this helps.

  • 0
Reply Report

check the file /etc/nsswitch.conf and look for the line starting with word "hosts"? Do you see the word "files" on this line ? If yes, is it before or after the word "dns" ?

On a normal system, this line should be something like

hosts      files dns

if yours is not present or in different order, that might be your problem.

  • 0
Reply Report