I spent the better part of yesterday wrestling with what should not have been a problem in the first place. But, since it was, and since it managed to burn up the majority of a perfectly good day of development, I share this information in hopes that it will spare someone else my frustration.
The Scenario
You're OS is Windows Vista Home Premium, the 64 bit edition. You are attempting to set up a local dev environment using Apache and MySQL, but no matter what you try, the changes you make to your hosts file just will NOT become visible to your ping attempts! For instance, you add an entry such as "127.0.0.1 local.mydev", but when you go to a command window and try to "ping local.mydev", you get "host not found". SO not cool.
Editing the hosts file
Okay, a few words about editing the hosts file in Vista. Vista is very self-protective, even to the point of trying to protect you from yourself, so editing the hosts file requires that you do so with admin privileges. Ah, but just being logged in as an admin isn't enough; you have to start notepad (or whatever editor you're using) using the "run as administrator" option. Click Start, enter 'notepad.exe' in the search box, when it shows up in the results, right click it and choose 'run as administrator'. THEN you can open your hosts file and edit it. Make sure when you go to save it that you change the file type to *.any and overwrite the original file; By default notepad really really wants to create hosts.txt (which your browser would ignore). If you plan on making hosts file changes frequently, you may as well just set up a shortcut on your desktop that already has admn privs and already points to your hosts file. Create a new shortcut with the target property of "C:\Windows\System32\notepad.exe c:\windows\system32\Drivers\etc\hosts". Then click the 'Advanced' button on the shortcut tab and check the "Run as administrator" box. Now everytime you need to edit the hosts file, you'll already have admin privs to do so.
The Solution
SO THEN, back to the issue. At this point you know that your changes to the hosts file are being saved, but still no positive ping action taking place. After googling for hours and trying all SORTS of things, here are the steps I followed that gave me positive results.
1. First, make certain that the system is looking at the same hosts file you are. The odds that it's looking somewhere else are slim, but best to eliminate the possibility anyway. To verify hosts file location, you'll be launching regedit and looking for the value of the registry key "DatabasePath" in the Tcpip/Parameters (full key path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters). The value should look similar to %SystemRoot%\System32\drivers\etc .
2. Stop the "DNS Client" service
3. Make sure that the hosts file name is all lower case. It shouldn't make a difference, but the information I found all references it that way and on Vista, it was actually named Hosts originally. Changing it's name can be a booger because of OS security, so to do so, see step 4....
4. Create a new hosts file. I tried using notepad, but could not get it to omit the ".txt" extension no matter what I tried, so ended up using EditPad Pro (freeware). Just delete or rename the old file, then create this new one, adding in the entries you need.
5. Go to a command window and test by trying to ping one of the entries you created. With the DNS Client service stopped, Vista should use your hosts file. At this point in the game, you should definitely have positive results.
6. Restart your DNS Client service, then re-test in a command window just to make sure it's still working as designed.
If you follow the steps above and it still doesn't work, I have no clue what to tell you except to perhaps try re-ordering the steps, toss in a reboot or two, try executing some ipconfig /flushdns commands. Some order of all of the above is what finally got me where I needed to be.
Oh,and if you learn anything in the process that I haven't caught on to, please come on back and leave that tidbit in the comments section of this post. If you do, all of your wildest dreams will come true.
Doug out.
You are not logged in, so your subscription status for this entry is unknown. You can login or register here.
My guess is, that you, by creating a new hosts file, accidently gave permissions to the networkservice to actually read that file. I'm not quite sure, why it hadn't these rights in the first place.
but it seems that if dns service is ON, it just skips the hosts check all together. ERR


