How to Block Websites using Hosts File in Windows
The Hosts file is used by the operating system to map human-friendly hostnames to numerical Internet Protocol (IP) addresses which identify and locate a host in an IP network. The hosts file is one of several system resources that address network nodes in a computer network and is a common part of an operating system's IP implementation.
The Hosts file contains lines of text consisting of an IP address in the first text field followed by one or more host names. Each field is separated by white space (Tabs are often preferred for historical reasons, but spaces are also used). Comment lines may be included, and they are indicated by a hash character (#) in the first position of such lines. Entirely blank lines in the file are ignored.
Using the Hosts file to block websites by domain is preferable to trying to use rules in Windows Defender Firewall to block IP addresses since websites will often use more than one IP address.
This tutorial will show you how to block websites for all users on the computer using the Hosts file in Windows 7, Windows 8, and Windows 10.
Windows 10: HOSTS file blocking telemetry is now flagged as a risk | bleepingcomputer
You must be signed in as an administrator to edit the Hosts file.
If you find manually editing the Hosts file directly uncomfortable, you could use a free standalone program like BlueLife Hosts Editor to help make editing the Hosts file easier.
Contents
- Option One: Block Websites using Hosts File
- Option Two: Unblock Websites Blocked in Hosts File
EXAMPLE: When you try to open websites blocked in Hosts file
![]()
1 Perform the following actions to open Notepad using Run as administrator: (see screenshot below)
A) Open the Start menu.
B) Click/tap on the Windows Accessories folder in All Apps to expand it open.
C) Right click or press and hold on Notepad, click/tap on More, and click/tap on Run as administrator.
2 In Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Open Ctrl + O. (see screenshot below)
3 Perform the following actions to open the Hosts file in Notepad: (see screenshot below)
A) Browse to and open the C:\Windows\System32\drivers\etc folder from the navigation pane or address bar in the Open dialog.
B) Select All Files (".") in the drop menu at the bottom right corner. This will allow you to see the hosts file listed.
C) Select the hosts file.
D) Click/tap on the Open button.
4 In the hosts file now opened in Notepad, make note of your localhost IP address (ex: "127.0.0.1"). You will need to use this while blocking websites in step 5 below. (see screenshot below)
5 Perform the following actions to add a website to be blocked: (see screenshot below)
Each website you want to block must be added on a separate line.
A) On a new line in the hosts file opened in Notepad, type your localhost IP address (ex: "127.0.0.1") from step 4.
B) Press the Tab key to add space.
C) Type the website address (ex: "www.google.com" or "www.facebook.com") you want to block.
This will block all websites that start with this added domain (ex: "www.google.com" or "www.facebook.com").
HTTPS sites will not get blocked unless you include www in its address.
D) If you would like to add a comment about this blocked website, then press the Tab key to add space, press the pound key # to indicate this is a comment, and type the comment you want (ex: "To block Facebook").
Comments are optional, and do not have to be added unless you would like to.
E) Press Enter to start a new line.
F) Repeat steps 5A to 5E if you would like to add more websites to be blocked.
6 When finished editing the hosts file in Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Save Ctrl + S. (see screenshot below)
7 Close Notepad.
8 If the websites you added to the host file are not being blocked immediately, then flush DNS cache or restart the computer to apply.
1 Perform the following actions to open Notepad using Run as administrator: (see screenshot below)
A) Open the Start menu.
B) Click/tap on the Windows Accessories folder in All Apps to expand it open.
C) Right click or press and hold on Notepad, click/tap on More, and click/tap on Run as administrator.
2 In Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Open Ctrl + O. (see screenshot below)
3 Perform the following actions to open the Hosts file in Notepad: (see screenshot below)
A) Browse to and open the C:\Windows\System32\drivers\etc folder from the navigation pane or address bar in the Open dialog.
B) Select All Files (".") in the drop menu at the bottom right corner. This will allow you to see the hosts file listed.
C) Select the hosts file.
D) Click/tap on the Open button.
4 In the hosts file now opened in Notepad, perform either step 4A or 4B below to unblock a website:
A) Add the comment # symbol in front of the line of the blocked website you want to unblock, and add a space after the # symbol. (see screenshot below)
Using the comment # symbol can be useful when you want to sometimes block and unblock a website on demand and don't have to add and remove the website each time. You can just add and remove the comment # symbol instead.
OR
B) Delete (remove) the line of the website you want to unblock. (see screenshots below)
![]()
C) Repeat step 4A or 4B if you would like to unblock more websites.
5 When finished editing the hosts file in Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Save Ctrl + S. (see screenshot below)
6 Close Notepad.
7 If the websites are not unblocked immediately, then flush DNS cache or restart the computer to apply.
That's it,
Shawn