Hosts File not working correctly

4

1

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!

acm

Posted 2010-08-12T15:50:18.877

Reputation: 143

1What version of Windows are you on? – Hello71 – 2010-08-12T15:53:04.070

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. – bryan – 2010-08-12T16:03:36.203

Windows XP; @bryan, what exaclty doesn't sound right? – acm – 2010-08-12T16:05:55.560

@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? – boot13 – 2010-08-12T16:31:45.633

192.0.32.10 is the correct IP of example.com. By "correct" he means "registered in the normal DNS hierarchy". – Andrew J. Brehm – 2010-08-12T16:36:25.113

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. :-/ – acm – 2010-08-12T16:38:14.910

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. – boot13 – 2010-08-12T17:54:37.877

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... – acm – 2010-08-13T08:12:45.873

@acmatos: Got it. I couldn't hear the emphasis on I and you until you added it. Text communication can be tricky. – boot13 – 2010-08-13T13:46:19.267

Answers

4

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.

Andrew J. Brehm

Posted 2010-08-12T15:50:18.877

Reputation: 4 411

Yes, I'm using an automatic proxy configuration. Shouldn't the host file be checked before the proxy?? Disabling the proxy will make sub.localhost work but not the example.com... One step in the right direction! :-) – acm – 2010-08-12T16:58:43.807

The proxy works on a higher layer than the hosts file. Your browser never connects to the target, the proxy server does. – Andrew J. Brehm – 2010-08-12T17:27:15.553

I will accept this answer because it was the most helpful and proxy issues are most likely to be causing my problem. Thanks. – acm – 2010-08-16T10:55:01.063

4

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.

JaHei

Posted 2010-08-12T15:50:18.877

Reputation: 674

Thanks, did both (dns flushing and reboot) already, however nothing changed. Had my faith on reboot also. :-) – acm – 2010-08-12T16:39:28.183

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.

Tamara Wijsman

Posted 2010-08-12T15:50:18.877

Reputation: 54 163

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. – CarlF – 2010-08-12T20:32:56.413

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 – 2010-08-13T08:14:53.827

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. – Tamara Wijsman – 2010-08-14T09:34:03.440

1

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.

William Hilsum

Posted 2010-08-12T15:50:18.877

Reputation: 111 572

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 – 2010-08-12T16:35:03.367

@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? – William Hilsum – 2010-08-12T16:48:24.183

Wil, I tried to clear that confusion in the original question coments. I tried both dns flush and reboot with no success... – acm – 2010-08-12T16:54:33.017

@acmatos - updated. – William Hilsum – 2010-08-12T17:36:57.923

Hello Wil, thanks for the effort however still no changes... I'll update OP with some more info. – acm – 2010-08-13T08:24:02.493

0

Flush your ARP cache:

  1. Open a cmd window.
  2. arp -a will show all of your ARP entries.
  3. arp -d will delete the entries (or a specific one).

I would also flush the DNS entries:

ipconfig /flushdns
arp -d

ping <whatever>

Harv

Posted 2010-08-12T15:50:18.877

Reputation: 147