Pinging localhost versus pinging 127.0.0.1

3

If I ping localhost, I receive a reply from ::1 which IIRC is the IPV6 loopback address.

If I ping 127.0.0.1, I receive a reply from 127.0.0.1 as expected.

Why is there a difference when hostname resolution of localhost is indeed 127.0.0.1?

Please see the following screenshot:

Screenshot of command prompt ping localhost and ping 127.0.0.1

user76275

Posted 2011-05-19T06:05:17.377

Reputation:

Answers

3

Hostnames can resolve to both IPv4 and IPv6 addresses. "localhost" resolves to IPv4 (127.0.0.1) and IPv6 (::1).

I think Windows' preference is to use IPv6 where possible, which is why localhost defaults to the IPv6 resolution. If you turned off IPv6 it would go to the IPv4 address.

The reason you dont encounter this much when pinging internet servers is that many ISPs don't provide customers with IPv6 addresses (and many routers/modems can't handle them), and you need all devices in a chain to use IPv6 if you want to reach a server using IPv6.

Spectre

Posted 2011-05-19T06:05:17.377

Reputation: 1 045

1Precisely - since Windows Vista, the Windows networking stack prefers IPv6. – Tobias Plutat – 2011-05-19T16:38:48.223

Technically there is nothing wrong with pinging either localhost or 127.0.0.1 since they will normally (there are exceptions if the user points localhost to some other server but that's quite unusual) point to the same server (your local computer). – Hengjie – 2013-02-10T09:04:37.393