3

I want to test some HTTP server on localhost address under Windows (XP) and I get strange behaviour: when I enter http://localhost/ in my browser I get connection reset error, while putting http://127.0.0.1/ or anything other that is mapped to this address in the 'hosts' file works just fine and the start page is displayed.

I've closed some processes I suspected, disabled firewall, and it didn't help. For one moment the 'localhost' got back and then it's gone again without any reason. How can I track down what is meddling with localhost address under Windows?

Edit1:
Here is my 'hosts' file:

127.0.0.1       localhost
127.0.0.1       moin

The 'moin' entry works fine, 'localhost' is reset. The HTTP server is play! framework, and the way I must use it is 'http://localhost:9000/@tests'.

Edit2:
The ping response indicates that the 'localhost' resolves to IPv6 ::1 address:

C:\> ping localhost

Checking IZABELA [::1] using 32 bytes of data:

Response from ::1: time<1 ms
Response from ::1: time<1 ms
Response from ::1: time<1 ms
Response from ::1: time<1 ms
...
1
  • Could you post your hosts file? What HTTP server are you using?
    – beatgammit
    Apr 4, 2011 at 16:35

1 Answer 1

3

This is because your localhost passes your network adapter (note the LMHOSTS in it's advanced configuration, this does in essence turn processing of the HOSTS file on and off) and your network adapter could do something extra with it. If you visit 127.0.0.1 then it directly goes to the loopback adapter, as for the other entries your network adapter might just choose to forward them instead of handling them (like the localhost entry). You can get routing information using route PRINT in a command prompt:

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.1.1    192.168.1.100    281 <--
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306 <==
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306 <==
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306 <==
      192.168.1.0    255.255.255.0         On-link     192.168.1.100    281
    192.168.1.100  255.255.255.255         On-link     192.168.1.100    281
    192.168.1.255  255.255.255.255         On-link     192.168.1.100    281
     192.168.11.0    255.255.255.0         On-link      192.168.11.1    276
     192.168.11.1  255.255.255.255         On-link      192.168.11.1    276
   192.168.11.255  255.255.255.255         On-link      192.168.11.1    276
     192.168.40.0    255.255.255.0         On-link      192.168.40.1    276
     192.168.40.1  255.255.255.255         On-link      192.168.40.1    276
   192.168.40.255  255.255.255.255         On-link      192.168.40.1    276
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link      192.168.40.1    276
        224.0.0.0        240.0.0.0         On-link      192.168.11.1    276
        224.0.0.0        240.0.0.0         On-link     192.168.1.100    281
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link      192.168.40.1    276
  255.255.255.255  255.255.255.255         On-link      192.168.11.1    276
  255.255.255.255  255.255.255.255         On-link     192.168.1.100    281

Note where I set the <== at the end, these ensure that the 127.0.0.1 interface is used when you visit a loopback address.

Note where I set the <-- at the end and 0.0.0.0 means any IP, these ensure that things like localhost, any other thing you forward in HOSTS and most IPs you visit are handled by your network adapter which uses the 192.168.1.100 interface and the 192.168.1.1 gateway.

A higher metric means more priority, so this is why <== has preference over <--.

More information can be found on subnetworks to understand the netmasks.


As for your problem:

  • Check your IIS/Apache configuration.
  • Disable your anti virus and firewall.
  • Reset your network adapter to see if it solves the problem.
  • Use the Troubleshoot Problems option to see if it resolves something.
  • Use ipconfig /flushdns to clear DNS resolution.
  • See what you get for ping localhost.
  • Try to disable IPv6.
  • Update the drivers for your network adapter.

Report back if you still have the problem, you might want to capture a Wireshark trace.

3
  • The firewall was disabled, as I stated before. I've added ping response to my question. Resetting adapter didn't help. Flushing DNS also didn't help. Updating drivers is impossible. More ideas?
    – Rajish
    Apr 4, 2011 at 21:07
  • @Rajish: Hmm, IPv6, does the same problem occur when you disable IPv6 and thus only use IPv4? As localhost resolves to the IPv6 variant your server is most likely not listening to the IPv6 IP and thus localhost would not work. Updating your network drivers should be possible, why is it impossible? Apr 4, 2011 at 21:21
  • 1
    I have already the 'newest' drivers for my hardware. Disabling IPv6 at all did the trick. Before that I've tried the trick described here but it didn't work.
    – Rajish
    Apr 4, 2011 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .