The Idea Dude

CONNECTING THE DOTS ONE AT A TIME

Thursday, April 20, 2006

The answer to the billion dollar question!

My blog has finally been able to contribute something material to the technical world rather than a philosophical meandering through life in the startup lane. For all those poor people with hosts files that don't work, here is the answer...but first you'll have to excuse the lengthy discourse of how I got there. It is relevant because it is a comprehensive collection of remedies suggested by well-meaning techies that will lead you to nowhere.

We created an internal staging server for our web application. Because it was using an internal IP and we weren't running a DNS server of our own, adding local IPs to the hosts file was the best solution for us. Behold, the entries did nothing for me on my machine. Here's the long arduous route I took over two days and one sleepless night before I found the solution.
  • Checked on my partner's machine, it worked fine...on my machine, it was as if the hosts file didn't exist.
  • Thought it was the lmhost caching that had precedence or somehow bypassed the hosts file. After much reading, the lmhosts file is there to map names to IPs for Netbios. It is the last resort if the DNS server/client caching, hosts file doesn't resolve the name. It became the proverbial redherring because putting the names into the lmhosts file work for some names and not others. Turns out that only the first 15 characters (Microsoft uses the 16th one) are relevant so names shorter than 15 chars worked and others didn't. Bottom line, the lmhosts file could mitigate your problem but doesn't solve it especially if you have urls longer than 15 characters. Back to square one. (btw: use nbtstat to clear and display the lmhost cache)
  • Someone posted a workaround. Stop the DNS client service, yup, hosts file worked. Ping works. Basically meant there was nothing wrong with the hosts file (or was there? see later). When you stop the DNS client, DNS entries don't get cached and applications instead of querying the cache read the host file separately. While it would work, it meant all queries would hit the DNS server, not ideal so the search goes on.
  • Found out how to flush the DNS client cache using ipconfig/flushdns and ipconfig/displaydns. While I've been able to edit hosts files on other machines with immediate results, I tried the brute force approach and flushed the cache which usually reloads the hosts file. No dice...
  • Went back to the dude principle and googled the world...while most posts were about how to use the hosts file to block ads, there were quite a number of people with the same problem over the last 4 years. No solution, just lots of suggestions.
  • Just to be sure I wasn't being stupid, checked the hosts file had no extension like txt. Compared registry and network settings with a machine on which hosts file worked. Checked the syntax was correct and the order was right, ip first and then name. Made sure there was only one hosts file on my entire drive (Remember, hosts file worked if DNS client is turned off? so it couldn't be that could it?)
  • Made sure there wasn't something hijacking the hosts file, there's a registry setting under tcp-ip settings that points the drivers\etc subdirectory where the hosts file resides. Nope, destination was secure.
  • Reset the tcp-ip settings as per another support article on the Microsoft site. That didn't work. Stopped short of fixing my winsock dll 'cos that didn't make sense.
  • Went to bed, woke up in the middle of night thinking maybe it was the environment variables that need to include the path to the etc directory i.e. the DNS client couldn't find the hosts file. Added that to the path. Nice try but no cigar. This was one tough hombre.
  • Checked to see if I had a rogue DNS client, dnsrslvr had the same size and date as other machines. In desperation...back to reading more posts in groups.google.com...with dismay to see some of these posts date back to 2002.
  • Someone suggested the file maybe readonly (duh?) or could be permissions. I'm logged on as the administrator on my machine. Shouldn't be the problem. But wait...someone said that they moved the contents to another file that didn't have ctrl-z (end of file) and it worked. Go back and check the file properties...all my files in the etc directory were dated 1 January 1980, hmmm....

Ta da! renamed the hosts file, created another file in notepad (fresh new file), cut the contents from the old hosts file and paste it to the new file and saved it. Works! All is calm in the world of theideadude. Actually, not calm but the gnashing of teeth is now replaced by the whoops of euphoria. Apparently the ctrl-z had been sufficient to throw the DNS client out even though the other utilities like ping worked fine. It is unclear to me why my files were dated 1980 (creation date not modification). They weren't the culprit as I subsequent found out. Note: copying the file doesn't work because it keeps the ctrl-z. I have no clue how the date was 1980 or maybe it was the Unix admin who was let loose on my machine a year ago...that would remain a mystery for the ages.

So this rather lengthy explanation is to ensure that some poor soul does not wait 4 years like some I found on the web or spend the last 24 hours like I did trying to solve this mystery.

The most apt way to end this post is to echo an advertisement I saw once (with a bit of my creative embellishment)...Technology is like tabasco sauce (and love), it can hurt so much but it always makes you come back for more....

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home