How to Block Websites By Editing the HOSTS File in Windows

Ads by Google

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.

Host name resolution

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. How to manually edit the HOSTS file.
  2. How to use a tool called HostsMan editor to do it easily.

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.

Edit HOSTS File Manually

Note: For Windows 7 users, there’s one more step. Type “Notepad” in Start Menu search bar, and then right click on the “Notepad” item, choose “Run as administrator”. Now you can open HOSTS file with “File -> Open” menu in notepad.

Ads by Google

Edit HOSTS File 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.

HOSTS file

To block a website, simply add a line like this:

127.0.0.1 example.com

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.

HostsMan Editor

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.

Before You Go...

Just wanted to let you know that we've got a special eBook on Google Chrome browser, called The Ultimate Chrome Productivity Guide where we show you how to master Google Chrome to make the most out of it. Make sure you buy it because it is worth much more than the price we're offering it for.

Get Guiding Tech articles delivered to your inbox.

Also get a free ebook when you subscribe.

We will never share your address. Unsubscribe at any time.



  • Shan

    Great guide-I’ve been looking for clear instructions to do this and this was perfect! Thanks!

  • Dhananjay Singh

    I was aware about changing the host file, but this is a fantastic detail of how its work. Thankyou

  • http://www.yabeen.com/ yabeen

    oh thanks, i need to block facebook. i added that in host ,its work when try to connect http://www.yabeen.com but its not work , if any pages select in the yabeen its ddnt works

  • Greg

    Can I use some universal denotation?
    I’d like to block hao123 but it has many sites e.g. hao123.com, hao123.cn, hao123.hk, hao123net.co, hao123kk.com, etc. Is there any way to block them altogether, e.g. writing hao123.* ?
    Thanks.

  • Kamal ahmad

    i have done exactly the same but facebook is not blocked.
    i wrote in host file :
    127.0.0.1(spaces using tab key)www.facebook.com
    but it did not work. what should i do… hosts file is edited succcessfully, no error.

  • Edwin

    About blocking manually. For example facebook webpage. If you type “facebook.com” it would still open “www.facebook.com”, “facebook.com/home.php”. Is there a way to manually block ENTIRELY the desired webpage?

    • shawn

      Start, Services, stop the DNS Client… this caches the site and the cache wont clear unless you stop the service, you can start it after if needed.

  • Agni

    Blocking using ‘internet options’ and ‘hosts’ file has failed in windows 8.1/ie11. why?

    • Support

      Because the new Microsoft Security Essentials in windows 8, don’t let you modify the hosts file.

      • Maverick

        They do, i have done it.
        You just have to give the required permissions. Google about it.