Thursday, February 11, 2010

Tip: Easily update hosts file using batch files

1.  Open notepad.
2.  Enter the following at the top to ensure a carriage return.

    echo. >>%WINDIR%\System32\drivers\etc\hosts

3.  Enter as many host entries as you need using the following syntax:

echo [IPADDRESS][TAB][HOSTNAME]>>%WINDIR%\System32\drivers\etc\host


4. Optional:  If you want notepad to automatically open up the hosts file when you are finished, you can also add this command at the end.

start notepad %WINDIR%\System32\drivers\etc\hosts

5.  Save the file with a .bat extension.
6.  Double-click on the file.
7.  If all goes as expected, your hosts file should now look like this.