Using cmd
and ping
on Windows gave me the following results:
- Pinging "localhost":
- Pinging "192.168.0.10" (local IP address):
Aren't both situations exactly the same?
I mean, I'm pinging the same interface, the same machine and the same address. Why do I get such different results?
EDIT: Here is my ipconfig /all
screen:
Best Answer
You are not pinging the same interface, without any physical interfaces you still have a "local host".
Your
localhost
is used to refer to your computer from its "internal" IP, not from any "external" IPs of your computer. So, the ping packets don't pass through any physical network interface; only through a virtual loop back interface which directly sends the packets from port to port without any physical hops.You might still wonder why
localhost
is resolving to::1
, while traditionally we would expect it to resolve to the IPv4 address127.0.0.1
. Note that.localhost
is traditionally a TLD (see RFC 2606) which points back to the loop back IP address (for IPv4, see RFC 3330, especially 127.0.0.0/8).Looking up
localhost
usingnslookup
gives us:Thus Windows prefers to use the IPv6 loop back IP address
::1
(see RFC 2373) as it is listed first.Okay, so, where does it come from, let's look at the hosts file.
Hmm, we have to look at the DNS settings of Windows.
This KB article tells us about a setting that affects what Windows prefers, emphasized in bold:
What is this prefix policy table?
This table decides what prefixes get precedence over other prefixes during DNS resolves.
Ah, so using that KB we could add entries here that denote that IPv4 has higher precedence than IPv6.
Note: There is no reason to override this behavior, unless you are experiencing compatibly problems. Changing this setting on our Windows Server broke our mail server, so it should be handled with care...