What is difference between localhost address 127.0.0.1 and 127.0.1.1

Solution 1:

As your machine gets started, it will need to know the mapping of some hostnames to IP addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In the absence of a name server, any network program on your system consults this file to determine the IP address that corresponds to a host name.

The loopback device is a special, virtual network interface that your computer uses to communicate with itself. It is used mainly for diagnostics and troubleshooting, and to connect to servers running on the local machine.

the loopback is interface lo and ip 127.0.0.1 by default

127.0.0.1 localhost

Debian than ubuntu choose to define 127.0.1.1 for mapping the ip of your host_name in case that you have no network

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.

127.0.1.1 host_name

Solution 2:

It doesn't really mean anything in particular (it's just another IP in the 127.0.0.0/8 block).

The reason it's used as the IP for your hostname is explained in Section 10.4 of the Debian Reference Manual.

Quote:

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.

Solution 3:

The following screen capture tells an interesting story.

Ubuntu default /etc/hosts file and ifconfig output

Effectively, it shows that 127.0.0.1 is the true loopback address. Thus, 127.0.1.1 is there for reasons other than that of basic IP networking.

As mentioned by @Videonauth, the 127.0.1.1 line is there as a crutch, a fix, to make finicky software be happy.

In my view, the loopback entry should almost always be in /etc/hosts. If you change your hostname from the default of localhost, then change the host name on the 127.0.1.1 line, not the 127.0.0.1 line.

If you change your hostname and give your machine a static IP, change both the hostname and IP fields in the 127.0.1.1 line.

In short, leave the 127.0.0.1 record alone.

Solution 4:

127.0.0.1 is the loopback address, commonly known as localhost, which is the name that resolves to it by the local hosts file. This file is in different locations depending on the OS, but in most Linux distros it is in /etc/hosts. This address always refers to the computer which made the request, so 127.0.0.1 is not a "real" address so to speak. Each device has it's own localhost. 127.0.1.1 on the other hand is used by certain software to mean the same thing, an alias in a way, but not really. The loopback address used by your machine internally should be 127.0.0.1, so don't mess around with that address in your hosts file!