December 9th, 2009


HowTo: Blocking Websites

Are you sick of Internet ads but don't want to be bothered using FireFox and the Adblocker extension (which works wonderfully, by the way)? Or how about your kids going to sites which you don't approve of? Are you using Windows (specifically XP)?

Well then I have a tip for you that will help you get a handle on what sites are loaded in your browser. For this example we are going to block Yahoo. How to block it is really simple.

First, you need to find a file simply called hosts. On most versions of Windows this should be in


The file has no extension but it's a plain text file so you can use notepad without any problems. Once you have the file open, you should see something like this at the top:

# Copyright (c) 1993-1999 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

Pretty much telling you exactly how to do it with one entry defined: localhost

You do not want to change that entry. It's how the computer recognizes itself as home and how network services "connect" to a network without there actually being a connection to the Internet or any other network.

To block a website, Yahoo in this example, you'll want to add another entry that looks like this:

Once you restart your network connection (do it however you like), yahoo should be completely blocked.

Now this only works on the top level Yahoo domain. Any sub-domains might still be available. To block any sub-domains, you'll have to block them one at a time following the same format.

There are programs out there that automatically generate a list of known harmful websites (pornography, sites that distribute malware, etc.) that also allows for easy editing of the hosts files. If I only had to recommend one, I would recommend Spybot - Search & Destroy. It's free, it searches for malware on your computer (mostly software that tracks your usage of the Internet (aka spyware)), allows for the editing of your hosts file, and is free and fairly simple to use.

Of course I like doing things without having to install any software and the above mentioned method for blocking websites is by far the easiest. You don't have to be a computer guru to edit the file, just remember the changes you've made. If you ever want to undo them, just delete the entry in question and restart your network connection. Another bonus is that while you have to do a little more monitoring yourself, in the end you don't have to pay someone else to block the sites for you.

Update: One thing I failed to mention, when you save the edited file, you'll have to delete the original and rename the file you saved from hosts.txt to just hosts, otherwise it won't work. For some reason notepad won't save this file without the extension. Don't worry about the warning about removing the file extension. In this case it isn't needed.
[tags]technology, computers[/tags]

Originally published at Ameliorations 1.0.