Mastering the Hosts File: A Comprehensive guide to Blocking Websites on Windows
The hosts file is a powerful, yet often overlooked, tool built directly into your Windows operating system. It allows you to override the Domain Name System (DNS), effectively blocking access to specific websites or redirecting them to different locations. This guide will walk you through everything you need to know to harness the power of the hosts file, ensuring a secure and customized online experience.
Understanding the Hosts File
Essentially,the hosts file acts as a local DNS server.When you type a web address into your browser, your computer first checks the hosts file before querying external DNS servers. If a match is found, your computer connects directly to the specified IP address, bypassing the usual DNS lookup process. This makes it a highly effective method for blocking unwanted content.
Locating and Opening the Hosts File
First, you need to find the hosts file on your system. Here’s how:
- Open File Explorer.
- Navigate to
C:WindowsSystem32driversetc. - Locate the file named “hosts” (it has no file extension).
Important: You’ll need administrator privileges to open and modify this file. Right-click on Notepad and select “Run as administrator” before proceeding.Then, open the hosts file within Notepad.
Editing the Hosts File: A Step-by-Step Guide
Editing the hosts file is straightforward, but requires precision. Here’s how to add entries to block websites:
- At the bottom of the file,add a new line for each website you want to block.
- Each line should follow this format:
IP address website address. - For blocking, use the IP address
0.0.0.0.
Here are a few examples:
* 0.0.0.0 www.example.com
* 0.0.0.0 example.com
* 0.0.0.0 adserver.example.net
You can also add comments to your entries for clarity. Use the # symbol to denote a comment. Such as: # Blocked for privacy reasons.
Once you’re done adding lines, click File > Save to save your changes.There shouldn’t be a popup after you click save. If there is, it means Notepad does not have administrative access, and that you need to close Notepad and run it as administrator. Once you’ve saved successfully, go ahead and exit Notepad.
Choosing Between 127.0.0.1 and 0.0.0.0
Two IP addresses are commonly used in the hosts file: 127.0.0.1 (localhost) and 0.0.0.0. While both can block access, there are key differences. 0.0.0.0 is generally the preferred choice. Rarely, a program running on your PC might have problems if you use 127.0.0.1, so it is indeed best to stick with 0.0.0.0.
Troubleshooting: When Blocking Doesn’t Work
Sometimes, despite correctly editing the hosts file, you might still be able to access blocked websites. This is often due to a feature called DNS over HTTPS (DoH).
Understanding DNS over HTTPS (DoH)
Recent versions of popular browsers like Chrome, Firefox, and Edge utilize DoH by default. DoH encrypts your DNS queries, enhancing your online privacy.Tho, this encryption can bypass your Windows hosts file.
When DoH is enabled, your browser directly contacts a secure DNS server, ignoring the local rules set in your hosts file. Consequently, blocked websites remain accessible through the browser.
resolving DoH Interference
To ensure the hosts file functions as intended, you have two options:
* Disable DoH in your browser: This forces your browser to use the standard Windows DNS client, which respects the hosts file.
* **Enable DoH