Re: /etc/hosts hostname alias
On Thu, 30 Dec 2004 20:10:08 +0100, Frank Lenaerts wrote:
> Can someone tell me why the hostname of a machine is added as an alias
> for 127.0.0.1 to /etc/hosts during the installation i.e. why do we
> have something like this in /etc/hosts?
>
> --- begin ---
> 127.0.0.1 localhost.localdomain localhost pluto
> --- end ---
The answer is that some utilities need to be able to resolve the hostname
to an IP address. If a machine has no permanent network interface with a
static IP address then the best alternative is to resolve the hostname to
a loopback address.
IMHO it is better to set up /etc/hosts like this:
127.0.0.1 localhost.localdomain localhost
127.0.1.1 pluto.plutosdomain pluto
The advantage of this is that it makes the fully qualified hostname its
own canonical host name and it makes localhost.localdomain the canonical
host name of localhost. If these are conflated by assigning them the same
IP address then the result is, inevitably, that one is the canonical host
name of the other, which can be confusing.
Of course if you have a permanent network interface with a static address
then it is best to use that instead of 127.0.1.1. E.g.,
127.0.0.1 localhost.localdomain localhost
138.45.1.8 pluto.plutosdomain pluto
> Having the hostname as alias for the localhost IP address already got
> me in troubles two times:
>
> (1) When adding a new host to a Kerberos realm. It took me quite some
> time to find out why I could not login to a newly added machine
> (using the same procedure as on my Woody boxes). Part of the
> problem was the fact that /etc/hosts contained the hostname (not
> fully qualified) as alias for 127.0.0.1.
You don't say what the real problem was so I can't comment.
> (2) When creating a sudoers file with Host_Alias definition. Using the
> (short) hostname makes that sudo keeps asking for a password while
> it should not. Using the IP address or deleting the hostname alias
> in /etc/hosts resolves this issue.
If I remove my hostname from /etc/hosts then I get this error message from
sudo:
jdthood@thanatos:~$ sudo ls
sudo: unable to lookup thanatos via gethostbyname()
> BTW, note that the output of hostname --fqdn shows
> localhost.localdomain. Deleting the alias shows the correct fully
> qualified hostname.
>
> Thus, why is the hostname added as an alias for 127.0.0.1?
One reason: To get rid of the error message from sudo. I believe that
there are other reasons but I can't remember offhand what they are. There
have been long discussions about this on debian-devel which may be
enlightening. Here is a thread that I started in June 2004:
http://lists.debian.org/debian-devel/2004/06/msg00443.html
This is not the only thread that has touched on this topic.
--
Thomas Hood
Reply to: