127.0.0.1 VS 127.0.1.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 the IP address is 127.0.0.1 by default.
127.0.0.1 localhost
Debian, then Ubuntu, choose to define 127.0.1.1 for mapping the IP address of your host_name in case that you have no network.
The host_name matches the hostname defined in /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