If the hosts file on Windows XP does not work

I just had one of these dreaded occurrences where the hosts file did not work on a Windows XP installation. (Yes, you read that correctly: “Windows XP”. I still have got a few installations of that to maintain.)

I could not figure out what the problem was, so I turned to Google which found “hosts file ignored, how to troubleshoot?” on ServerFault. The accepted answer lists several steps to trouble shoot. The one that helped me was:

5. Permissions
Sometimes there are issues with permissions on the file, the file
attributes, and similar things. To recreate the file with default

    1. Create a new text file on your desktop.
    2. Copy and paste the contents of your current hosts file into
       this file in Notepad.
    3. Save the new text file and rename it to hosts.
    4. Copy (do not move) the file to your
       directory, and overwrite the old file.

Last point is important: Copying works, moving doesn't.

Unfortunately the described steps did not work for me because I already had moved the hosts file from the desktop to c:\Windows\System32\drivers\etc so the original file and its permissions was already overwritten. What I did to solve this was:

  1. Follow the steps 1 to 3 above.
  2. Delete the original hosts file in the %SystemRoot%\System32\drivers\etc directory
  3. Copy one of the other files in that folder (I used “services”) and rename the copy to “hosts”
  4. Follow step 4 above

Now ping works as expected and connecting to the Embarcadero License Server also does.