Summary
-
The hosts file is the first place Windows checks IP addresses when connecting to websites, and can be manually edited to block access to certain websites.
-
The hosts file is located in the “C:\Windows\system32\drivers\etc” folder in both Windows 10 and 11, and you will need administrator rights to edit it.
-
To block a website using a hosts file, point the URL to 0.0.0.0 or 192.168.0.1.
The hosts file is the first place Windows checks when connecting to a website. You can edit it manually to block access to certain websites. Find out what it is, where it is, and how to edit it.
What does the hosts file do?
When you enter a regular web address to access a website, such as google.com, your computer does not automatically determine how to connect. To establish a connection, the correct IP address associated with the web address is required.
The hosts file is the first place your computer will look to find a website's IP address, but by default the hosts file does not contain one. If your computer cannot find an IP address in the hosts file, it checks the DNS cache or connects to DNS server. When a web address and IP address are inserted into a hosts file, it will provide that information to your computer every time you try to connect to that web address.
If the hosts file instructs your computer to find a web address from an IP address that does not connect (for example, 0.0.0.0), it blocks access to the website.
Windows Hosts File Locations
The hosts file is located in the “C:\Windows\system32\drivers\etc” folder in both Windows 10 and 11. Editing it requires administrator rights, which means you can't just open it in a regular Notepad window.
How to Edit Windows Hosts File
You can edit the hosts file in any text editor. There are many different programs available, but both Windows 10 and 11 come with Notepad and I'd recommend sticking with it. Avoid using a word processor –differences between Notepad and a word processor such as Microsoft Word can sometimes cause problems.
You will need to run Notepad as an administrator to edit the hosts file. To do this on Windows 11 (or Windows 10), click the Start button and type notebook to the search bar. On the right, click “Run as administrator.”
Once Notepad opens, click File > Open and navigate to C:\Windows\System32\drivers\etc.
By default, Notepad is set to search for TXT files, so you'll need to set it to search for “All Files” from the drop-down menu instead. Then click on the hosts file and click Open.
Once the hosts file is open, you can start adding lines to block websites. The lines included in the hosts file can be broken down into three main components, each of which is separated by at least one space.
Number |
Component |
Description |
---|---|---|
1 (Green) |
IP address |
This will tell your computer where to look for the website. |
2 (blue) |
Web address |
This is the address of the website you want to block. |
3 (purple) |
Comment |
Where you describe what the string does. There should be a hashtag before the comment. |
You don't need to include a comment for the hosts file to work, but commenting on files as you edit them is a great habit to get into.
When you're done adding rows, click File > Save to save your changes. After clicking the “Save” button, the pop-up window should not appear. If yes, this means that Notepad does not have administrative access and you need to close Notepad and run it as an administrator. After successful saving, exit Notepad.
There are two addresses: 127.0.0.1 and 0.0.0.0, which are commonly used in the hosts file to block traffic. There are significant differences between 127.0.0.1 and 0.0.0.0but in most cases either one will do. In rare cases, a program running on your computer may have problems if you use 127.0.0.1, so it's best to stick with 0.0.0.0.
If you can still connect to blocked addresses
The latest versions of Google Chrome, Mozilla Firefox, and Microsoft Edge use DNS over HTTPS (DoH) by default. DNS over HTTPS works the same as a regular DNS server, however DNS over HTTPS encrypts your requests to improve your privacy.. Encrypting your queries means that third parties will not be able to know what queries you sent to the DNS server or how the server responded.
When DNS over HTTPS is enabled in a browser, the browser bypasses the normal DNS client in Windows 10 and 11. This means that the browser completely ignores the hosts file and instead uses the secure DNS server specified by the browser, so any addresses you try to block using the hosts file will be accessible. If you want to use the hosts file to block web browser traffic, you need to disable DNS over HTTPS in your browser.
Luckily you can enable DNS over HTTPS in Windows 11. This will allow you to use a hosts file to block addresses while still maintaining the benefits of DNS over HTTPS.