How does the Host command query DNS?

Chris Adams linux at cmadams.net
Wed Apr 23 17:31:41 UTC 2014


Once upon a time, Robert Moskowitz <rgm at htt-consult.com> said:
> I have noticed that the Host command is always returning first IPv4
> addresses, and then IPv6 addresses.  So I asked on the BIND list can
> got the following:

You asked the BIND list a different question than you are asking here.
BIND returns the record type requested, in random order when there is
more than one (e.g. multiple A records).  To get multiple types, you
have to send multiple queries (ANY is special).  The "host" command-line
tool does not duplicate the way an application does lookups.  "host"
(per the man page) specifically by default looks up A, AAAA, and MX, in
that order.

Applications on the other hand use a few different library calls to
convert names to addresses, most commonly gethostbyname() (old,
IPv4-only) or getaddrinfo() (new, can handle multiple address families).
For modern applications that use getaddrinfo(), the default is to follow
the ordering rules defined in RFC 3484 that (in general) put IPv6
addresses ahead of IPv4 addresses.

You can control some of the ordering with /etc/gai.conf; see "man
gai.conf" for more info.

-- 
Chris Adams <linux at cmadams.net>


More information about the users mailing list