25

My (Windows XP, Professional, v2002, SP3) workstation is completely ignoring my hosts file.

Here is the code in my hosts file:

127.0.0.1       localhost

172.17.1.107    wiki

But, when I open a browser and type "wiki" in the URL bar and hit "Enter" it takes me to the old location of my wiki as it appeared in my old hosts file:

10.0.36.100     wiki

Even though I have renamed the old hosts file "hosts_full" and moved it to my desktop (so, out of the etc folder entirely).

I have so far taken the following steps:

  1. Restarted (3 times)
  2. Ran ipconfig /flushdns from the command line
  3. Ran ping wiki from the command line, response was

Reply from 10.0.36.100: bytes=32 time=1ms TTL=63

I've cleared every cache I can think of (IE, FF).

I have an ISA firewall client that runs on my machine and I've tried all of this with it disabled and enabled. In fact, the firewall uses the old hosts file to resolve itself:

10.0.2.126      isa3

And somehow it still works fine even though the new hosts file doesn't contain that line.

Any ideas??? Thanks in advance for the help!

1
  • what happens when you create a new entry for that ip, say 172.17.1.107 wikitest?
    – shufler
    Aug 6, 2009 at 17:00

13 Answers 13

27

Any chance you are using a proxy server for browsing? If so it might be that the proxy server is resolving the dns name for you.

And thats why you get different results in a commandline with ping as opposed to the browser.

Off chance traffic is intercepted and changed. Very off chance...

5
  • 1
    Yes, actually, I found out there is a corporate proxy that is intercepting my requests and responding to them. Somehow it was bypassing my hosts file. If there was an entry in the corporate proxy it was overriding my local hosts file entry. While this answer didn't really tell "how" to fix the problem, it did identify the actual root cause of the problem (it's not the firewall...)
    – cmcculloh
    Feb 15, 2010 at 13:19
  • 1
    When i had the problem it was an easy fix. I chose to not use proxy on that IP(Under proxy settings in Firefox) This fix may not apply to your problem(Firewall might be blocking outgoing HTTP without proxy etc). It may also be a bitch roll out to multiple machines, if you dont have centralized management of Mozilla profiles. I can't answer for IE since we dont use it.
    – artifex
    Feb 16, 2010 at 8:30
  • 3
    .. *bitch* roll out .. Lol
    – manas
    Nov 25, 2014 at 13:14
  • 1
    It only took 4 years before someone noticed @silent_warrior ;)
    – artifex
    Nov 26, 2014 at 11:38
  • 1
    @artifex Thanks for your answer and comment, this led me to realise that I can set up exceptions which solved my issue. Anyone interested see here: stackoverflow.com/questions/37658876/…
    – haakym
    Jun 16, 2016 at 13:10
9

Firewall Responding To Pings?
This is a long shot from the ip address you gave, but what happens when you ping the new ip directly, does that work?

The reason I ask, if 10.0.36.100 happens to be a firewall that responds to the ping, it will say reply from that, even though you were pinging a different IP....

Big Hosts File?
Also, this got me and another IT person once, there were lots of blank lines in the window hosts files, and then entries way down below -- we didn't noticed the scroll bar :-)

Is the hosts file really the hosts file?
Lastly, look in the registry and make sure the host file is where you think it is, the following key specifies where the actual hosts file is:

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath
2
  • 1
    1: Reply from 172.17.1.107: bytes=32 time<1ms TTL=63 2: Nope, reviewed entire hosts file scroll-bar and all... 3: DataBasePath, Type="REG_EXPAND_SZ", Data="%SystemRoot%\System32\drivers\etc" That %SystemRoot% part got me curious, so I opened up my "Environment Variables" and looked for a SystemRoot variable. Didn't see one, so I created one and set it to C:\Windows, then I did an ipconfig /flushdns and pinged www.wiki.com, but it still responded from 70.35.23.23 instead of 172.17.1.107 (which is what I set it to in my hosts file). Thanks though! Good suggestions all!
    – cmcculloh
    Aug 7, 2009 at 13:32
  • Good catch, my system was booting off of drive E: and not C: as expected.
    – Manny
    Apr 5, 2018 at 20:24
5

Try to flush your DNS Cache with Start -> Run...

 ipconfig /flushdns

Also try to deactivate NetBIOS and LMHOSTS for your Network Adapter. You can change the settings in the TCP/IP Properties of the used Network Connection, under Advanced -> WINS.

0
4

