What Is the Windows Hosts File?

If you’ve ever used a phone company’s directory, you’d know how it maps any phone record to a unique person, business or residence. In the same manner, the hosts file in any operating system matches IP addresses with unique domain-based hostnames (or websites), server names, proxies, and more. In Windows systems, as with Linux or Mac, the hosts file’s main purpose is to enable simple IP address mapping of hostnames and servers. Therefore, it is similar to the Domain Name System (DNS). Each hosts file entry follows the default localhost entry in a separate line. Each line is preceded by a hash (#) symbol that allows you to insert comments. The real applications of the Windows hosts file requires you to omit the # sign.

Where Is the Hosts File on Windows?

The Windows hosts file is always found at “C:\Windows\System32\Drivers\etc.” It’s a text file that is not associated with any program. You can easily open it with Notepad though. Note: If you try adding another file with the name “hosts” to the “etc” folder, it will have negligible impact on the original hosts file process, as you’re simply renaming it as another duplicate file.

How to Open the Hosts File in Windows as Administrator

The only way to open the hosts file in Windows as the administrator is to use Notepad. The reason you need Admin access is that the hosts file’s internal entries can only be managed by users with the highest admin privileges.

How to Edit My Hosts File in Windows

Here we will learn how to modify the hosts file in Windows, which is how the end use applications are served. Note: if you forget to edit the hosts file as an admin user in Windows, you will encounter a “You don’t have permission to save in this location. Contact the administrator to obtain permission” message.

Applications of the Windows Hosts File

As the hosts file can override the DNS server, it can achieve advanced objectives, such as blocking or redirecting any website or URL of your choice.

1. Edit Windows Hosts File to Block Websites

You can use the Windows hosts file to remove time-wasting URLs, entertainment sites, and other websites you don’t want to visit. Don’t want to spend time on Netflix? Simply block it entirely at a system level. There may be a time you need to block multiple domains of the same service as individual entries in the hosts file. For example, it treats “twitter.com” and “m.twitter.com” as two separate entries. After you save the list of blocked websites in Notepad, you won’t be able to access it on a browser again unless you edit the hosts file to regain access. This blocking method is supported on Google Chrome, Microsoft Edge, Firefox, Opera and many other browsers. It is very important to delete the browser cache after blocking the website in the hosts file, otherwise, it will keep loading again. Apart from the major browsers, you can also block websites on less-used alternative browsers such as SlimBrowser.

2. Edit Windows Hosts File to Redirect Websites

You can use the Windows hosts file to redirect any website to another URL. This may not always be supported due to security certificate conflicts.

3. Spam and Malware Protection with Hosts File

The Windows hosts file can also be used to manage multiple spam user links, third party sites, cookies, ad trackers, and surveillance bots. It can be used to keep malware sites at bay. Browsers such as Firefox give you a complete list of trackers and bots on any webpage. If you want to frequent a website while avoiding its spammy links, simply add them as blocked entries in a host file.

1. Why is my hosts file not working?

Is Windows not able to read the hosts file on your computer? You may encounter this error when you don’t set the line endings properly in Notepad as an admin user. It really boils down to syntax errors in saving the entries. The good thing is these problems are very easy to fix. To avoid possible errors in entries saved using the Windows hosts file, make sure you copy-paste the entire first sentence containing “127.0.0.1” and “localhost” in the default entry. Use it to modify each and every line below.

2. How can I clear my hosts file in Windows?

Clearing the hosts file is very easy. This allows you to reuse the hosts file document just as it was in a previous state.

3. How can I reset the Windows hosts file back to the default?

Sometimes you may face errors in the Windows hosts file configuration, especially after it was changed several times. To undo these errors, it’s a good idea to reset the Windows hosts file back to its default state.

4. Can I delete the Windows hosts file?

While the hosts file has a very powerful function in blocking websites, interestingly, it’s just an optional system resource in Windows 11/10. You can easily delete the hosts file from your PC without it affecting the PC operations in any way. You can always recreate a new hosts file by resetting it as a default in Notepad using the method shown above.

5. Can malware affect the hosts file?

As the hosts file has a powerful role to play in blocking and redirecting websites in Windows, it is a favorite attacking point for malware authors. Sometimes even Windows Defender may incorrectly determine that the hosts file was changed by malware or spyware. In this case, you can exclude the hosts file from being scanned by Windows Defender while you correct the malware links inserted inside the file. Yet, in other cases, malware authors may name their malware after hosts and try to place it in the etc folder. Image credit: Pixabay