Using the Windows Hosts File to Block Websites

The Hosts file is used by the operating system to map hostnames to IP addresses. It’s a historical file that’s used by Windows to signpost internal and external websites, and other such networking services. You can, use it to your advantage though.

The Perfect Host

The Hosts file is simply a plain text file for mapping network locations and is checked by Windows to see if there’s an entry whenever the user requests access to a website or network resource. Here’s how to block websites using it.

Step 1 – First you need to open the Hosts file with administrative access. To do this, click on the Windows Start button and type notepad. When Notepad appears in the search list, right-click it and choose Run as Administrator from the menu and click Yes for the UAC message authentication.

Step 2 – Within Notepad click File > Open and navigate to c:\Windows\System32\drivers\etc. Click the drop-down menu saying Text Documents and change it to All Files. This will list the files within the etc folder. Click on the Hosts file, then click the Open button.

Using the Windows Hosts file to block sites2

Step 3 – You can see that the Hosts file is a historic text file dating back from the early days of networking and communications. The localhost entry at the bottom of the file, is your computer. This is the important entry, as we’re going to fool the networking services into believing that a website is stored locally.

Step 4 – It’s this fooling Windows that makes this such an effective solution to blocking sites, as you’re not fiddling with your router or other networking devices. Let’s say, for example, you want to block BDM Publications. Open a browser and go to the BDM Publications website,

Step 5 – Either close or minimise the browser window and get back to the Hosts file in Notepad. Press Enter a couple of times to start a new line under the last hash and type in: Don’t add the HTTPS or the www part, just as it appears in the address bar.

Step 6 – In Notepad, click File > Save, to obviously save the newly edited Hosts file. Now get back to your browser and either refresh the page or close and reload the browser. When back up, in the address bar enter the site: You can now see that the page won’t load.

Using the Windows Hosts file to block sites6

Step 7 – You can try searching for it via Google or Bing but it still won’t load as you’ve successfully blocked access to the website’s hostname from the Hosts file. You can also see that any sub-domains after the main address are also blocked, which is certainly handy for some sites.

Step 8 – What we’ve done here is fool Windows’ networking services into thinking that the website, is being hosted on the computer itself and not out there on the Internet. If we wanted to remove the block, we can simply delete the line or put a hash at the start of the line and save the file.

Using the Windows Hosts file to block sites8

Step 9 – Over time you can add more sites to the Hosts file list, pointing each one back to the address of the local computer to block it from ever being reached; even if you use a different browser or other internet accessible program.

Step 10 – If you want a complete list that’s already been created, then WinHelp2002 provides a downloadable compressed Hosts file that you can replace your own with. You can find it here; just read the instructions to replace the new Hosts file.

Using the Windows Hosts file to block sites10

Find more guides like this in…

David Hayward

David has spent most of his life tinkering with technology, from the ZX Spectrum, getting his hands on a Fujitsu VPP5000/100 supercomputer, and coding on an overheating Raspberry Pi. He's written for the likes of Micro Mart, Den of Geek, and countless retro sites and publications, covering reviews, creating code and bench testing the latest tech. He also has a huge collection of cables.

Related Articles

Back to top button