127.0.1.1 in /etc/hosts

Tom H tomh0665 at gmail.com
Tue Nov 28 10:42:59 UTC 2017


On Mon, Nov 27, 2017 at 5:47 PM, Stuart McGraw <smcg4191 at mtneva.com> wrote:
>
> What is the meaning of the line:
>
> 127.0.1.1 mymachine.xxx mymachine
>
> in my /etc/hosts file? It was put in there by a Xubuntu-17.10
> install (or to be more accurate, an Ubuntu server-17,10 + Xubuntu
> package install.) I am installing some backup software (bacula)
> which for reasons I haven't delved into, dislikes (as in breaks)
> when it resolves "mymachine"s address and ends up with 127.0.0.1
> which is what happens when the above line is present in /etc/hosts.
>
> Will I break something else if I remove or replace the line
> with the machine's "real" ip address which keeps bacula happy,
> eg:
>
> 10.10.200.85 mymachine.xxx mymachine

You can replace the 127.0.1.1 line with the 10.10.200.85.

The 127.0.1.1 is useful for the hostname to be resolvable on
dhcp-provisioned systems. IIRC, there was a version (or were versions)
of Ubuntu where NM would edit "/etc/hosts" to insert the current dhcp
ip address.

Another solution would be to install "libnss-myhostname". It's a
subpackage of the "systemd" source package (like "udev"). It's not
installed by default because one of Ubuntu's core developers dislikes
it, IIRC, because he considers incompatible with Debian's 127.0.1.1
setup.

The output below is from my laptop with "libnss-myhostname" installed
and an EMPTY "/etc/hosts". [For some reason, Lennart chose to
associate 127.0.0.2 to a system's hostname rather than 127.0.1.1.
Debian and Ubuntu used to switch 127.0.0.2 to 127.0.1.1 but it looks
like this patch has been dropped.]

th at tosh ~ $ grep VERSION /etc/os-release
VERSION="18.04 LTS (Bionic Beaver)"
VERSION_ID="18.04"
VERSION_CODENAME=bionic

th at tosh ~ $ dpkg -l libnss-myhostname | grep ^ii
ii libnss-myhostname:amd64 235-2ubuntu3 amd64 nss module providing
fallback resolution for the current hostname

th at tosh ~ $ grep hosts /etc/nsswitch.conf
hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]
dns myhostname

th at tosh ~ $ cat /etc/hosts

th at tosh ~ $ cat /etc/hostname
tosh

th at tosh ~ $ getent hosts 127.0.0.1
127.0.0.1 localhost

th at tosh ~ $ getent hosts 127.0.1.1

th at tosh ~ $ getent hosts 127.0.0.2
127.0.0.2 tosh

th at tosh ~ $ getent hosts 192.168.1.223
192.168.1.223 tosh

th at tosh ~ $ getent hosts tosh
fe80::e294:67ff:fe87:6aae tosh

th at tosh ~ $ getent ahosts tosh
fe80::e294:67ff:fe87:6aae STREAM tosh
fe80::e294:67ff:fe87:6aae DGRAM
fe80::e294:67ff:fe87:6aae RAW
192.168.1.223 STREAM
192.168.1.223 DGRAM
192.168.1.223 RAW

th at tosh ~ $




More information about the ubuntu-users mailing list