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

1

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.

cja

Posted 2014-02-06T15:24:47.337

Reputation: 143

Is your HTTP server also listening on ::1 or just IPv4? – jscott – 2014-02-06T15:33:32.243

1Just ipv4 . . . – cja – 2014-02-06T15:33:57.860

uncomment it, and you got your localhost back) – alexus – 2014-02-06T15:52:21.360

The first line assumes you're running DNS on your box, and that localhost would resolve to your local IP. – Steve Butler – 2014-02-06T15:53:27.010

@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 – 2014-02-06T16:04:29.457

why did I lose 2 points for this question 7 hours today? – cja – 2014-02-07T12:26:42.870

Answers

0

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.

Steve Butler

Posted 2014-02-06T15:24:47.337

Reputation: 116

1

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

from

# 127.0.0.1     localhost

to

127.0.0.1     localhost

Poliquin

Posted 2014-02-06T15:24:47.337

Reputation: 111

@cja Yes it should work without that entry in the localhost file. Not sure why it's not for you. – Michael – 2018-03-10T00:26:55.083

Sorry - I realise I didn't explain my understanding. Please see new final paragraph in question. – cja – 2014-02-06T15:36:34.090

'127.0.0.1' is probably (hard)coded into the TCP/IP stack but not 'localhost' – Poliquin – 2014-02-06T15:43:07.053

What does the comment mean? It implies that localhost works without an entry in the hosts file – cja – 2014-02-06T15:43:54.293

0

Yes Microsoft did make that change. Apparently this is because on an IP6 only machine (will be more common in the future) that default entry of resolving localhost to IP4 address will cause it not work. So they moved that logic into the DNS resolver itself where they could be independently disabled.

Source: https://serverfault.com/a/9665/104049

Michael

Posted 2014-02-06T15:24:47.337

Reputation: 186

0

The comment is talking about the DNS implementation in Windows itself, not the DNS implementation in Chrome.

David Schwartz

Posted 2014-02-06T15:24:47.337

Reputation: 58 310

That's what I thought – cja – 2014-02-06T17:46:52.157

-1

An upgrade to windows 8.1 will delete some or perhaps all added services ... i.e. Apache, MySQL. Just look at the services running on your computer you will notice that all your web related services are GONE.

Peter

Posted 2014-02-06T15:24:47.337

Reputation: 1

Welcome to Super User! That doesn't answer OP's question- there is no indication that this changed as part of an upgrade. – bertieb – 2018-04-25T23:02:31.293

Furthermore, the question explicitly says that http://127.0.0.1:9876/ works, so obviously the local service is still running. – Scott – 2018-04-26T01:31:09.783