Hosts File not working correctly

15,373

Solution 1

Is your Web browser using a proxy?

Mine is (I am at work) and when I connect to a Web site it seems to use the address the proxy server thinks, not the address my computer thinks.

Solution 2

Try opening a command line (cmd.exe) and do ipconfig /flushdns and then restart the browser.

Also, I just got to ask since it might be too obvious or sound too stupid. Have you tried rebooting (or at least logged out and then logged in)? I never cease being amazed at what problems this can solve.

Solution 3

UPDATE: Removing Proxy Configuration from browser solved it for sub.localhost. example.com however still not working...

Are you trying to visit www.example.com instead of example.com? There is a difference between both!

You should add www.example.com to the hosts file too if you want them both to forward to 127.0.0.1.

Solution 4

You said example.com opens 192.0.32.10 - it should go to 127.0.0.1, so either you wrote wrong or the hosts file is not being applied correctly.

I am not sure about the example.com issue, but for the others, I would say that if ping is working, they are working fine, so simply double check that the webserver you are using has the host headers (or whatever setting on your server) set up correctly.

Edit -

Unsure why this is happening, First thing I would try is a different browser such as Firefox as this has it's own network settings which should not be affected by other system settings. If this solves it, then go back to IE and on the last tab (Advanced), choose Reset to remove anything else that may be setting this.

next, you can try tweaking your priorities of what is checked.

Open up the Registry Editor and navigate to :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider

Look for HostPriority and make sure it is a lower number than DNSPriority. You can also change it to a lower number such as 5 to make sure it takes priority over everything else.

If it still is not working, I would just say to check things such as your spelling, but it is hard without seeing the machine in person.

Share:
15,373

Related videos on Youtube

acm
Author by

acm

Backend developer at TheFork

Updated on September 17, 2022

Comments

  • acm
    acm almost 2 years

    I'm having some issues with my hosts file.

    127.0.0.1 localhost
    127.0.0.1 whatever
    127.0.0.1 sub.localhost
    127.0.0.1 example.com
    

    localhost and whatever both work. However the others have weird behaviour.

    Ping sub.localhost

    c:\>ping sub.localhost
    Pinging sub.localhost [127.0.0.1] with 32 bytes of data:
    

    Ping example.com

    C:\>ping example.com
    Pinging example.com [127.0.0.1] with 32 bytes of data:
    

    All seems ok, but browsing example.com will open the correct example.com page @ 192.0.32.10 which is not the expected behaviour... (obviously sub.localhost wont work at all)

    Any ideas why this happens?

    UPDATE 1: Removing Proxy Configuration from browser solved it for sub.localhost. example.com however still not working...

    UPDATE 2: Some more info...

    C:\Documents and Settings\amatos>ping example.com
    Pinging example.com [127.0.0.1] with 32 bytes of data:
    
    C:\Documents and Settings\amatos>ping www.example.com
    Pinging www.example.com [127.0.0.1] with 32 bytes of data:
    
    C:\Documents and Settings\amatos>nslookup example.com
    Server:   ac1.-------.pt  (# suppose this is the router address...)
    Address:  192.168.202.2
    
    Non-authoritative answer:
    Name:    example.com
    Address:  192.0.32.10
    

    Thanks to all that have tried to help so far!

    • JJ_Australia
      JJ_Australia almost 14 years
      What version of Windows are you on?
    • bryan
      bryan almost 14 years
      hosts has 127.0.0.1 example.com and you say "browsing example.com, will open the correct example.com page @ 192.0.32.10 ", this doesn't sound right to me.
    • boot13
      boot13 almost 14 years
      @acmatos: I'm with Bryan - you appear to want example.com to go to 127.0.0.1, yet you also say that when it goes to 192.0.32.10, that is 'correct'. Which do you actually want?
    • Andrew J. Brehm
      Andrew J. Brehm almost 14 years
      192.0.32.10 is the correct IP of example.com. By "correct" he means "registered in the normal DNS hierarchy".
    • acm
      acm almost 14 years
      I mean that if I browse example.com, it will open the same page that you see when you browse example.com. That's the correct page. The correct behaviour however, should be opening 127.0.0.1 (since its defined in hosts to behave like that). I hope I made it clearer this time. :-/
    • boot13
      boot13 almost 14 years
      Yes, if you browse example.com, it will open the page that you see when you browse example.com. That's a tautology. However, I know what you're trying to say.
    • acm
      acm almost 14 years
      boot13: that's not what I said. "(...) if I browse example.com, it will open the same page that you see (...)". I know it's not perfectly explained, however I'm doing my best...
    • boot13
      boot13 almost 14 years
      @acmatos: Got it. I couldn't hear the emphasis on I and you until you added it. Text communication can be tricky.
  • acm
    acm almost 14 years
    everything is well written... checked a million times. localhost as well as whatever are being correctly interpreted and both open 127.0.0.1, so I think it's safe to say hosts file is working, right?
  • acm
    acm almost 14 years
    Thanks, did both (dns flushing and reboot) already, however nothing changed. Had my faith on reboot also. :-)
  • William Hilsum
    William Hilsum almost 14 years
    @acmatos - You wrote "example.com will open the correct example.com page @ 192.0.32.10" - I am confused what you said correct page then? Also, have you tried flushing your dns settings and/or rebooting the machine?
  • acm
    acm almost 14 years
    Wil, I tried to clear that confusion in the original question coments. I tried both dns flush and reboot with no success...
  • Andrew J. Brehm
    Andrew J. Brehm almost 14 years
    The proxy works on a higher layer than the hosts file. Your browser never connects to the target, the proxy server does.
  • William Hilsum
    William Hilsum almost 14 years
    @acmatos - updated.
  • CarlF
    CarlF almost 14 years
    Agreeing with TomWij, also consider that your browser may automatically add the "www." prefix to "example.com" when you type it. So it's loading a different site from what you thought.
  • acm
    acm almost 14 years
    Nop, that's not the problem, both example.com and www.example.com have been added to hosts file and there are no changes.
  • acm
    acm almost 14 years
    Hello Wil, thanks for the effort however still no changes... I'll update OP with some more info.
  • Tamara Wijsman
    Tamara Wijsman almost 14 years
    Have you tried to use a different browser? This can help you to determine if it's only your browser or it is a system-wide problem.
  • acm
    acm almost 14 years
    I will accept this answer because it was the most helpful and proxy issues are most likely to be causing my problem. Thanks.