Unable to resolve localhost, 127.0.0.1 or local IP address?
Solution 1
I cleared the browser cache! And it works!! (Oh, how I laughed... and cried!)
However, I don't think the fundamental cause was the browser cache. But that has indeed finally cleared the problem at the browser end!
localhost
was working OK in the beginning. And then it wasn't resolving... in ALL browsers. It was at this point I fired up Safari (which I rarely use and should have been free of cache issues), and it didn't work in Safari either.
I then went round in circles flushing DNS (as Administrator), changing HOSTS file, VirtualHost config, changing DNS servers, reseting the TCP/IP adapter (netsh int ip reset resetlog.txt
- https://support.microsoft.com/kb/299357 - also see this other question: Ping myself, works with ipv6 not ipv4 in Windows 7), rebooting, etc. And eventually clearing the browser cache! So, one of the former "flushes" must have resolved it, but why it happened I still don't know!
One thing is for sure... the browsers were caching the hell out of the bad response. Firefox was still returning the entire failed response from my ISPs DNS long after I had changed the DNS servers on my network adapter. So the response I was seeing was impossible, which prompted me to clear the cache! -sigh-
And my HOSTS file no longer contains an entry for 127.0.0.1 localhost
- it is commented out - as it was originally, before this fiasco began.
Solution 2
netsh int ip reset resetlog.txt
Run as administrator and reboot fixed it for me.
Related videos on Youtube
MrWhite
Updated on September 18, 2022Comments
-
MrWhite almost 2 years
If I try to access
localhost
or127.0.0.1
or even my local IP address192.168.1.14
the browser is unable to resolve this!? (Why it's even trying to resolve it I don't know - I didn't think it would need to?)The browser is taking time to try and resolve this and eventually fails by attempting
http://www.localhost/
(in the case oflocalhost
).Tried all browsers... Chrome, Firefox, Opera, Safari.
This was working OK! I have just installed XAMPP (Apache, MySQL, PHP, ...) and after installing I could navigate to
localhost
to see the default XAMPP welcome page.localhost
stopped working first, whilst I could still navigate to127.0.0.1
. But now neither of these work (as if it took time for caches to clear?!). And neither does192.168.1.14
(my local IP).Bizarrely I can still navigate to
localhost/index.html
,localhost/xampp
,localhost/phpmyadmin
, etc. But not the barelocalhost
. (Although I'm convinced I lost access to all barlocalhost/phpmyadmin
at one point!?). In the same way I can accesshttp://192.168.1.14/index.php
and192.168.1.14/xampp/
, but not192.168.1.14
.The webserver appears to be working OK. I can navigate to a local site I have setup in a VirtualHost and that works OK (just PHP, no DB).
'ipconfig /flushdns
- reports that it was successfull, but no change.Turning off the webserver makes no difference. (Without the webserver running it should immediately fail, but instead it still tries to resolve it.)
Turned off Anti-Virus and Windows Firewall - no difference.
Windows HOSTS file previously did not have an entry for
localhost
(even when it worked OK). I have added an entry forlocalhost
, but this makes no difference. Like I mentioned above, even using127.0.0.1
directly does not work! The IPv6 (::1
) entry is commented out.127.0.0.1 localhost
ping localhost
works! And appears to correctly ping my local computer (the computer name is reported). So, why does this work, and nothing else?
I can create a VirtualHost with
ServerName mylocalhost
and add an approprite entry in my Windows HOSTS file to point to127.0.0.1
ie.127.0.0.1 mylocalhost
and this works OK! (This displays the "Welcome to XAMPP..." homepage)The default document (ie.
DirectoryIndex
) is setup OK.
This other question (from 3 years ago!) appears to have the same problem, but no good answers:
Cannot find local host via browser - can ping localhost and 127.0.0.1 okIn fact I have found numerous other references to
localhost
not working, but no answers. Some of these appear to be related to IPv6 conflicts, but I don't think that is the case here.-
Darius over 10 yearsWhat error message do you get when attempting to browse to localhost? Do you have any files served on localhost? Maybe tried localhost/index.html ?
-
MrWhite over 10 years@Darius: Nothing meaningful is reported by the browser, simply "This webpage is not available" (in Opera, and similar messages in other browsers). Yes,
localhost
should be serving files (the default XAMPP welcome message - which I did see fromlocalhost
when it was first installed). Bizarrelylocalhost/index.html
does work (this is just an "It Works" message) and nowlocalhost/xampp
has started working again, as well as anylocalhost/XXX
URL. But the barelocalhost
(or127.0.0.1
) does not. -
MrWhite over 10 years@Darius: In fact I quickly setup a
mylocalhost
pointing to the same site (see question update) and this works OK.DirectoryIndex
is setup to serve default files. (Butlocalhost
actually results in the browser trying to resolve it!?)
-