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 address 127.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
using nslookup
gives us:
nslookup localhost
...
Name: localhost
Addresses: ::1
127.0.0.1
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.
type %WINDIR%\System32\Drivers\Etc\Hosts
...
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
...
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:
In Registry Editor, locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
Double-click DisabledComponents to modify the DisabledComponents entry.
Note: If the DisabledComponents entry is unavailable, you must create it. To do this, follow these steps:
In the Edit menu, point to New, and then click DWORD (32-bit) Value.
Type DisabledComponents, and then press ENTER.
Double-click DisabledComponents.
Type any one of the following values in the Value data: field to configure the IPv6 protocol to the desired state, and then click OK:
- Type
0
to enable all IPv6 components. (Windows default setting)
- Type
0xffffffff
to disable all IPv6 components, except the IPv6 loopback interface. This value also configures Windows to prefer using Internet Protocol version 4 (IPv4) over IPv6 by modifying entries in the prefix policy table. For more information, see Source and Destination Address Selection.
- Type
0x20
to prefer IPv4 over IPv6 by modifying entries in the prefix policy table.
- Type
0x10
to disable IPv6 on all nontunnel interfaces (on both LAN and Point-to-Point Protocol [PPP] interfaces).
- Type
0x01
to disable IPv6 on all tunnel interfaces. These include Intra-Site Automatic Tunnel Addressing Protocol (ISATAP), 6to4, and Teredo.
- Type
0x11
to disable all IPv6 interfaces except for the IPv6 loopback interface.
Restart the computer for this setting to take effect.
What is this prefix policy table?
netsh interface ipv6 show prefixpolicies
(or prefixpolicy
on earlier versions)
Precedence Label Prefix
---------- ----- --------------------------------
50 0 ::1/128
45 13 fc00::/7
40 1 ::/0
10 4 ::ffff:0:0/96
7 14 2002::/16
5 5 2001::/32
1 11 fec0::/10
1 12 3ffe::/16
1 10 ::/96
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...
18You are not pinging the same interface, even without any physical interfaces you still have a "local host". – Tamara Wijsman – 2012-04-18T20:31:17.953
If by "the same interface", you mean the loopback interface, you are correct. If you mean the Ethernet interface, you are wrong for several reasons. (For example, how is ::1 associated with the Ethernet interface? And why would the Ethernet interface -- whose job is to send Ethernet packets on the wire and receive them from the wire -- be involved in an operation that never involves an Ethernet packet or a wire?) – David Schwartz – 2012-04-18T21:47:12.697
I'm fairly certain this question has been asked on Stackoverflow before, if I can find it... – Chris S – 2012-04-18T22:28:09.747
The heart of this gets answered by this SO, I believe: http://stackoverflow.com/questions/6938039/localhost-vs-real-ip-address
– Dawson Toth – 2012-04-19T02:45:20.060I think the interesting thing is: why do you get a number of bytes transferred and a TTL when pinging a remote host, but neither when pinging localhost? Nobody likely cares that the IP address format is a bit off. – dhasenan – 2012-04-19T03:14:53.833
On mine I get Bytes transferred and with both. I don't know if the difference with yours is IPv6 related – barlop – 2012-04-19T12:26:40.170
@David Schwartz The Loopback is an interface to a network. That is the internal network which does not need a Ethernet Interface, hence Tom Wijsman was correct. – David Allan Finch – 2012-04-20T09:13:02.583
@DavidAllanFinch: There is only one loopback interface, and it handles all IP traffic that is strictly local to the machine. How is it correct to say that "you are not pinging the same interface"? – David Schwartz – 2012-04-20T18:15:20.713