Enkidu said:
The hosts file is not loaded at startup. It is read every time that
the computer needs to resolve a name that it doesn't know about.
No, it is loaded into memory (or more correctly the DNS resolver cache) at startup by the
TCP/IP Protocol Driver. It is also reloaded every time the hosts file is changed (the
Protocol Driver service gets a file change notification from the OS when the file is
edited).
Do a "ipconfig /displaydns" in a command prompt before and after a edit of the hosts file
to see this effect (you may want to do "ipconfig /flushdns" first to start with clean
sheets and avoid a lot of scrolling).
The file itself is not read when the computer needs to resolve a name that it doesn't know
about. Monitor the file access on your computer with filemon.exe from
www.sysinternals.com
if you want to, and you will not see any access from services.exe or any other file
against this file in this case. But if you change the file, you will see that services.exe
reads the file afterwards.
eg, if you ping notvalid you will get a message saying "Ping request
could not find host notvalid". However if you then add a line to
hosts, such as 111.111.111.111 notvalid, then ping notvalid you will
get a message "Pinging notvalid\ [111.111.111.111] with 32 bytes of
data:" without rebooting or anything.
The problem described was with the cached values, so the above doesn't
make any difference. However the Microsoft workaround is pretty
drastic. It *should* be possible (though I've obviously not checked
this) to refresh the cached entries by merely editting the hosts file
so that its access date is changed. This should I believe force the
re-read of the hosts file. But I'd have to wait a year to test it!
Editing the file will not reset the Time-To-Live for the entries in the DNS cache and you
do not need to wait a year to test it ;-) You can check this by looking at the TTL values
for each entry by running "ipconfig /displaydns" before and after a edit on the host. Even
deleting the entries from the hosts file, saving the file, running "ipconfig /flushdns",
and then adding the entries back will not reset the TTL value.
Also new entries in the hosts file will get the same TTL value as the ones that originally
was there, so this is a global value that starts at approx. 31536000 (60x60x24x365) when
the computer is started up and then is decremented with 1 for each second. If 0 is
reached, all the host names from the hosts file are no longer resolved, and you need to
reboot the computer (unless you have SP4 installed).