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

Bug#247734: /etc/hosts: Two lines with the same IP address?



On Tue, 2004-06-08 at 15:48, Andrew Suffield wrote:
> On Tue, Jun 08, 2004 at 02:40:55PM +0200, Thomas Hood wrote:
> >     127.0.0.1	localhost
> >     127.0.0.1	pingo

> The above two lines *must* be precisely equivalent to *one* of the
> following four lines:
> 
> 127.0.0.1 localhost
> 127.0.0.1 pingo
> 127.0.0.1 localhost pingo
> 127.0.0.1 pingo localhost
> 
> Off the top of my head I couldn't tell you which one it is. But under
> the NSS interface, it must be one of them, because that is what
> gethostby*() is going to return to applications.

With

    127.0.0.1	localhost
    127.0.0.1	pingo

if you look up "pingo" then you get "pingo" as the canonical host name;
and if you look up "localhost" then you get "localhost" as the canonical
host name.  That's different from getting either one or the other as
the canonical host name for both.

Also, as you noted later, it does make a difference to getent and it
could make a difference to other programs that read /etc/hosts
directly.


> Note that #247734 contains confusing misinformation. It uses host(1),
> which ignores /etc/hosts and uses DNS directly - and DNS can represent
> things which NSS cannot.

The experiments with "host" were illustrations of the results you
get from dnsmasq, which reads /etc/hosts.


On Tue, 2004-06-08 at 15:40, Steve Langasek wrote: 
> > Is it legal for /etc/hosts to contain two lines with the same
> > IP address?  In particular, is the following legal?:
> 
> No, these would be duplicate keys and one of the two will never be
> used (or they'll be used inconsistently).

It's clear that both are used because one can look up the IP
address for either 'localhost' or 'pingo'.

What do you mean by 'used inconsistently'?


Steve Langasek continued:
> See other responses for the fix for this; but, er, why would you want
> the canonical name for 127.0.0.1 to be anything other than "localhost"
> anyway?  That just invites confusion, IMHO.

The answer, I guess, first, is that "hostname --fqdn" has to succeed
even if one's machine isn't connected to any network and even if it
doesn't have a fixed public IP address -- otherwise sudo complains. 
So it seems reasonable for one's hostname to resolve to 127.0.0.1.

Second, one wants "hostname --fqdn" to yield the hostname, not "localhost".

But maybe these are things that one should not want.


On Tue, 2004-06-08 at 15:16, Tore Anderson wrote: 
> Set 'pingo' as the first in the list.

But then the canonical host name of localhost is "pingo".  That, I
suppose, is what S.L. would condemn as confusing.  :)


>  On a related note, I've never quite understood why the installer
>  insists that the domain name must not be part of the hostname.  Quite
>  annoying, really.

One reason may be the following.  If the hostname is a FQDN "foo.bar.baz"
and /etc/resolv.conf contains no "domain" option then the latter defaults
to "bar.baz".

What I'm looking for in this thread are reasons why it's not fine
after all to have multiple lines with the same IP address.
--
Thomas




Reply to: