In my /etc/hosts file, I have two lines:
127.0.0.1 localhost
127.0.1.1 hostname
What is the difference between the two lines, where do I find the host name?
In my /etc/hosts file, I have two lines:
127.0.0.1 localhost
127.0.1.1 hostname
What is the difference between the two lines, where do I find the host name?
The other answer quotes an obsolete bogus reference which doesn't match the link and doesn't look like it will be corrected. Here is the correct quote from today's Debian Reference Manual:
5.1.1. The hostname resolution
For example, "/etc/hosts" looks like the following.
127.0.0.1 localhost 127.0.1.1 <host_name>
[...]
Each line starts with a IP address and it is followed by the associated hostname.The IP address 127.0.1.1 in the second line of this example may not be found on some other Unix-like systems. The Debian Installer creates this entry for a system without a permanent IP address as a workaround for some software (e.g., GNOME) as documented in the bug #719621.
The <host_name> matches the hostname defined in the "/etc/hostname".
For a system with a permanent IP address, that permanent IP address should be used here instead of 127.0.1.1.
For a system with a permanent IP address and a fully qualified domain name (FQDN) provided by the Domain Name System (DNS), that canonical
<host_name>.<domain_name> should be used instead of just <host_name>.
For the curious in bug #719621 there's a link to a discussion list discussing about the very same subject "127.0.0.1 vs. 127.0.1.1". It also mentions that Fedora uses 127.0.0.2
for the same purpose. Indeed it appears a slightly different mechanism is in use on Fedora for this.
For example, in Section 10.5 of the Debian Reference Manual:
Some software (e.g., GNOME) expects the system hostname to be resolvable to an IP address with a canonical fully qualified domain name. This is really improper because system hostnames and domain names are two very different things; but there you have it. In order to support that software, it is necessary to ensure that the system hostname can be resolved. Most often this is done by putting a line in /etc/hosts containing some IP address and the system hostname. If your system has a permanent IP address then use that; otherwise use the address 127.0.1.1.
https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#s-net-dns