/etc/hosts and /etc/host.conf confusion

David Fuchs david at davidfuchs.ca
Tue Jun 22 11:36:28 PDT 2004


Hello,

	I'm having some difficulties understanding the semantics behind the 
resolver in FreeBSD, and how /etc/host.conf, /etc/hosts, and 
/etc/resolv.conf fit together.

	The manpage 'host.conf(5)' states:

	"The host.conf file holds part of the configuration for the resolver of 
FreeBSD.  It describes what services (e.g., DNS or yp(8)) the C library 
resolving routines (like gethostbyname(3)) will use, and their order of 
use, when resolving host names or addresses."

	Well that explanation sounds good to me.  My /etc/hosts file looks like 
this:

# $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

	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, no mention of a hosts file anywhere.

	As an addition to this, the manpage 'hosts(5)' states the following:

	"When using the name server named(8), this file provides a backup used 
when the name server is not running."

	Would someone please clarify this, as it seems to contradict my default 
'host.conf(5)' file in /etc, which explicitally states that /etc/hosts 
will be consulted before bind.

	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 
daemon to host my domain, not for everyday recursive lookups.)  Or does 
it literally refer to when my local copy of named(8) is not functioning?

	Thanks in advance for clearing things up for me.

-- 
Thanks,
-David Fuchs


More information about the freebsd-questions mailing list