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

Re: /etc/hosts and resolving of the local host/domainname - 127.0.0.1 vs. 127.0.1.1



On 30-07-13 22:57, Russ Allbery wrote:
> Christoph Anton Mitterer <calestyo@scientia.net> writes:
> 
>> - The system hostname (and domainname if any) should ALWAYS be
>> resolvable, whether a network is up or not, regardless of which.
>> (Assuming that lo is always up, if not, many things break anyway.)
> 
> This principal (and the general UNIX tradition of putting the local host
> and IP address in /etc/hosts) has caused us no end of problems, since that
> information inevitably gets out of date when systems are moved around or
> re-IP'd.  We now do not put the local hostname anywhere in /etc/hosts, and
> I believe that's the correct configuration for any system with stable DNS
> and network.

Agreed; however, for mobile systems, assuming stable networking (or even
the existence of any networking at all) is just plain wrong; and since
there are very good reasons why "ping $(hostname)" and similar things
should work, I think at least a single line with the local hostname
should be in /etc/hosts.

I think using 127.0.1.1 is a bad idea; I wasn't part of the original
discussion, but I've only ever seen problems with it, and I never
understood why we switched to that in the first place. The right way, in
my opinion, is that /etc/hosts should look like this:

127.0.0.1	localhost
127.0.0.1	hostname.domain	hostname

or, alternatively:

127.0.0.1	hostname.domain	hostname	localhost

both make "hostname" output the hostname as specified in /etc/hostname,
and "hostname --fqdn" output the FQDN. It also doesn't result in any
problems with IP address changes in my experience, since 127.0.0.1
should always be correct; the only exception is when the hostname is
actually _changed_, but then you have to change other files anyway
(/etc/hostname, for instance), so at that point it shouldn't matter too
much.

-- 
This end should point toward the ground if you want to go to space.

If it starts pointing toward space you are having a bad problem and you
will not go to space today.

  -- http://xkcd.com/1133/


Reply to: