When I ping localhost the address resolves to the ipv6 loopback of ::1

My MySQL and Apache installations expects the ipv4 address of

How can I configure my WindowsXP to resolve localhost to

My C:\WINDOWS\system32\drivers\etc\hosts file: localhost trunk focus demo

I have also have the following set in the Windows registry:


Anything else I can try?

  • 2
    ping -4 localhost – user Jan 12 '12 at 12:27
  • 1
    Who would upvote such a pointless comment. When you ping localhost and don't specify a protocol, it appears to be defaulting to ipv6. When apache and mysql lookup localhost, they will be specifying the protocol and so will get an ipv4 address if that is what is requested. Perhaps tell us a bit more about the problem you are seeing, as a different approach might be needed. – Paul Jan 12 '12 at 13:21
  • This is similar to the bug in Visual Studio's built-in Cassini web-server: it refuses to listen on ::1. As a result: it is, by default, unusable. Hopefully MySql is capable of binding to IPv6. – Ian Boyd Nov 19 '12 at 12:48

It depends on the application that you are using i.e. your application is asking for ipv6 address.

eg. telnet on linux tries to connect using ipv6 address before it tries, unless of course you specify protocol explicitly


x@x:~$ telnet localhost
Trying ::1...

v4 specified

x@x:~$ telnet -4  localhost

For your problem since you are not binding for v6 addresses (for apache and mysql services). In mysql and apache config you can explicitly specify "" in places where localhost is specified. This should solve your problem.

  • I changed my main server name in the apache config file to as you suggested and created a virtual host with servername of localhost and now I get both and localhost to work. MySQL still not happy, but it may be an unrelated issue... – JannieT Jan 12 '12 at 14:20
  • do you have problem accessing mysql directly or through apache (eg php or cgi-bin) – daya Jan 12 '12 at 14:28
  • I can access MySQL via php, but not directly, see my new question:superuser.com/questions/377699/… – JannieT Jan 12 '12 at 16:54

If you don't want to use IPv6 disable it on your connection and make sure you have IPv4 enabled.

Asuming you have a standard wired link you find this in the properties window of "local area connection". You have multiple entries there. You should see "Internet Protocol Version 6 (TCP/IPv6)" and "Internet Protocol Version 4 (TCP/IPv4)". Uncheck v6 and check v4.

Although I don't exactly understand your problem.

  • You should rather uninstall IPv6 altogether. – kinokijuf Jan 12 '12 at 13:43
  • 2
    No, uninstalling IPv6 is not correct. Better solution is to change apache and mysql config to listen on IPv6 addresses as well – daya Jan 12 '12 at 13:52
  • @daya Exactly. That's why I wrote the last sentence – Tom Jan 12 '12 at 14:05

Whether the IPv6 or IPv4 address is provided will depend on what query the software tries first. If the software tries a AAAA query first, then IPv6 will be provided.

But one way to work around this may be to adjust the definition of "localhost", which may be defined by your system's "hosts" or "hosts.txt" file. See Wikipedia Hosts file locations.

Just remove the IPv6 reference. This will probably cause the IPv6 query to provide no results, so the IPv4 query will be tried.

However, this isn't really a recommended practice; understand there may be side effects (from other programs that may rely on IPv6 and the standard "localhost" name). It is recommended to back up this file (so you can easily restore it) before mucking with changes. (A simple copy will likely do the trick.) And test any program that may use the "localhost" name before declaring your efforts to be a success.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.