How to block hosts
How to block hosts
How to Block Websites By Editing the HOSTS File in Windows
DNS, which stands for Domain Name System, can convert the elusive IPv4 or IPv6 addresses to meaningful names, and then translate the characters back to IP addresses. For example, when you want to visit a website, DNS will tell your web browser the real IP address of it, and then web browser will download the web page directly from that IP address.
As you may expect, the process of translating IP addresses to website names will consume some time, which could cause access delay. Particularly, if the DNS servers are down, you will not be able to visit most websites through their URL, which isn’t uncommon.
Hence, it is necessary to make a list for mapping hostnames to IP addresses. That is what Windows HOSTS file does. On most Windows systems, the HOSTS file content is used preferentially over other methods, such as the DNS.
With the proper use of Windows HOSTS file, you can accelerate the access speed of favorite websites, test a website locally and even selectively block certain websites (Image by technet).
In fact, blocking websites through the HOSTS file is an effective way to do it because it blocks it across all the browsers (we’ve previously discussed methods to block sites in Internet explorer and Google Chrome).
This article has some tips to manage the HOSTS file and block websites with it. The two methods I’ll discuss here are:-
1. Edit HOSTS File Manually
Windows NT platform systems including Windows 2000, Windows XP and Windows 7 have their HOSTS file in the path %SystemRoot%\system32\drivers\etc\ (“%SystemRoot%” is relative path, which depends on the system-wide environment variable, it should be C:\Windows or C:\WINNT in most cases).
Basically, you just need to type the above mentioned path in Windows search bar (or run box) to get to the “etc” folder where you’ll find the HOSTS file.
You can use any text editor to open the file and edit it manually.
The HOSTS file contains lines of text including an IP address and one or more hostnames. You can add the mapping relationship of each websites. The comment lines are indicated by a hash (#) character, which will be ignored by system.
To block a website, simply add a line like this:
127.0.0.1 (or Localhost) is the standard hostname given to the address of your computer. You mapped the website name to your PC, hence you can’t visit the site any more. So if you want to block Facebook, just add this line: 127.0.0.1 facebook.com
2. Edit HOSTS File with HostsMan Editor
HostsMan Editor (via cybernet news ) provides a sleek interface for managing your HOSTS file. If you are going to use your HOSTS file often, I recommend you use this tool.
As you see in the screenshot above, the add button can let you add the sites you want to block. You just need to map them to the localhost IP.
You can add, delete or temporarily disable the items with this tiny tool. What’s more, it can list potential risks items in “Possible Hijacks” section.
So that was about how to make use of the HOSTS file in Windows to block websites.
Also check our review of OpenDNS, another way to filter the websites that get accessed on your computer.
Last updated on 07 February, 2022
The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.
Read Next
DID YOU KNOW
Windows Hello is a biometric authentication feature in Windows 10.
More in Windows
Top 3 Ways to Delete Temporary Files on Windows 11
Top 7 Ways to Fix Startup Programs Not Launching on Windows 10
JOIN THE NEWSLETTER
Get Guiding Tech articles delivered to your inbox.
How to Lock, Manage, Edit Hosts File in Windows 11/10
The Hosts file in Windows 11/10, is used to map hostnames to IP addresses. This Hosts file is located deep down in the Windows folder. It is a plain text file, and the size of the original default Hosts file is around 824 bytes.
Hosts File in Windows 11/10
Let us take a look at them.
Host file location
The Hosts file in Windows is located at the following location:
Lock Hosts file to prevent hijacking
Imagine clicking on www.thewindowsclub.com and seeing a completely different website load in your browser. Malware can redirect Web addresses on your computer by altering your Hosts file. This is referred to as the Host File Hijack.
To prevent Host file hijacks, you may navigate to it, right-click on it, select Properties and make it a Read-only file. This will lock down your Hosts file and prevent anyone or any malware from writing to it.
Block website using the Hosts file
To block a website using the Hosts File, simply add the following entry:
Although I do not do it, many users like to manually add entries to it in order to block the opening of one or more particular websites. Others, like to download and use List from well-known sources like mvps.org, to add entries that block malware sites from opening.
How to edit Hosts file in Windows 11/10
Now let us go into a detailed explanation.
To edit the Hosts file, navigate to the following folder location:
Here you will see the Hosts file. Right-click on it and select Notepad. Make the changes and Save.
But sometimes, even when you are logged on with administrative credentials, you may receive the following error message:
Access to C:\Windows\System32\drivers\etc\ hosts was denied
Cannot create the C:\Windows\System32\drivers\etc\hosts file. Make sure that the path and file name are correct.
In this case, type Notepad in Start search and right-click on the Notepad result. Select Run as administrator.
Open the Hosts file, make the necessary changes, and then click Save.
Using free Hosts File Editor software
If you are looking for an easier way, you can use a free Hosts file Editor software.
1] Using HostsMan
While you can always manually manage or edit Hosts file manually, I would like to suggest that you use a third-party freeware tool like HostsMan to do it.
HostsMan is a feature-rich tool that lets you add, remove, edit entries in the Hosts file. It also lets you easily add third-party Hosts lists that help in blocking malware sites and lets you easily enable or disable the Hosts file. It includes a built-in hosts file updater & a hosts editor. It lets you scan the hosts file for errors, duplicates, and possible hijacks – and also lets you create an Exclusion list. One more useful feature it offers is the Hosts file backup manager. Backup your Hosts file to a safe place and use it to restore it, should the need arise.
Hostman also lets you Flush DNS cache, open Hosts with a text editor, count the number of hosts, find duplicates, replace IP, scan hosts for malicious entries, rearrange hosts, manage DNS Client Service and more. In short, it’s the only Hosts Manager that you will even need. You can download it from its home page.
2] Using SysMate Hosts File Manager
SysMate Hosts File Manager and is another tool that lets you do so. With Host File Walker you can add as many records to the system hosts file. It even lets you backup and restore the Hosts File.
3] Using Host File Editor tool
You can download it from here. It offers a portable version too.
TIP: See this post if Hosts File is not working in Windows. How to manually reset the Hosts file back to default in Windows may also interest you.
If your browser has been hijacked, you might find this post on Browser Hijacking and Free Browser Hijacker Removal Tools helpful.
Date: January 23, 2021 Tags: Hosts, Security
How To Block Websites On Windows Using The Hosts File
Protect your kids, stop trackers, eliminate distractions
Why would you want to know how to block websites? Maybe you want to keep your kids safe on the Internet? Maybe you want to block distracting websites so you don’t procrastinate? It can also be used to block tracking sites that are embedded in ads.
Whatever your reason, you can simply block websites on Windows 10 using something called the hosts file.
The text below can get a bit technical, especially if you have never gotten into the nuts and bolts of Windows system files. If you want a quick overview, be sure to check out our short and easy to follow YouTube video first.
What Is The Hosts File?
Have you heard the term DNS (Domain Name System)? It refers to a system of files distributed around the Internet that help resolve domain names like helpdeskgeek.com into its actual Internet Protocol (IP) address which happens to be 13.225.198.106. That helps your computer know what server to talk to when you want to view this site.
Before DNS came into being in 1984, this was done through a local file on your computer called the hosts file. Back then computers weren’t connected to many other computers. At most, we may have connected to a few dozen. It was easy to keep all that information in a plain old text file. The host file lives on today.
How Does The Hosts File Work?
The hosts file allows the computer to look up other computer names, like localhost, or domain names, like helpdeskgeek.com and the IP number for them is right beside the name in the file. It’s a bit like how your friends’ names are associated with their phone numbers in your phone. You don’t need to remember or punch in the number, just find the person’s name.
Before we go further it’s important to understand that some IP addresses are reserved for local use. That means that they can only be used to point to your computer and devices within your immediate network. That means anything before your communication connects to the Internet.
For example, the IP address 127.0.0.1 always means the computer you’re working on, also known as localhost. Try typing that in your web browser. It will likely bring up a blank page.
Also understand that www.website.com and website.com are not the exact same thing. For both of them to take us to the same website both must resolve to the same IP address.
Blocking Websites With The Hosts File
Enter the localhost IP of 127.0.0.1. Press the tab key and enter facebook.com. Press Enter to go to the next line. Create a second line like the one above, but use www.facebook.com instead of just facebook.com.
Is The Website Blocked?
Open the command prompt and run ping facebook.com then run ping www.facebook.com. You should see that the IP address it’s trying to ping is 127.0.0.1.
Now open your web browser and go to facebook.com. It might still load! Why? Facebook’s real IP may still be sitting in the browser cache and the browser will use that IP first. Delete your browser’s cache and try Facebook again. You should now see an error page.
I Don’t Want to See an Error Page
You could try redirecting the site to another IP address, but these days that won’t work well. Maliciously editing the hosts file used to be a common attack by hackers. Now, web browsers check carefully for certificates to prevent this. But, you can still try.
Another way to not see an error page is to install and set up a web server on your computer and have the hosts file point to that. Maybe have it display a page that says, “Get back to work!” or lists some of your goals as motivation to stay off social media.
What Else Can I Do With The Hosts File?
You can use the same technique but paste in the URLs of various malware and tracking ad sites. There is a pre—made hosts file of malware and ad sites that you can copy and paste into your hosts file. As of writing this, it was last updated in March, 2020.
Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches. Read Guy’s Full Bio
How to Block Websites via Hosts file in Windows 11
In this guide, we will show you the steps to block the website of your choice using the Hosts file on your Windows 11 PC. A host file on your Windows PC is used to map hostnames to IP addresses. But that is more along the technical terms. Out of all the plethora of tasks that this file beholds, there’s no denying that its major role is associated with the blocking of websites. Many network administrators usually opt for this method due to its dual benefits involved.
First off, you don’t need to take the help of any third-party app or antivirus. Moreover, many users are now well and aware of the methods to bypass or remove the blocked websites using the firewall or antivirus app. But this host file methodology is something that not many seem to be aware of. All in all, there could be quite a few reasons why one would consider blocking websites using the Hosts file in Windows 11. And in this guide, we will show you how to do just that. So without further ado, let’s get started.
How to Block Websites via Hosts file in Windows 11
That’s it. These were the steps to block websites using the Hosts file in Windows 11. If you have any queries concerning the aforementioned steps, do let us know in the comments section. We will get back to you with a solution at the earliest.
About Chief Editor
Sadique Hassan
A technical geek by birth, he always has a keen interest in the Android platform right since the birth of the HTC Dream. The open-source environment always seems to intrigue him with the plethora of options available at his fingertips. “MBA by profession, blogger by choice!”
Block Websites Using Hosts File in Windows 10
How to Block Websites Using the Hosts File in Windows 10
Every Windows version comes with a special Hosts file which helps resolving DNS records. In addition to your network configuration, the file can be used to define a domain=IP address pairing which will have priority above the value provided by the DNS server. Using this trick, you can block certain web sites from opening in the web browser on your computer.
The Hosts file is just a regular text file which can be modified using any text editor. The only catch is that the editor app should be started elevated (as Administrator). The hosts file is located in the system directory, so non-elevated apps will fail to save it.
The Hosts file consists of lines of text. Each line must include an IP address in the first text column followed by one or several host names. Text columns are separated from each other by white space. For a historical reason, is often preferred, but spaces will also do the trick. Lines started with a hash character (#) are comments. Windows ignores blank in the hosts file.
To Block Websites using Hosts File in Windows 10,
Note: Use one entry per line. Entries should look as follows:
How to test the changes
To test the changes you have made, open a command prompt and use the ping command to see the address in the output.
In my case, the remote address of the google.com domain will be resolved to my local computer.
Finally, you might want to unblock a blocked web site. Here’s how it can be done.
To Unblock Websites Blocked in the Hosts File,
Note: Adding the comment symbol is useful when you want to temporarily unblock an web address, or block/unblock it on demand.
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!
Author: Sergey Tkachenko
Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube. View all posts by Sergey Tkachenko
7 thoughts on “Block Websites Using Hosts File in Windows 10”
I’ve been using a premade hosts file for years. Get it at “http://winhelp2002.mvps.org/hosts.htm”.
I find it easiest to copy the file to the desktop then delete the old one. Do my editing and then move it back to it’s original location as many security options block modification of this file.
Important Note: The HOSTS file now contains a change in the prefix in the HOSTS entries to “0.0.0.0” instead of the usual “127.0.0.1”.
This was done to resolve a slowdown issue that occurs with the change Microsoft made in the “TCP loopback interface” in Win8.1.
This change in the prefix should not affect everyday users. I’ve had some feedback that COMODO antivirus, and System Mechanic seems to have issues with the “0.0.0.0” prefix … to resolve this issue:
You can use the “Replace” function in Notepad to convert the entries, or either of these freeware utilities (see below) has an option for converting the entries from “0.0.0.0” to “127.0.0.1.
Win8 doesn’t ‘phoning home’ directly to ‘microsoft.com’ it uses a number of other domains with different names, all owned by Microsoft.
I did all the recommendations with updating the hosts file, and it’s still not working. Using windows 10
@Timur – It would help if you list the sites blocked. Here’s the list I’m using.
########################
# Block windows update
########################
127.0.0.1 *.download.windowsupdate.com
127.0.0.1 *.microsoft.com
127.0.0.1 *.update.microsoft.com
127.0.0.1 *.windowsupdate.com
127.0.0.1 *.windowsupdate.microsoft.com
127.0.0.1 download.microsoft.com
127.0.0.1 download.windowsupdate.com
127.0.0.1 ntservicepack.microsoft.com
127.0.0.1 test.stats.update.microsoft.com
127.0.0.1 windowsupdate.microsoft.com
127.0.0.1 wustat.windows.com
It seems complete, but I’ve also shut off every Windows 10 update switch I can find in the registry, so this is just my back-up plan. Good luck.
If anyone can add to the list, that would be great.
There are applications out there to help edit hosts; so you don’t have to go through the rigmarole of searching it out and then remembering you needed to open notepad with admin privs. Not only that, certain apps allow you to work with multiple hosts files (ie, if you are a web dev, etc). Happy blocking!