127.0.0.1 is accessible/working but localhost not accessible/ not working

127.0.0.1 is accessible/working but localhost not accessible/ not working

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

IPv6 Isolation on Windows: Why localhost Fails While 127.0.0.1 Works

This is a classic symptom of IPv6 misconfiguration on modern Windows systems. The specific behavior described—where 127.0.0.1 resolves and responds correctly, but localhost fails—is almost exclusively caused by the operating system's default preference for IPv6 over IPv4 when resolving the hostname "localhost".

In your case, the fact that you are receiving a reply from ::1 (the IPv6 loopback address) confirms that the network stack is successfully resolving the name localhost to an IPv6 address. However, your WAMP server application is likely bound strictly to the IPv4 interface (127.0.0.1). When your browser requests http://localhost, the OS attempts to connect to ::1. If the web server is not listening on the IPv6 loopback interface, or if there are firewall rules blocking traffic to that specific address family while allowing traffic to 127.0.0.1, the connection times out.

Understanding the Resolution Hierarchy

On Windows 8 and later versions, the DNS resolver prioritizes IPv6 addresses over IPv4 when a hostname maps to both. By default, Microsoft's hosts file entry often looks like this:

::1           localhost
127.0.0.1     localhost

When you change this to only include 127.0.0.1, you are forcing the system to skip IPv6 entirely for that hostname. If your application server (Apache, Nginx, or Node) was compiled or configured to listen only on IPv4, and your browser attempts an IPv6 connection, the handshake fails before it even reaches the application logic.

The command ping localhost returning Reply from ::1: time<1ms proves that the name resolution is working perfectly for the hostname; the issue lies purely in the transport layer compatibility between the client's chosen protocol and the server's listening sockets.

Verifying Application Binding

To resolve this without relying solely on editing the hosts file (which can be overwritten by system updates), you should verify exactly how your web server is configured to listen.

If you are using Apache, check the httpd.conf or virtual host configurations. Look for the Listen directive. If it reads only:

Listen 80
# or specifically
Listen 127.0.0.1:80

You must explicitly bind to all interfaces or ensure IPv6 is disabled if not needed. To disable IPv6 entirely on Windows (a nuclear option that resolves the issue but affects other software), you can run the following command in an elevated Command Prompt:

netsh interface ipv6 set teredo state disabled
netsh int ipv6 set registrysetting disabled=1

However, a more surgical approach is to modify your application's binding settings. For example, if you are running a PHP or Node.js application through WAMP, check the configuration to ensure it is not accidentally binding to :: (all IPv6 interfaces). If you cannot change the server code, editing the hosts file as you attempted is valid, but doing so requires removing the IPv6 line entirely:

127.0.0.1     localhost

Ensure there is no preceding empty line or comment that might confuse the parser in older versions of WAMP, though modern Windows handles this gracefully.

The Pitfall of Mixed Environments

The trade-off here is reliability versus configuration complexity. Relying on 127.0.0.1 guarantees IPv4 connectivity but breaks DNS-based routing if your application ever needs to listen on IPv6 for external access. Conversely, forcing the OS to prefer IPv4 by editing the hosts file can interfere with other applications that explicitly rely on the default Windows behavior.

If you are developing a Laravel application or similar stack, this issue can cause confusing "Connection refused" errors even when the server logs indicate it is running. Always verify the laravel artisan serve command output; it will explicitly state which IP it is binding to. If you see [Sun ...] Local: 127.0.0.1, then your browser must connect via IPv4.

For production environments, this specific isolation issue rarely occurs because servers are typically configured with explicit Listen directives that match the desired protocol stack. However, on local development machines running WAMP, Windows updates frequently reset network stacks to prioritize IPv6, making manual intervention in the hosts file or application configuration necessary until a future patch aligns the defaults again.

Final Recommendation

The most robust fix without altering global system settings is to ensure your web server explicitly listens on both 127.0.0.1 and ::1 if you wish to maintain localhost functionality, or simply remove the IPv6 mapping for localhost from your C:\Windows\System32\drivers\etc\hosts file permanently. If you are deploying Laravel projects, remember that the default php artisan serve command binds to 127.0.0.1, so accessing it via http://localhost on Windows 8+ requires either server configuration changes or hosts file adjustments.

Our network