Loopback Address
On Wikipedia, there’s an explanation like this: Loopback (also written loop-back) is the routing of electronic signals or digital data streams back to their source without intentional processing or modification. It is primarily a means of testing the communications infrastructure. In simple terms, it’s routing data sent from the “source” back to the “source.”
As someone who likes to take it easy, we will definitely encounter something like this -> Virtual loopback interface. When the application/service we’re writing wants to communicate on the same machine, we basically use this.
In Unix-like systems, the virtual loopback interface is usually named or. We can use to take a look:
Hmm, 127.0.0.1, indeed, is an IPv4 loopback address. According to the IETF standards, the IPv4 address block 127.0.0.0/8 is reserved as loopback addresses (i.e., 127.0.0.0 ~ 127.255.255.255). Under IPv6, the loopback address is.
Under IPv6, 127.0.0.1 is represented as ::1
Several Common Little Guys
OK, that’s the introduction to loopback addresses, let’s look at the following commonly used “little guys”:
Here, we’ll throw out a few questions? Then answer them ourselves! 😎
It’s obvious, 0.0.0.0 and 127.0.0.1 are IP addresses, and localhost is a hostname. For more specific details, you can look at the following two questions.
When disconnected from the network, if we use the ping command to ping a public IP address, it generally doesn’t go through. But it can. Because 127.0.0.1 is a loopback address, the operating system handles packets to public IPs that go through real network cards differently than the packets to virtual network cards with local loopback addresses (the previously introduced lo and lo0, Virtual loopback interface). Packets to public IPs follow a ring buffer, while packets to a loopback address use a data structure input_pkt_queue, triggering a soft interrupt ksoftirqd for processing, which this article delves into 👉🐂.
As for it being reachable, it’s because localhost DNS resolves to the loopback address 127.0.0.1. You can use to view the Linux hosts file. IETF standards reserve the domain name localhost to the loopback address 127.0.0.1 by default.
Why can you still ping 0.0.0.0 when disconnected? You can think about it together with the next question.
Listens to all IPv4 addresses on the local machine. It allows service users to access the web service on the local machine through multiple IP addresses (including loopback addresses, as long as the service users and the local machine are on the same network). provided an introduction to the special 0.0.0.0 address.
Wireshark Loopback Address Packet Capture
Here’s an introduction to capturing loopback address packets using
Wireshark needs to be installed to capture loopback packets.
1. Locally, we use Go’s Gin to set up a rough web service:
2. Open Wireshark and capture the virtual network card’s loopback address:
3. Filter the TCP port and curl localhost:8080/ping:
All done, time to log off! 😊