Localhost
In computer networking, localhost is a hostname that refers to the current computer used to access it. It is used to access the network services that are running on the host via the loopback network interface. Using the loopback interface bypasses any local network interface hardware.
Question
I have seen 127.0.0.1
is local host address. But what is it and what is the differences between this and my local adapter like LAN IP address or WLAN IP address. Is there any connection between this l27.0.0.1
and my LAN or WLAN Network card?
Answer
127.0.0.1` is an IP that’s part of the IANA reserved range for loopback use (the full range is 127.0.0.1-127.255.255.255).
The processing of any packet sent to a loopback address, is implemented in the link layer of the TCP/IP stack. Such packets are never passed to any network interface controller (NIC) or hardware device driver and must not appear outside of a computing system, or be routed by any router. This permits software testing and local services in the absence of any hardware network interfaces.
Your loopback NIC is it’s own network adapter and not connected in any way to your LAN or WLAN NIC.
On some operating systems (such as Linux or Cisco IOS, not sure about Windows), you can create multiple loopback NICs. 127.0.0.1 is a (possibly defacto) standard for at least one of them, and it’s generally expected at least one loopback NIC exists on any TCP/IP capable system with this IP.
Prove
Evidence 1
No packets will hit the network. Unplug your network cable and try it!
Evidence 2
$ iperf3 -s
$ iperf3 -c localhost -p 5201 -t 10000
[ ID] Interval Transfer Bitrate
[ 7] 0.00-124.83 sec 466 GBytes 32.0 Gbits/sec sender
[ 7] 0.00-124.83 sec 0.00 Bytes 0.00 bits/sec receiver
$ netstat -an | grep 5201
tcp4 0 0 127.0.0.1.5201 127.0.0.1.59347 ESTABLISHED
tcp4 0 1441792 127.0.0.1.59347 127.0.0.1.5201 ESTABLISHED
tcp4 0 0 127.0.0.1.5201 127.0.0.1.59346 ESTABLISHED
tcp4 0 0 127.0.0.1.59346 127.0.0.1.5201 ESTABLISHED
tcp46 0 0 *.5201 *.* LISTEN
Reference
- https://superuser.com/questions/733793/what-is-the-exact-meaning-of-localhost-on-the-operating-system
- https://superuser.com/questions/321734/how-does-localhost-127-0-0-1-work
- https://en.wikipedia.org/wiki/Localhost
- https://stackoverflow.com/questions/860626/does-a-connection-to-localhost-go-out-onto-the-network