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
...
Best Answer
This is because your
localhost
passes your network adapter (note theLMHOSTS
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 visit127.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 thelocalhost
entry). You can get routing information usingroute PRINT
in a command prompt:Note where I set the
<==
at the end, these ensure that the127.0.0.1
interface is used when you visit a loopback address.Note where I set the
<--
at the end and0.0.0.0
means any IP, these ensure that things likelocalhost
, any other thing you forward inHOSTS
and most IPs you visit are handled by your network adapter which uses the192.168.1.100
interface and the192.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:
Troubleshoot Problems
option to see if it resolves something.ipconfig /flushdns
to clear DNS resolution.ping localhost
.Report back if you still have the problem, you might want to capture a Wireshark trace.