Linux – Why does the hostname appear with the address 127.0.1.1 rather than 127.0.0.1 in /etc/hosts

defaultshostnamelinuxlocalhostloopback

This may be a bit of a noobish question, but I was taking a look at /etc/hosts on my new Xubuntu install and saw this:

127.0.0.1 localhost
127.0.1.1 myhostname

On most 'nixes I've used, the second line is omitted, and if I want to add my hostname to the hosts file, I'd just do this:

127.0.0.1 localhost myhostname

Is there a difference between these two files in any practical sense?

Best Answer

There isn't a great deal of difference between the two; 127/8 (eg: 127.0.0.0 => 127.255.255.255) are all bound to the loopback interface.

The reason why is documented in the Debian manual in Ch. 5 Network Setup - 5.1.1. The hostname resolution.

Ultimately, it is a bug workaround; the original report is 316099.