[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: where is /etc/hosts supposed to come from?

On 2009-12-29 18:49:00 +0100, Gabor Gombas wrote:
> On Tue, Dec 29, 2009 at 02:52:44PM +0100, Vincent Lefevre wrote:
> > When the machine is correctly configured (i.e. really has a FQDN),
> > "hostname -f" is reliable.
> No, it is not. "hostname -f" can return one value only, while a host may
> have dozens or hundreds of valid FQDNs.

Well, the node name is unique. From that, you'll obtain the FQDN with
either the obsolete function gethostbyname or the new POSIX function
getaddrinfo (by using the AI_CANONNAME flag). POSIX says:

  If the AI_CANONNAME flag is specified and the nodename argument is
  not null, the function shall attempt to determine the canonical name
  corresponding to nodename (for example, if nodename is an alias or
  shorthand notation for a complete name).

And here's what the getaddrinfo(3) man page says under Debian:

  If hints.ai_flags includes the AI_CANONNAME flag, then the ai_canonname
  field of the first of the addrinfo structures in the returned  list  is
  set to point to the official name of the host.

Then you need to configure your machine according to the spec, i.e.
you need a single FQDN / canonical name / official name of the host.

> Example: there is a router box called "gw" which has about a dozen
> addresses that resolve to "gw.<domain>" for just as many domains. Some
> addresses even share the same NIC. Which FQDN should "hostname -f"
> display?

This doesn't really matter. The FQDN may also be another name, i.e.
the nodename may be something more meaningful than "gw".

But host names (like www.debian.org) can also resolve to several IP
addresses corresponding to different machines. So, make use that the
FQDN doesn't correspond to such a host name.

> Why that one, and not some other?

You should ask this question to those who configured such routers
(but this would be more a practical matter, as you may have plenty
of choices).

> I've submitted a patch for hostname (#562830) to add two new options:
> one that displays all IP addresses of the host, while the other displays
> all the FQDNs for those addresses.

A FQDN is not associated with an IP address, but with a host. You
cannot call them FQDN, which already has a well-established meaning.

If I understand correctly, you do a reverse DNS lookup. Now, I'm
wondering... Can a hostname obtained by reverse DNS lookup resolve
to different IP addresses?

> Neither relies on the value returned by gethostname(), so "the
> hostname must be an FQDN" misbelief together with any usage of
> "hostname -f" can die a silent death.

"hostname -f" just follows the POSIX notion of canonical name (a.k.a.
FQDN). So, I doubt it will die.

Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)

Reply to: