Friday, March 5, 2010

Can't Access Localhost using IP Address or Computer Name

Well, I'm not sure when this feature on my pc broke, but it did and it WAS at some point working. I concluded that this can be a tricky little problem as I scoured the internet looking for an answer. Apparently, many people have this problem, and it is never really clear if they resolved it....or how they did.

I spent way too much time on this issue, but darn it I get really annoyed when something used to work, but then does not work anymore.

My problem was getting my locally served website to be accessed either by the ip address of my computer (http://xx.xx.xx.xx) or by the computer name (http://my-computer-name-here). On my computer, or another computer on the local network. When I would try these methods I got a page not found error. The same error occurred on other pc's too, make sense, but I had to hope...

I could access my site on my pc using the http://localhost. As a note, I'm on Vista but I don't think that was my problem. As a another note, I changed many things so I guess it could have been several of these steps combined, but I think it was the final steps that did it...

Okay so lets look at things that were right about the localhost, just in case you need to check this. My host file was correct. Located @ \windows\system32\drivers\ets\hosts

it contained the necessary line of:

127.0.0.1 localhost

My IIS was set up correctly, I had a Default Website running, IIS was running, the bindings on the default web site was just HTTP, port 80.

I had my Firewall OFF, I turned OFF my anti-virus. So that took those variables out of the equation.

I checked if my port 80 was open (-netsh -an), well actually, I tried to think I knew what I was looking at. Maybe subconsciously I did :)

I made sure I was not running Sql Server tools that might interfere like SSIS. (I read somewhere that may hog port 80 if on.)

I could ping my PC by computer name and ip address. (ping xxx.xxx.xxx)

I checked permissions on the physical folder, I made sure Anonymous access was on. I did not think it was an IIS problem with all these things in place.

So I finally found some post that sounded feasible, although not really directed at my problem. But, I decided to just blindly follow the instructions as a last straw. Totally risking they could be wrong...and in the end it did resolve my problem. Good thing. I was totally relieved.

In reflection, I faintly recall having to run this command before, but I forgot or someone else was running it for me. Gee thanks for babying me so I could spin my wheels for a whole day!

My steps, just as a reference, I'm not recommending anything to anyone....

turned off IIS

Open a command prompt
Type: netsh {enter}
Type: http {enter}
type: add iplisten ipaddress=xx.xx.xx.xx *message successfully added should follow
Type: exit
Open a command line
Type: ipconfig /flushdns

turned IIS back on.

browsed to http://localhost ...check...still working
browsed to http://xx.xx.xx.xx ..oh finally working
browsed to http://my-computer-name ...finally working

got on another pc, attempted remote access...finally working

okay, so I'm pretty sure adding the listener is what made this work, but maybe it was that flushing command. I was running XP before then 'upgraded' to Vista and changed my computer name so maybe it needed to clear something out. i'm not sure.

And again I don't know if this is right. All I know is that it made it work. So now I could go back to doing my original work...sending my localhost link to someone so they could look at a page design....

Hope that helps someone!

9 comments:

  1. Are you sure the http is the right command? I tried your instructions and it returned command not found when I type http. I am using Windows 2003 standard server.

    ReplyDelete
  2. @Ramesh
    hmm..my local development machine is windows vista? maybe since your machine is an actual server there is another command out there?

    ReplyDelete
  3. thank you it worked. I'm using windows 7.
    However, I can't access from outside of local network.

    ReplyDelete
  4. @HKChaos in my case, i only needed access from inside the local network. outside might require some firewall stuff.

    ReplyDelete
  5. Mine is an XP machine and i tried with "=http"
    then gave "add iplisten ipaddress=x.x.x.x"

    but the command comes as the command not found...

    any ideas???

    ReplyDelete
  6. The command is just http then press enter, Is that what u entered?

    ReplyDelete
  7. Thanks alot this fixed my ip browsing issue as well

    ReplyDelete
  8. Thanx Alot this saved me three days of research.

    ReplyDelete