4

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?

marked as duplicate by womble Aug 13 '18 at 23:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    127.0.0.0/8 (so 127.0.0.1 - 127.255.255.255) is reserved for your host's loopback device. – cburn11 Aug 6 '18 at 16:13
  • Your host's hostname is set in /etc/hostname. – cburn11 Aug 6 '18 at 16:25
  • 2
    There are RFCs that cover the 127.0.0.0/8 block. See this question. – Ron Maupin Aug 6 '18 at 16:30
  • @cburn11 Your comment doesn't explain the difference between the two IPs. – Stefan Lasiewski Aug 6 '18 at 17:28
  • @StefanLasiewski There is a bit of difference and not a bit of difference between the two IPs. – cburn11 Aug 6 '18 at 19:19
2

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.

1

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

  • 2
    you write "section 10.4" then link section 5. (indeed 5.1.1 deals about 127.0.1.1). 10.4 is about handling source code – A.B Aug 6 '18 at 16:59
  • Correct. Copy and paste hehe... – fvillalba89 Aug 6 '18 at 17:59
  • So, the 127.0.1.1 hostname line is a placeholder, and is used if the host wasn't assigned an permanent IP address, and should be replaced with a permanent IP address if possible. Contrast that to the 127.0.0.1 localhost line, which should always exist. – Stefan Lasiewski Aug 6 '18 at 22:28
  • @CoryKnutson hem... so 10.4 was changed into 10.5 (10.5. Version control systems), not 5 (Chapter 5. Network setup) or 5.1.1 (5.1.1. The hostname resolution) ? This quote is from a probable very old Debian ch 10.4 DNS chapter that doesn't exist on debian.org anymore (eg: qref.sourceforge.net/Debian/reference/…) – A.B Aug 7 '18 at 5:53
  • 1
    @CoryKnutson The quote from the OP doesn't match the link provided by the OP anyway. So 10.4 is from an other link not provided, with a text that was completely changed (into nowadays 5.1.1), 10.5 is never ok. OP should juste quote again from the correct link he made (using section 5.1.1). as is this information is hard to corroborate with the link – A.B Aug 8 '18 at 13:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.