There is a nginx server listen on 8080 port, and telnet with localhost and 127.0.0.1. One connected, one connected fail otherwise.
[test@localhost sbin]$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
[test@localhost sbin]$ telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
What's the difference between 'localhost' and '127.0.0.1'?Why localhost connect fail?Thanks!
127.0. 0.1 is known as a loopback address, but you may see it under the name "localhost." When you point your browser to 127.0. 0.1, it tries to connect to the computer you're using right now. This is handy when you want to connect to a server on your own computer.
0.1, the IP address of the local computer. This IP address allows the machine to connect to and communicate with itself. Therefore, localhost (127.0. 0.1) is used to establish an IP connection to the same device used by the end-user.
Localhost is a hostname that refers to the local machine currently making the request. On many computers, localhost is an alias for the IP address 127.0. 0.1. When a computer pings this IP address, it is communicating with itself.
On modern computer systems, localhost as a hostname translates to an IPv4 address in the 127.0. 0.0/8 (loopback) net block, usually 127.0. 0.1, or ::1 in IPv6. The only difference is that it would be looking up in the DNS for the system what localhost resolves to.
127.0.0.1
is the IPv4 address to the local machine.
localhost
is a name that is looked up to find the addresses of the local machine. In your case it finds the IPv6 address first (::1) and tries to connect to that. If your service is only listening on IPv4, it will fail to connect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With