The hosts file is a text file located in one place in all modern versions of Windows. Most people don’t even need to dig into this, but if you do, you will need to know how to open and edit the hosts file.
However, some versions of Windows do not allow direct editing of the hosts file. In fact, you will get an error if you try to save the changes. Fortunately, there is a simple tip you can use to edit your hosts file on Windows 10, 8, 7, Vista, or XP.
What does a hosts file do?
The original purpose of the hosts file was what DNS servers do now â€” mapping friendly domain names to hostile IP addresses.
It is much easier to remember a domain name, like YouTube.com, than an IP address, like 188.8.131.52. Instead of having to enter the IP address in the address bar every time you want to watch YouTube videos, you can simply enter the domain name and the DNS server your device is using will match the name with the correct address so you can access to a web page is much easier.
The hosts file, since it serves as a kind of DNS server, works the same way. You can enter the IP address to which the domain name should be resolved. In other words, you can tell your computer to load an IP address other than the DNS server, which will allow you to do a few interesting things.
Why is the Hosts file edited?
One of the reasons for editing the hosts file is because you want a super easy way to block websites from loading on your computer Enter an invalid or incorrect IP address for the site you want to block, and every time you try to access it, the hosts file will load the IP of your choice. Depending on what you choose, it can block the website completely.
You can use the same technique to force the hosts file to block malicious sites. There are even lists of hosts file entries (like this one) that you can download and import into your hosts file to block hundreds of malicious sites or ads.
Another use case for the hosts file is to speed up web browsing. If the DNS server you are using is down or is not fast enough, manually entering the IP address and domain name mappings in the hosts file allows your computer to find those addresses almost instantly, rather than relying on the DNS server.
Tip: Learn how to use alternate DNS servers for faster Internet access.
Windows Hosts file location
You need to know where to find the hosts file before you can open it for editing. This is the location of the hosts file on Windows 10 through Windows XP:
C: Windows system32 drivers etc
How to Edit the Hosts File
The hosts file is a text file, which means you will need a text editor to make changes to it. However, since the hosts file is super-basic and does not require working with hyperlinks, images, etc., you can use a basic text editor (i.e. no need to use a full-fledged editor like Microsoft Word).
Opening the Hosts file
Let’s start by simply opening the hosts file. We’ll be using Notepad, which is built into Windows 10 through Windows XP.
- Open the Run dialog box by holding the Windows key and then pressing R once.
- Type Notepad and press Enter to open the program.
- Go to File> Open.
- In the file name text box below, type (or copy and paste) the location of the hosts file shown above and press Enter.
- Select the menu to the right of the text box to change text documents (* .txt) to All files (*).
- Double-click hosts in the file list to open the hosts file for editing in Notepad.
Editing the Hosts file
The hosts file has several examples showing how to format entries. You must first give the IP address and then the domain name, and the two must be separated by at least one space (a tab is a good way to format them).
Here are some examples:
As you can see in the image above and read from the directions in the hosts file, the # character is used as a comment, which means that anything that follows it is avoided. This is why the above two example lines are useful in this hosts file; they are not accompanied by this symbol.
Related: edit Hosts file to add local DNS lookup
If you want to block websites with the hosts file like YouTube, Amazon, Google, Reddit.com, etc., you can enter a fake IP address like 0.0.0.0.
Note. When you enter the URL of a site that you want to associate with a specific IP address, be sure to exclude the leading part and only enter the subdomain like www or whatever for the site you add.
Save Hosts File
This is how we save the hosts file to make sure it works no matter what operating system you are using, which text editor you choose, or how your Windows settings are configured:
- Go to File> Save as.
- Change the Save as type setting to All Files (*).
- Rename the file hosts.backupfile and then save it to your desktop.
- Close Notepad and find the hosts file you just created on your desktop. You want to remove part of the .backupfile name and leave only hosts (no period or text after word).
- After that, navigate from file to another on the desktop and confirm the name change when asked.
- Copy the hosts file.
- Open the location of the hosts file that you opened earlier ( etc folder).
- Paste the hosts file you copied from the desktop and confirm any rewrite prompts if you see them.