- “Are all
127.x.x.x
addresses restricted to the local machine?” Yes
- “Are all
127.x.x.x
addresses bound to the lo
interface” Yes
- “Are
127.x.x.x
addresses routed over the network?” No
127.0.0.0/8 - This block is assigned for use as the Internet host loopback address. A datagram sent by a higher-level protocol to an
address anywhere within this block loops back inside the host. This
is ordinarily implemented using only 127.0.0.1/32 for loopback. As
described in [RFC1122], Section 3.2.1.3, addresses within the entire
127.0.0.0/8 block do not legitimately appear on any network anywhere.
— RFC5735
- “Is
127.0.0.2
the same as 127.0.0.1
?” NO
While 127.0.0.1
to 127.255.255.254
are all local addresses bound to interface lo
. They are not the same. You can use each address to bind a different service onto the same port. E.g 16 Million web-servers on port 80, only accessible from the local machine (If you don't run out of memory, or other resource first)
I have just set up a docker service to bind to 127.0.0.2:80
. I have then added an alias to /etc/hosts
. Now I can connect to it via http://myserver
, but not via http://127.0.0.1
or http://localhost
. However it is only available to this machine. As it is, only, on the lo
interface.
I then set up another docker service to bind to 127.0.0.3:80
, and a python service on localhost:80
and another on 127.0.0.4:80
.
This may not work on all operating systems.
I am using Debian(9) Gnu/Linux, Linux kernel 4.9.0-3-amd64. Some OSs may treat all addresses 127.0.0.1
→ 127.255.255.254
the same. Some may only work with 127.0.0.1
.
see also
7
Need to mention that it is not the same in OS X, which only 127.0.0.1 route to loopback. See here.
– Wenbing Li – 2014-09-08T00:54:46.5676@CMCDragonkai 127.0.0.1 and 127.0.0.124 may be on the same interface but they are not the same address. One might use an uncommon ip like 127.0.0.2 if one wants to use set up a service on a common port and not interfere with other services that may be listening to that same port on 127.0.0.1 – Keith Reynolds – 2015-08-19T03:21:37.230
This answer seem 99% correct, just the summary line at the start is wrong. see https://superuser.com/a/1255308/62123
– ctrl-alt-delor – 2017-11-26T19:20:49.333This answer is 99% correct when measured by characters, but 99% wrong when measured by meaning. Yes they are the same network (as are 192.168.x.x), but they are not the same, hence the different numbers. – ctrl-alt-delor – 2019-04-12T16:11:39.713
The Wikipedia page has since changed, and now says "although any address in the range 127.0.0.1 to 127.255.255.254 is mapped to it", rendering the gist of this answer in direct conflict with Wikipedia. – SilverSkin – 2012-09-18T12:06:26.493
7@SilverSkin Would you mind explaining what you mean? The only difference between what's in answer and what's in Wikipedia now is that they (correctly) excluded 127.0.0.0 and 127.255.255.255, which are network / broadcast addresses. The gist is still the same - 127.x.x.x == 127.0.0.1 (except for 127.0.0.0 and 127.255.255.255, which is expected on any /8 network). – icyrock.com – 2012-09-20T01:17:43.130
1So there's no difference between binding to 127.0.0.1 versus binding to 127.0.0.124? So why does the hiredis bother with 127.0.0.2, if it's the just the same address? Also what happens if you did send a message to 127.0.0.0? – CMCDragonkai – 2014-06-14T05:30:04.210