How to Block Websites Using Windows 8 Hosts File


Internet is really a good place to learn a lot of stuff, but equally, it has a real time-wasting and/or dark side where you don’t want your family members or employees to go check out. One simple solution to deal with this problem is to employ some sort of hardware or software solutions which can effectively block unwanted sites, but using these solutions may be expensive and may also require technical knowledge to configure them.

That said, without spending anything extra or without messing with a whole lot of settings, there is a slick way built right into Windows which you can easily use to block or redirect unwanted websites. So without further ado, let us see how to block websites using Windows 8 hosts file.

Note: Even though we are using Windows 8, this trick will work with any previous versions of Windows like 7 & Vista.

What is Windows Hosts File

For starters, Windows Hosts file is a simple system file that is used to override the default DNS behavior. Again, DNS (Domain Name System) is a service which is mainly responsible for mapping the human readable web addresses to its numerical IP addresses. For example, whenever you try to access you are mapped to its IP address

Windows Hosts file is a local file, i.e, it is specific to your computer. Because it is a local file with certain changes (like the ones shown below), you can easily override default DNS behaviour.

Note: For those who are using Linux, check out the guide here for using the Hosts file in Linux.

Block Websites Using Windows Hosts File

Windows Hosts file can easily be edited using any text editor, e.g. you can use your native Windows text editor Notepad. So let us get started.

1. First off, open your Notepad as an administrator. To do that, open your Start screen and type “Notepad.” Right click on the Notepad app and select the “Run as administrator” option from the list.


2. Once you have opened the Notepad, click on “File” and select “Open” from the list or simply press “Ctrl + O” to open the “Open file” window.

3. Here navigate to:

Once you are there, make sure that you have selected “All files” so that you can see all the files located in the directory. Here select the file named “hosts” and click on the Open button.


4. The above action will open the Hosts file with administrative privileges. Now to block a website you need to add a line just like the one below for each website.


That’s all there is to do. What the above line does is that whenever you try to access “” or “” you will be redirected to the IP address For those who are unaware, (localhost) is a local IP address, and you won’t get anything for that unless you configured your PC to run as a server.

5. Once you have finished editing the Windows Hosts file, press “Ctrl + S” to save the changes and close the Hosts file. The changes are immediate, i.e. no browser or system restart is required. If any user tries to access the blocked URL, they will get the web server not found error.

In the future, if you want to unblock or undo the redirect you can either remove the added line for that specific website or you can comment out of that line by using the “#” symbol at the beginning of the line. Once the symbol is added, it will look something like this…

That said, using the above tip, you can even add your own comments like the reason why you blocked or redirected that specific URL, etc.

That’s all there is to do, and it is that simple to block websites using the Windows 8 Hosts file. Comment below on what you thing of this handy trick.

Vamsi Krishna Vamsi Krishna

Vamsi is a tech and WordPress geek who enjoys writing how-to guides and messing with his computer and software in general. When not writing for MTE, he writes for he shares tips, tricks, and lifehacks on his own blog Stugon.


  1. I have tried each step, and even restarted the computer, cleared all history and checked the file and it’s extension to make sure I have made all requisite changes. How do I figure out how it’s not working?

    1. Hi Sarah, Try to access that blocked website using your web browser and you should receive website not found error. If you didn’t receive the error or if that website is not blocked, then there is something you have done wrong.

      Also, try to whitelist “hosts” file in your antivirus solution.

      1. I have checked it, and like I said earlier, I did not receive any read only or admin privileges denied type errors. I am wondering if the host file is getting bypassed. The text in it, the first part, is identical to examples I have seen online. How does one whitelist a file in the antivirus program? If it was necessary, wouldn’t the antivirus block editing of the host file in the first place?

        1. Hi Sarah, Please share what you’ve entered into the hosts file.

          As per your question, No antivirus software won’t block editing hosts file, but it may delete/ignore any changes made to the hosts file. This is because, some antivirus softwares may think that the changes are made by some malware or malicious software.

  2. The first few lines from the beginning look like the following:
    # Copyright (c) 1993-2009 Microsoft Corp.
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a ‘#’ symbol.
    # For example:
    # # source server
    # # x client host

    # localhost name resolution is handled within DNS itself.
    # localhost
    # ::1

  3. I’ve done this too, used to work on Win 7 and lower but it does not work at all with Windows 8. Edit the host file and nothing happens, with or without Windows Defender too, with or without AVG free version.

  4. works on win8 for me had to take ownership of the hosts file first and edit and save it….
    before installing software.

Comments are closed.