0

I have some difficulty to picture a diagram for the meaning of loopback. https://en.wikipedia.org/wiki/Loopback#Virtual_loopback_interface

Any traffic that a computer program sends to a loopback IP address is simply and immediately passed back up the network software stack as if it had been received from another device.

What does the action "loop back" mean?

What are the source and destination in the loopback scenario?

How is that different from a regular scenario?

Could you use some commands to show the loopback scenario and the regular one?

For example:

  • When I type ssh localhost, it works just like ssh with any other IP address.
  • When I type http://localhost:631 in browser's address bar and hit return, it works just like typing any other URL.

"loopback" is supposed to mean "a message or signal ends up (or loops) back to where it started" (https://askubuntu.com/questions/247625/what-is-the-loopback-device-and-how-do-i-use-it). But in the two examples, I don't see that meaning happening, but just the same thing as non-loop back IP addresses.

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977
  • 5
    I'm voting to close this question as off-topic because it is [also](https://unix.stackexchange.com/questions/508023/what-can-an-ip-address-be-assigned-to) not about Unix / Linux. – Jeff Schaller Mar 22 '19 at 18:38
  • What do you want? Moderator at networkEngineering site says my question is OS specific. Could you stop abusive comments and votes? You should have higher standard on yourself. – Tim Mar 24 '19 at 11:32

2 Answers2

1

You are confusing the device driver layers and the IP layers of the stack.

At the IP layer, 127.0.0.1 is just another IP address and treated the same.

At the driver layer, packets sent via the loopback interface are "simply and immediately passed back up the network software stack" as opposed to being sent to a network card.

This concept is not OS specific; various OSes use the same concept.

Stephen Harris
  • 42,369
  • 5
  • 94
  • 123
  • I am not confusing. I am asking what the action "loop back" means. – Tim Mar 22 '19 at 21:25
  • 1
    Your edited question shows even more confusion between `localhost` (127.0.0.1) and loopback interfaces. Yes, you _are_ confused between the network stack layers. – Stephen Harris Mar 24 '19 at 01:34
1
      | --- > ---\
lo    |          |
      | --- < ---/

      | --- > --- |
veth0 |           | veth1
      | --- < --- |

A veth pair is a pair of ethernet devices with a cable between them. Implemented as a virtual device. They are designed to communicate with containers: one end of the veth pair can be moved into a container.

You can think of lo like a veth pair, except there is only one end.

In reality the implementation details are not the same. This is at least clear when you look at the strange fact that ping 127.0.0.2 works, but you cannot see the address 127.0.0.2 in ip -4 addr. But there is no need to care unless you are exploiting that "feature" of the legacy version of Internet Protocol, or you are developing the kernel.


A more advanced way to think of lo is that it does not need to do anything, just like the dummy interface. (You can play with ip link add type dummy).

When you ping the IP address of your computer's ethernet or wifi interface, it works without sending anything over that interface. It is possible to verify this with tcpdump or the packet counters in ip -s link. The same is true for dummy, and the same is true for lo.

But if you haven't observed this, you can use the less advanced explanation. It does not really mislead you.

There is some difference in how lo and dummy are used, but that is the magic 127.0.0.2 stuff that is not important to the question.

sourcejedi
  • 48,311
  • 17
  • 143
  • 296
  • Thanks. Does loopback mean that any process running on a host and sending something to a loopback IP address at the host will receives what it has sent? – Tim Mar 22 '19 at 22:04
  • Does ping always get back what it sends, when success, regardless the target IP address is loopback or not? Do you have other examples to show the difference between a loopback Ip and a nonloopback IP? – Tim Mar 22 '19 at 22:08
  • @Tim `veth` interfaces have addresses, you assign them and use the addresses like any other network interface. If you're not listening e.g. to UDP port 123, you will not receive packets sent to UDP port 123. – sourcejedi Mar 22 '19 at 22:09
  • @Tim I am explicitly not caring about any difference for loopback interfaces (and loopback IPs), unless of course you found a reason :-). – sourcejedi Mar 22 '19 at 22:10
  • Sorry, I haven't met veth interface – Tim Mar 22 '19 at 22:10
  • @Tim it is a pair of ethernet devices connected by a cable :-). As a virtual device. – sourcejedi Mar 22 '19 at 22:16
  • Does sending a message to a loopback address work effectively the same as ping an IP address successfully, in that both gets the message back as response? – Tim Mar 23 '19 at 00:09
  • @Tim yes. If I understand your question. `ping` is not special here. You could instead connect to any port, which you have a process listening to. Remember that where services do not bind to 127.0.0.1, they tend to default to a "wildcard". I.e. they listen on all addresses of this computer's network interfaces. – sourcejedi Mar 23 '19 at 00:22
  • Thanks. Let me try to rephrase my confusion about the "loop back" action. (1) When I type `ssh localhost`, it works just like `ssh` with any other IP address. (2) When I type `http://localhost:631` in browser's address bar and hit return, it works just like typing any other URL. "loopback" is supposed to mean "a message or signal ends up (or loops) back to where it started." (https://askubuntu.com/questions/247625/what-is-the-loopback-device-and-how-do-i-use-it) But in the two examples, I don't see that meaning, but just the same thing as non-loop back IP addresses. – Tim Mar 23 '19 at 01:30
  • @Tim you need to look at the packet level to understand what is meant by loopback. `ping` might be easier in that sense. If you `ping google.com`, you build an ICMP echo request, wrap the ICMP with an IP header, and route it out on a physical interface where we wrap it with an Ethernet header and trailer. If you `ping localhost` then we build the packet and route it out to `lo` - but then it comes straight back to us, and our own system has to deconstruct it, process it and generate the ICMP echo response. – sourcejedi Mar 23 '19 at 01:48
  • If `ping 192.168.1.98` the private IP address of the host, is the packet routed out to the router of the LAN and then the router sends it back to the host? – Tim Mar 23 '19 at 01:58
  • @Tim it does not. At least on Linux. Not sure if the IP standard requires this behaviour. It is looped back internally, as per the "more advanced" part of the answer. – sourcejedi Mar 23 '19 at 02:05
  • 1
    Do you mean both loop back and private IP addresses work at packet level in the same "loopback" way? What is the difference between private address and loopback address then? https://unix.stackexchange.com/questions/507980/why-is-some-virtual-network-interface-assigned-private-ip-address-while-some-is – Tim Mar 23 '19 at 02:14