[Fwd: /etc/hosts and /etc/host.conf confusion]

Kevin Stevens freebsd at pursued-with.net
Fri Jul 2 21:44:14 PDT 2004


On Jul 2, 2004, at 20:39, David Fuchs wrote:

> # $FreeBSD: src/etc/host.conf,v 1.6 1999/08/27 23:23:41 peter Exp $
> # First try the /etc/hosts file
> hosts
> # Now try the nameserver next.
> bind
> # If you have YP/NIS configured, uncomment the next line
> # nis

That's typical.

> 	Considering that 'hosts' is listed first, I would expect that any 
> entries I add to /etc/hosts will take precedence over entries 
> retrieved from bind.  So, I added an entry to this file for a random 
> IP-to-name mapping, and tested it with the 'host(1)' command, and it 
> failed.  When I enable debugging, it clearly shows that it's 
> consulting the first nameserver listed in resolv.conf (an external 
> host), no mention of a hosts file anywhere (or attempt to send a 
> request to the local host)

Try ping; even if the host isn't available you can see if it resolves.  
"host" does it's own thing, which is sometimes non-obvious (to me at 
least).  Look at the sections in man host about the variables it 
expects to be configured.

> Additionally, what classifies as 'when the name server is not running' 
> - does this mean that /etc/hosts is used when all the nameservers 
> listed in /etc/resolv.conf are unavailable? (As I only use the local 
> named(8) daemon to host my personal domain, not for everyday recursive 
> lookups.)  Or does it literally refer to when my local copy of 
> named(8) is not in the process list?

The latter.  For example, many workstations aren't configured to run 
named at all; they'll still reference their local hosts file.

KeS



More information about the freebsd-questions mailing list