34

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.

4
  • So localhost works fine, but 127.0.0.1 doesn't? Did you modify anything in hosts file?
    – mkierc
    Commented Dec 31, 2015 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
    Commented Jan 1, 2016 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
    Commented Jan 1, 2016 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
    Commented Jan 1, 2016 at 16:42

6 Answers 6

76

Just one command did the work

netsh http add iplisten 127.0.0.1

4
  • 4
    Thanks ! And just want to point out a document for this command msdn.microsoft.com/en-us/library/windows/desktop/…
    – hazjack
    Commented Jun 6, 2017 at 8:01
  • 4
    solved my problem after a whole day searching for an answer. thanks
    – kishea
    Commented Aug 5, 2019 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. Commented May 19, 2021 at 21:36
  • For some reason all my IIS sites stopped working when I did this
    – Mike Flynn
    Commented Dec 21, 2021 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
8
  • 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
    Commented Jan 1, 2016 at 12:14
  • have you tried pinging 127.0.0.1 to see if there is any sort of response? Commented Jan 1, 2016 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. Commented Jan 2, 2016 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
    Commented Jan 2, 2016 at 17:19
  • 1
    Could you check the information about listing what ip/port is tied to the service? It's listed in this question serverfault.com/questions/558204/… Commented Jan 5, 2016 at 22:22
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.

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}`)
})
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.

1
  • 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. Commented May 13, 2022 at 20:51
-1

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

2
  • 2
    Where is this screen from ? Commented Mar 14, 2022 at 2:17
  • It's the IIS binding screen against a website Commented Apr 28, 2022 at 11:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.