The hosts file is a part of the operating system on your computer that maps hostnames into IP addresses. This file is like a telephone book for your computer. It converts human-friendly hostnames to IP addresses your machine can understand. It may be necessary to edit this file for testing, troubleshooting or blocking websites. Here’s the guide to editing the hosts file on Windows 7.
What exactly is the host file?
Overview
The hosts file is a text file in ASCII format that matches IP addresses with hostnames. Your computer will default to refer to the hosts before contacting the DNS servers on the internet. You can override DNS on your local computer by using the hosts file.
Find the hosts file in Windows 7
Path To Hosts File
In Windows 7, the hosts file is located at C:\Windows\System32\drivers\etc\hosts
. The file is hidden, and you need administrative rights to view and edit it.
Editing the hosts file
Be sure to create a copy of your hosts file before you make any changes.
Open Notepad as Administrator
You will need to use a text editor that has administrative rights in order to edit the hosts file. Search for Notepad, click on it and choose ‘Run As Administrator’.
Open the hosts file in
In the Notepad, go to File > Open, and navigate to the location of the hosts file (C:\Windows\System32\drivers\etc\
). Type hosts
in the filename and click Open.
Edit the hosts file
You will find a host file that contains comments (lines beginning with ‘#’), followed by IP addresses and hosts). You can block a particular website by adding a line to the end of your hosts file. Enter 127.0.0.1
followed by the URL.
Save your changes
To save your changes, click File > Save. If you have trouble saving, ensure that you are running Notepad with administrator rights.
Validating changes and troubleshooting
Clear the DNS Cache
You should flush the DNS cache after editing your hosts file to ensure that your changes are immediately applied. Enter ipconfig
and press Enter.
Check your changes
You can use the Command Prompt to ping the hostname that you added in the hosts file. You should see the IP address of the hostname if you mapped it to 127.0.0.1
.
Troubleshooting
You should check your administrative rights and make sure you typed in the filename and path correctly if you run into problems. Check your antivirus and firewall settings as certain software may block system file changes.
Conclusion
The hosts file allows you to control the way your system interacts on the Internet. It should, however, be used with caution. Create a copy of your document before you edit it. If you are unsure, you may want to seek professional advice.