Why does localhost not work in Windows 8.1, but 127.0.0.1 does?

27,629

Solution 1

I can't find reliable documentation, but it appears since windows 7 they changed localhost resolution to DNS. I'm guessing the DNS client service actually hands back localhost when you do an operation, because your DNS server, where ever it is, probably wont resolve localhost. You can always set the hosts file, and it aught to override what the DNS client gives you.

Here's at least proof that it changed since windows 7:

http://support.microsoft.com/kb/972034

I'm assuming its the DNS service, because on my Win8 box, those lines are commented, and yet localhost resolves back to ::1 and of course my DNS is not configured for IPv6, and even if it were, it wouldn't resolve localhost.

Solution 2

If you remove the second '#', localhost should work as well.

from

# 127.0.0.1     localhost

to

127.0.0.1     localhost
Share:
27,629

Related videos on Youtube

cja
Author by

cja

Updated on September 18, 2022

Comments

  • cja
    cja almost 2 years

    I have a HTTP server running on port 9876.

    I put http://127.0.0.1:9876/ into Chrome and the page loads instantly.

    I put http://localhost:9876/ into Chrome and the page never loads.

    I have never modified C:\Windows\System32\drivers\etc\hosts.

    Every line in the hosts file is commented out.

    The following lines exist in the file and may be relevant:

    # localhost name resolution is handled within DNS itself.
    #   127.0.0.1       localhost
    

    As I said, I have not added these lines myself. I have not edited the hosts file.

    Obviously I can uncomment the second line to make localhost work. But why is this necessary if the first line is correct? Did Microsoft write the first line? It looks like they're telling me that localhost will work without being defined.

    • notWhoIam
      notWhoIam over 10 years
      Is your HTTP server also listening on ::1 or just IPv4?
    • cja
      cja over 10 years
      Just ipv4 . . .
    • alexus
      alexus over 10 years
      uncomment it, and you got your localhost back)
    • Steve Butler
      Steve Butler over 10 years
      The first line assumes you're running DNS on your box, and that localhost would resolve to your local IP.
    • cja
      cja over 10 years
      @SteveButler Ok, put that in an answer and I'll accept it. Also, can you explain why MS decided to disable localhost by default?
    • cja
      cja over 10 years
      why did I lose 2 points for this question 7 hours today?
  • Poliquin
    Poliquin over 10 years
    '127.0.0.1' is probably (hard)coded into the TCP/IP stack but not 'localhost'
  • cja
    cja over 10 years
    What does the comment mean? It implies that localhost works without an entry in the hosts file
  • cja
    cja over 10 years
    That's what I thought
  • Michael
    Michael over 6 years
    @cja Yes it should work without that entry in the localhost file. Not sure why it's not for you.
  • bertieb
    bertieb about 6 years
    Welcome to Super User! That doesn't answer OP's question- there is no indication that this changed as part of an upgrade.
  • Scott - Слава Україні
    Scott - Слава Україні about 6 years
    Furthermore, the question explicitly says that http://127.0.0.1:9876/ works, so obviously the local service is still running.