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

Re: localhost.localdomain



On Fri, 2005-10-07 at 16:26 +0200, Christoph Haas wrote:

> The problem is probably that the "localhost.localdomain" stands before
> "localhost" in that line. So if you "reverse resolve" 127.0.0.1 you
> end up with "localhost.localdomain" which some applications don't understand.

Christopher hits the nail on the head.  There are two separate issues:

1 - Is there a reason to have localhost.localdomain
2 - If there is localhost.localdomain should *not* precede localhost!

I'm not going to comment on the former but the latter is a *BIG* deal.
The current Debian /etc/hosts file is flat out wrong.  When a call to
gethostbyname(3) or gethostbyaddr(3) and an IPV4 address of 127.0.0.1 is
supplied, it should return "localhost".  Provided resolv.conf is
configured to use files and then dns, gethostbyname/gethostbyaddr is
going to query /etc/hosts.  In /etc/hosts multiple hostnames can be
assigned to a single address, but when resolving an address to a
hostname, the *first* hostname in the list is returned by
gethostbyname/gethostbyaddr.

Every sane implementation of IP returns "localhost" when querying
127.0.0.1.  It doesn't matter if the implementation
uses /etc/hosts, /etc/inet/hosts, /boot/beos/etc/hosts, or (*gulp*) c:
\winnt\system32\drivers\etc\hosts.

Of course, other systems ship with a default hosts file containing
something in addition to "localhost" that resolves to 127.0.0.1.  The
issue with Debian is that "localhost.localdomain" comes *before*
"localhost".  A call to gethostbyname() to resolve localhost returns a
struct referring to 127.0.0.1.  A call to gethostbyname() to resolve
127.0.01 returns a struct referring to localhost.localdomain.  This is
*wrong*.

This has been mentioned before, but I'll say it again.  This is solely
because the Debian /etc/hosts reads:
127.0.0.1       localhost.localdomain localhost

"localhost.localdomain" and "localhost" must be swapped.  The first
entry in the list of hosts *must* be "localhost".

Just as a sanity check, Solaris ships with:
127.0.0.1	localhost loghost

FreeBSD ships with:
127.0.0.1       localhost localhost.my.domain myname.my.domain

I don't have access to AIX, HPUX or other major Unices, but I bet in the
hosts file, 127.0.0.1 is immediately followed by localhost -- and other
aliases follow localhost.  "localhost" *must* be first.

-Jeff



Reply to: