Why is my localhost not 127.0.0.1 but ::1, and what notation is that?

63

7

When I use the Ping command against my localhost (on Windows Vista), it doesn't show up as 127.0.0.1.

C:\Windows\system32>ping localhost
Pinging GIGA [::1] from ::1 with 32 bytes of data:

ping pong

Instead, it shows up as ::1 (pair of colons and a one). What kind of notation is this? And why is it not showing up as 127.0.0.1?

Here's what I see in the c:\windows\system32\drivers\etc\hosts file.

::1             localhost
127.0.0.1       localhost

As suggested by Gregg I have already tried changing this order.

127.0.0.1       localhost
::1             localhost

The expected result is that 127.0.0.1 would take precedence over ::1 but that was not the case.

As I have learned now, this can be done by adding a prefix policy instead. To force cmd to use IP version 4 the option -4 can be used. To force Windows to always use IP version 4, IP version 6 or some of its components can be disabled through the properties dialog for the network adapter or through a registry tweak.

Samir

Posted 2013-10-31T18:53:17.233

Reputation: 17 919

Question was closed 2013-11-01T17:23:25.823

7

In Tom Wijsman's answer you'll find out http://superuser.com/questions/414050/why-is-there-a-difference-between-ping-localhost-and-ping-local-ip-address

– Rudolph – 2013-10-31T18:56:39.263

1

Not only is that IPv6, but there is nothing special or hard-coded about localhost; it is specified in the HOSTS file. It is 127.0.0.1 by default, but you can change it to whatever you want, or remove it altogether.

– Synetech – 2013-10-31T19:24:10.723

1@Synetech on Windows 7 it's commented out by default with a note: localhost name resolution is handled within DNS itself. – gronostaj – 2013-10-31T22:15:09.827

Answers

91

This is because ping on Windows Vista and newer Windows uses IPv6 by default when available. ::1 is a shortened notation of IPv6 loopback address - equivalent of IPv4 loopback 127.0.0.1.

The full notation of the abbreviated ::1 IPv6 address is 0000:0000:0000:0000:0000:0000:0000:0001.

If you want to force ping to use IPv4 instead you can specify the IPv4 address explicitly or use the -4 option.

ping 127.0.0.1
ping -4 localhost

If you want to change the IPv6/IPv4 preference overall you can check IPv4 vs IPv6 priority in Windows 7.

For additional information you can also see the article localhost.

pabouk

Posted 2013-10-31T18:53:17.233

Reputation: 5 358

18

[::1] is shorthand for loopback address in IPv6. If you would like to disable IPv6 for some reason (I would not advise it, but you may have a specific reason for wanting it), all you need to do is the following (for Windows 7):

  • Start, Control Panel
  • Network and Sharing
  • View Active Network, Local Area Connection, Properties
  • Uncheck the checkbox next to Internet Network Protocol Version 6

If you'd like screenshots, a guide from Microsoft can be found here: link.

Additionally, you may also want to take a look at the Wikipedia Page for IPv6, specifically, Presentation:

The localhost (loopback) address, 0:0:0:0:0:0:0:1, and the IPv6 unspecified address, 0:0:0:0:0:0:0:0, are reduced to ::1 and ::, respectively. This two-colon replacement may only be applied once in an address, because multiple occurrences would create an ambiguous representation.

To summarize, this is basically the equivalent of wanting to write every number 1 to 100, but instead of writing out every number individually, instead you write 1, 2, 3...99, 100 or 1-100

Michael H

Posted 2013-10-31T18:53:17.233

Reputation: 498