The hosts file is a plain text file used to map host names to IP addresses. On Windows, it is located in the C:\Windows\System32\drivers\etc folder.

Note that the "Hosts" file is owned by the "System" account [NT AUTHORITY/SYSTEM] and may only be modified by an administrator.

Preparation

To prepare for this activity:

  1. Start Windows.
  2. Log in if necessary.

View the hosts file

To view the hosts file:

  1. Open the Start menu.
  2. In the Run box, type Notepad.exe and press Enter. Note: If you will be editing the hosts file in the next activity, you must right-click on Notepad and Run as administrator rather than press Enter.
  3. In Notepad, select File then Open.
  4. Navigate to C:\Windows\System32\drivers\etc.
  5. Change the file type to open from Text Documents (*.txt) to All Files (*.*).
  6. Open the hosts file.
  7. Read the comments in the host file. The comments begin with a # character.
  8. Observe the host records stored in the file. At a minimum you should find a record for 127.0.0.1 localhost.

Edit the hosts file

To edit the hosts file:

  1. Change the line 127.0.0.1 localhost to 127.0.0.1 localhost me.
  2. In Notepad, select File then Save to save the file.
  3. Open a command prompt.
  4. Type ping me and press Enter.
  5. Observe the results. The ping should be successful, because the name me is now defined as an alias for the loopback address 127.0.0.1.
  6. In Notepad, remove me from the line 127.0.0.1 localhost and then save the hosts file.
  7. In the command prompt, type ping me and press Enter.
  8. Observe the results. The ping should fail, because the name me is no longer defined as an alias for the loopback address.
  9. In Notepad, add a line of 8.8.8.8 googledns and then save the hosts file.
  10. In the command prompt, type ping googledns and press Enter.
  11. Observe the results. The ping should be successful, because the name googledns is now defined as an alias for 8.8.8.8.
  12. In Notepad, remove the line of 8.8.8.8 googledns and then save the hosts file.
  13. In the command prompt, type ping googledns and press Enter.
  14. Observe the results. The ping should fail, because the name googledns is no longer defined as an alias for 8.8.8.8.
  15. Close the command prompt and close Notepad to complete this activity.

Readings

References