Block Websites using Hosts File in Windows  

    Block Websites using Hosts File in Windows

    Block Websites using Hosts File in Windows

    How to Block Websites using Hosts File in Windows
    Published by Category: Network & Sharing
    06 Aug 2020
    Designer Media Ltd

    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




    EXAMPLE: When you try to open websites blocked in Hosts file
    Block Websites using Hosts File in Windows-blocked_website_by_hosts_file-1.png Block Websites using Hosts File in Windows-blocked_website_by_hosts_file-2.png






    OPTION ONE

    Block Websites using 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.

    Block Websites using Hosts File in Windows-notepad_run_as_administrator.png

    2 In Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Open Ctrl + O. (see screenshot below)

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-1.png

    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.

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-2.png

    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)

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-3.png

    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.

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-4.png

    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)

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-5.png

    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.






    OPTION TWO

    Unblock 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.

    Block Websites using Hosts File in Windows-notepad_run_as_administrator.png

    2 In Notepad, click/tap on File Alt + F in the menu bar, and click/tap on Open Ctrl + O. (see screenshot below)

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-1.png

    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.

    Block Websites using Hosts File in Windows-block_website_in_hosts_file-2.png

    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.


    Block Websites using Hosts File in Windows-unblock_website_in_hosts_file-1.png

    OR

    B) Delete (remove) the line of the website you want to unblock. (see screenshots below)

    Block Websites using Hosts File in Windows-unblock_website_in_hosts_file-2a.png
    Block Websites using Hosts File in Windows-unblock_website_in_hosts_file-2b.png Block Websites using Hosts File in Windows-unblock_website_in_hosts_file-2c.png

    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)

    Block Websites using Hosts File in Windows-unblock_website_in_hosts_file-3.png

    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






  1. Posts : 69,490
    64-bit Windows 11 Pro for Workstations
       #1
      My Computers


 

Tutorial Categories

Block Websites using Hosts File in Windows Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:26.
Find Us




Windows 10 Forums