33

I can't figure out when this started to happen, but the result is - 127.0.0.1 is not working on any port from anywhere (for example, browser says Unable to connect). Here are the results of my research:

  1. localhost, COMPUTER_NAME and actual IP address all work fine
  2. there is nothing special in my hosts file
  3. ping to 127.0.0.1 and tracert do work fine
  4. all the programs that have 127.0.0.1 hardcoded are not working (this point makes me disappointed the most, because I can't do anything in this case )

What else can I do to identify the source of problem and fix it?

UPDATE: as soon as Redis does work on 127.0.0.1 and both IIS and AzureStorageEmulator don't work I assume this is HTTP only issue.

Lanayx
  • 2,731
  • 1
  • 23
  • 35
  • So `localhost` works fine, but `127.0.0.1` doesn't? Did you modify anything in [hosts file](https://en.wikipedia.org/wiki/Hosts_(file))? – mkierc Dec 31 '15 at 14:21
  • Correct. I tried everything I could do with hosts file, but it didn't help. I suppose it is because 127.0.0.1 is not a domain name, but the ip address so hosts file doesn't affect it. – Lanayx Jan 01 '16 at 12:09
  • Can you clarify what you mean by "working" - what are you expecting to happen? Do you have a server running on the local machine? On which port? – Pekka Jan 01 '16 at 15:40
  • I mean that connection can't be established when using 127.0.0.1. For example, I run IIS and can access site using localhost, when I run azure emulator, I can access it using localhost too (tried different ports, but they don't matter). But I can't connect to them using 127.0.0.1. – Lanayx Jan 01 '16 at 16:42

6 Answers6

73

Just one command did the work

netsh http add iplisten 127.0.0.1

Lanayx
  • 2,731
  • 1
  • 23
  • 35
  • 4
    Thanks ! And just want to point out a document for this command https://msdn.microsoft.com/en-us/library/windows/desktop/cc307219(v=vs.85).aspx – hazjack Jun 06 '17 at 08:01
  • 4
    solved my problem after a whole day searching for an answer. thanks – kishea Aug 05 '19 at 20:45
  • 2
    I would like to know how did the 127.0.0.1 stopped listening? Which application did this configuration without my knowledge. This was working before I installed Docker, and despite I've uninstall it, it did not recover. So I don't know if it was the the culprit. – Daniel Lobo May 19 '21 at 21:36
  • For some reason all my IIS sites stopped working when I did this – Mike Flynn Dec 21 '21 at 21:50
6

If it's a DNS problem, you could try:

  • ipconfig /flushdns
  • ipconfig /registerdns

If this doesn't fix it, you could try editing the hosts file located here:

C:\Windows\System32\drivers\etc\hosts

And ensure that this line (and no other line referencing localhost) is in there:

127.0.0.1 localhost
Penguinparty
  • 126
  • 4
  • dns flush doesn't help. The line in the hosts file doesn't change anything. Moreover, if i map any other name except localhost to 127.0.0.1 it is not working too. – Lanayx Jan 01 '16 at 12:14
  • have you tried pinging 127.0.0.1 to see if there is any sort of response? – Penguinparty Jan 01 '16 at 23:08
  • Ah my apologies, missed that. What "programs" exactly are not working? Is it only in your web browser (I know you mentioned that as one of them above)? Regardless I would say try clearing the browser cache and browser dns. – Penguinparty Jan 02 '16 at 10:09
  • Good question. Just checked redis and it does work on 127.0.0.1. I guess it's because it doesn't use http, but it's special protocol RESP. Will update the question now. To the second part, this is not browser issue, Fiddler (for IIS) and Visual Studio Server Explorer (for azure emulator) both can't connect to 127.0.0.1. – Lanayx Jan 02 '16 at 17:19
  • So I'm not really familiar with either of those, but I was wondering if this could be some sort of program specific error as opposed to Windows? Have you found anything to indicate that the problem specifically has to do with Windows? – Penguinparty Jan 03 '16 at 09:14
  • I would be glad to know what is the source of the problem. To the exact error, fiddler says "502 - Connection Failed", chrome displays ERR_CONNECTION_REFUSED error. – Lanayx Jan 03 '16 at 09:24
  • 1
    Could you check the information about listing what ip/port is tied to the service? It's listed in this question http://serverfault.com/questions/558204/iis-refuses-connection-to-localhost-and-127-0-0-1 – Penguinparty Jan 05 '16 at 22:22
  • Thank you for the reference =) Found the answer after looking at that listing – Lanayx Jan 06 '16 at 09:26
1

In windows first check under services if world wide web publishing services is running. If not start it.

If you cannot find it switch on IIS features of windows: In 7,8,10 it is under control panel , "turn windows features on or off". Internet Information Services World Wide web services and Internet information Services Hostable Core are required. Not sure if there is another way to get it going on windows, but this worked for me for all browsers. You might need to add localhost or http:/127.0.0.1 to the trusted websites also under IE settings.

Gregor
  • 358
  • 2
  • 7
0

I had a similar issue. Check your listen port. A mistake I made ealier was

app.listen(() => console.log(APP_NAME} is listening on port ${PORT}`))

Make sure you include the port as shown below

app.listen(PORT, () =>{
  console.log(`${APP_NAME} is listening on port ${PORT}`)
})
tripleee
  • 175,061
  • 34
  • 275
  • 318
0

This answer may seem overly obvious, but in most cases it is sufficient to simply remove the "localhost" entry in the "Host Name" field:

settings window

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
WAVE
  • 1
0

In the end for us, it was IE11 that was blocking for 127.0.0.1 - after adding it to the exceptions list, it loaded the page.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – another victim of the mouse May 13 '22 at 20:51