Turns out that my corporate DNS was being hit before my hosts file. So I:

  1. Opened my TCP/IP Properties (Control Panel > Network Connections > Local Area Connection > Properties > (scroll down) Internet Protocol (TCP/IP) > Properties.
  2. Clicked "Use the following DNS server addresses:" (Instead of Obtain DNS server address automatically)
  3. entered "172.0.0.1" and "172.0.0.2" (and clicked ok)

Now my hosts file works just fine... From the command line. However, if I put an entry in for www.google.com that points to 172.17.1.107, when I ping it from the command line, it returns from the IP address I specified in the hosts file. But if I hit it from the browser, it still shows me Google instead of my local site. But if I put an entry in for "fredspc" that points to 172.17.1.107 and hit that from the browser, it takes me to 172.17.1.107.

I figured this out because if I entered "tedspc" in my hosts file (i.e. something that would never resolve) and gave it an IP address and pinged it, it would resolve to that IP address. The problem was that www.wiki.com and anything else I was entering into my hosts file had an entry in my corporate DNS server, which was causing it to resolve, which meant it never looked at my hosts file (because the corporate DNS server gets looked at first before the hosts file). So I've cut the corporate DNS out of the command prompt loop, but not out of the browser loop I guess... Any ideas?

3
  • 1
    Hi. Good to hear that you have a workaround. But as much as I know the hosts file should always be used first to make dns lookups prior to every entry in your dns server list. Is it possible to deactivate the lookup in the hosts file completely with some dhcp - options? Maybe you can add your corporate DNS Servers as third and fourth entry in your dns server list.
    – grub
    Aug 7, 2009 at 14:53
  • Perhaps your web browsers are configured with a proxy server? Dec 30, 2009 at 14:59
  • I'm guessing the DNS servers should be local IPs (127.0.0.x, not 172.0.0.x)?
    – mwfearnley
    Feb 24, 2020 at 11:46
3

According to http://technet.microsoft.com/en-us/library/bb727005.aspx it could be in your local NETBIOS name cache. You can use nbtstat to query/purge this cache.

nbtstat /c

shows the cached entries which can be cleared with

nbtstat /R
0
2

Every time I use the host file for my DNS entries (which is always) I turn off(disable) the DNS service (services.msc) running natively. Then do a ipconfig /flushdns if that fails reboot said server/desktop and that will clear the cache. What DNS entries are not in the host file the server/desktop will resort to the Default DNS settings of the Network Interface that have been setup. This also allows for testing different firewalls and such.

2

I just got caught up changing C:\windows\system32\drivers\etc\hosts when %SystemRoot% was defined as C:\WINNT instead of C:\windows... I don't know why this particular server had an entire windows installation in both C:\windows and C:\winnt but at least I don't feel insane anymore.

I feel kind of dumb but it's just another quick check for other people who run into this problem!

2

Are you sure you are editing RIGHT hosts file? Usually it located in

%SystemRoot%\system32\drivers\etc\hosts

2

After trying many different suggested solutions, I checked the security on the ‘etc’ folder and compared its permissions to that of the ‘es-ES’ folder, and found that the group Users did not have Read & execute rights like they did on the other. After taking ownership (again) of the ‘etc’ folder, I granted group Users Read & execute permissions, and had them inherited by the folder contents. That fixed the problem for me–whatever part of the system queries the hosts file evidently is under the restrictions of the User group. I must have removed the group’s permissions accidentally at some point when trying to modify the hosts file.

1
  • This fixed it for me. I just added the Users group directly to the hosts file, flushed the cache, and the hosts file was immediately respected again.
    – user51928
    May 15, 2013 at 20:44
2

Deleting the original file on windows and replacing it with a new one is important!

I know the question has been answered, but it's clear that there are many different reasons and possible solutions. What did the trick for me was to delete the file, rather than to overwrite it.

I also know that @olefebvre already posted something similiar, but I didn't recognize it with its abbreviations and it's not (only) related to odd characters, it is to bring windows to recognize the file at all.

0
2

please try to use spaces instead of tabs.

Like here:

127.0.0.1 localhost
172.17.1.107 wiki
1
  • My experience has generally been that Windows is fine with tabs in the hosts file. Has this solution worked for anyone?
    – mwfearnley
    Feb 24, 2020 at 11:08
1

Could you check your permission on the host file ? Try to use an FQDN for the hostfile "wiki" entry.

3
  • What should the permissions be (right now the file is not read only and all permissions are set to allow for all users)? I tried setting to www.wiki.com and it still didn't work. (I changed the line to 172.17.1.107 www.wiki.com) Then I opened up my command prompt and tried pinging www.wiki.com and it returned "Pinging www.wiki.com [70.35.23.23] with 32 bytes of data" but then it said "Request timed out" three times. Then anything I tried to ping returned Request timed out. I'm in the middle of a BIND install now to try and fix this, I don't know if that would effect the pings...
    – cmcculloh
    Aug 6, 2009 at 14:56
  • And now I either installed BIND wrong, or my computer is ignoring that too, because it isn't working either...
    – cmcculloh
    Aug 6, 2009 at 15:16
  • Try deleting the file and create a new one, w/o copy/pasting. Maybe some texteditor inserted odd characters in there (UTF8).
    – olefebvre
    Aug 7, 2009 at 9:47
1

have you checked hosts and lmhosts.sam?

1
  • Yeah, everything in lmhosts.sam is commented out and there's only the two lines I specified in the original question in my hosts file...
    – cmcculloh
    Aug 6, 2009 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .