Hosts file/Edit
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:
- Start Windows.
- Log in if necessary.
View the hosts file
To view the hosts file:
- Open the Start menu.
- 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.
- In Notepad, select File then Open.
- Navigate to C:\Windows\System32\drivers\etc.
- Change the file type to open from Text Documents (*.txt) to All Files (*.*).
- Open the hosts file.
- Read the comments in the host file. The comments begin with a # character.
- 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:
- Change the line 127.0.0.1 localhost to 127.0.0.1 localhost me.
- In Notepad, select File then Save to save the file.
- Open a command prompt.
- Type ping me and press Enter.
- 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.
- In Notepad, remove me from the line 127.0.0.1 localhost and then save the hosts file.
- In the command prompt, type ping me and press Enter.
- Observe the results. The ping should fail, because the name me is no longer defined as an alias for the loopback address.
- In Notepad, add a line of 8.8.8.8 googledns and then save the hosts file.
- In the command prompt, type ping googledns and press Enter.
- Observe the results. The ping should be successful, because the name googledns is now defined as an alias for 8.8.8.8.
- In Notepad, remove the line of 8.8.8.8 googledns and then save the hosts file.
- In the command prompt, type ping googledns and press Enter.
- Observe the results. The ping should fail, because the name googledns is no longer defined as an alias for 8.8.8.8.
- Close the command prompt and close Notepad to complete this activity.