6

I thought that the loopback IP address of my machine is 127.0.0.1.

I do not understand why am I able to ping IP addresses until 127.255.255.254.

Ron Maupin
  • 99,565
  • 26
  • 120
  • 195
yoyo_fun
  • 1,531
  • 4
  • 19
  • 28
  • 2
    I think your question is off-topic here, but I would like to tell you that the entire range 127.0.0.0/8 (127.0.0.1 - 127.255.255.254) is reserved for loopback purposes and they are always available. On most systems, localhost resolves to 127.0.0.1 which is the most commonly used IPv4 loopback address. – Hung Tran Oct 02 '17 at 08:08
  • @HungTran Thank you for the information. So basically my own computer has many local IP addresses? – yoyo_fun Oct 02 '17 at 08:45
  • Yes, and the right term should be loopback IP addresses, NOT local. – Hung Tran Oct 02 '17 at 09:11
  • @HungTran Thank you, I understand. So the computer can have an IP address on the NIC and that is the local IP address, the IP assigned to the NIC. The loopback is a separate IP address but it is not assigned to the NIC it is just an internal IP address that the computer uses to communicate with itself. Am I correct? – yoyo_fun Oct 02 '17 at 09:14
  • Basically, we can understand like that. You can read more discussions here. – Hung Tran Oct 02 '17 at 09:36

2 Answers2

8

The entire address block 127.0.0.0/8 is the block of loopback addresses for a host. There are RFCs that explain this.

The goes back at least as far as RFC 990, ASSIGNED NUMBERS:

The class A network number 127 is assigned the "loopback" function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. No datagram "sent" to a network 127 address should ever appear on any network anywhere.

RFC 1122, Requirements for Internet Hosts -- Communication Layers:

(g) { 127, }

Internal host loopback address. Addresses of this form MUST NOT appear outside a host.

Also RFC 3330, Special-Use IPv4 Addresses:

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 should loop back inside the host. This is ordinarily implemented using only 127.0.0.1/32 for loopback, but no addresses within this block should ever appear on any network anywhere [RFC1700, page 5].

Ron Maupin
  • 99,565
  • 26
  • 120
  • 195
1

To answer the OP's Q: "why am I able to ping IP addresses until 127.255.255.254"? (which is a dup of https://serverfault.com/questions/360283/loopback-interface-on-linux-catches-all-loopback-traffic)

A: the early RFCs were ambiguous, Linux and apparently Windows interpreted them to mean "the host should respond on all loopback addresses. BSD - and thus macOS - use the "only 127.0.0.1/32" interpretation.

Aside: Linux's systemd relies on this behaviour - its systemd-resolved local stub listener receives requests via the loopback interface and filters out anything other than 127.0.0.53 or 127.0.0.54 (ref. https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html). At no point are the IP addresses 127.0.0.53 or 127.0.0.54 configured on lo.

Ben L
  • 11
  • 2
  • RFC 1700 was not the original source for the entire block being the loopback block. It goes back at least as far as RFC 990 ("...a datagram sent by a higher level protocol to a network 127 address should loop back inside the host.") where it is clear that a packet sent to any address in the old Class A 127 (127.0.0.0/8) is to loop back inside the host. See my answer on this. – Ron Maupin Aug 24 '22 at 11:41
  • Ack; I'll amend the answer's second para to "The early RFCs were ambiguous, Linux and apparently Windows interpreted them to mean "the host should respond on all loopback addresses"; BSD - and thus macOS - use the "only 127.0.0.1/32" interpretation. – Ben L Aug 25 '22 at 12:33
  • systemd relies on this behaviour: Why? It would also be possible that only the "used" addresses (127.0.0.1, 127.0.0.53 and 127.0.0.54) respond to an ICMP echo request - or even to implement TCP/IP in a way that ping is not supported for localhost at all. – Martin Rosenau Sep 01 '22 at 12:52
  • Your last paragraph doesn't match the behaviour of systemd-resolved (v250.8) on my system. systemd-resolved bind()s only to those two specific addresses, so it never gets to see any other traffic going to 53/udp on the loopback interface. I have just verified that using strace. – TooTea Sep 12 '22 at 11:05
  • TBH, I didn't reverse engineer this, rather I'm going mainly by a cursory examination of systemd's source: if I'm reading it right systemd-resolved has a "bind to interface and filter only valid addresses" approach. e.g. https://github.com/systemd/systemd/blob/v251/src/basic/socket-util.c#L1270, and https://github.com/systemd/systemd/blob/v251/src/resolve/resolved-dns-stub.c There's also use of IP_FREEBIND in there too. So, "it's complicated" ;-) The main point I was trying to make was that at no point are the IP addresses 127.0.0.53 or 127.0.0.54 configured on the lo interface. – Ben L Sep 13 '22 at 12:49