4

How is 127.0.0.1 related to 127.0.0.2?

Using ssh to login to tleilax (OpenSuSE):

tleilax:~ # 
tleilax:~ # hostname
tleilax
tleilax:~ # 
tleilax:~ # hostname -f
tleilax.bounceme.net
tleilax:~ # 
tleilax:~ # cat /etc/hosts
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.
# Syntax:
#    
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#

127.0.0.1       localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts
127.0.0.2       tleilax.bounceme.net tleilax
tleilax:~ # 
tleilax:~ # exit
logout
Connection to 192.168.1.4 closed.

logged into doge (Ubuntu):

thufir@doge:~$ 
thufir@doge:~$ hostname
doge
thufir@doge:~$ 
thufir@doge:~$ hostname -f
doge.bounceme.net
thufir@doge:~$ 
thufir@doge:~$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   doge.bounceme.net   doge

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
thufir@doge:~$ 

My understanding is that 127.0.0.1 and 127.0.1.1. are, at least in Ubuntu, used for the hostname:

Somme years ago Thomas Hood started a discussion[0] about how the system
hostname should be resolved.
The eventual result[1] was that Debian nowadays ships /etc/hosts like
these per default:

127.0.0.1 localhost
127.0.1.1 <host_name>.<domain_name> <host_name>

As also described in the Debian reference[2].

I had a short mail conversation with Thomas and he proposed bringing up
the following at d-d.

https://lists.debian.org/debian-devel/2013/07/msg00809.html

On tleilax I used yast -- why does it give an IP address of 127.0.0.2? Is that any different from 127.0.0.1? Is it just an artifact of using yast?

Finally, will it muck up yast in any way were I to change 127.0.0.2 to 127.0.0.1? I'm guessing it doesn't really matter -- I'm more curious about it.

To what extent is this just convention within each distro, versus a wider requirement for how IPv4 addresses work?

  • 1
    This page (Common Hostname Problem on Linux) advises against mapping your host's name to a loopback address (127.something) because "Many programs need to determine their own IP address so that they can tell other machines how to contact them. This doesn't work with the default /etc/hosts on many Linux machines," ... – Scott Feb 23 '15 at 5:40
  • Curious. For doge I entered the FQDN during install, Ubuntu populated the hosts file. For tleilax yast populated the hosts file (OpenSuSE). – Thufir Feb 23 '15 at 5:42
  • 1
    @Scott the advice on that page seems to be a bit outdated; if a host is able to tell another host how to contact them, they have already established a network connection, from which the other machine can easily get the IP address of the sender. the proposed scheme doesn't take NATting (the local IP address doesn't help in contacting the host; a very common case) nor multihomed hosts (where a host as multiple IPs; a not-so-common case) into account; it also doesn't deal with DHCP (the local IP changes often and is thus illsuited for a static file like /etc/hosts; also very common) – umläute Mar 3 '15 at 9:34
2

your loopback devicelo is bound to the network 127/8 (aka 127.0.0.1/255.0.0.0), thus any address in the range 127.0.0.1 to 127.255.255.254 is your local loopback.

therefore, it doesn't matter whether you use 127.0.0.1 or 127.0.0.2.

the reason why they (Debian) chose the scheme they chose are explained in the Debian-reference (and it's really a workaround for a bug)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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