Monday, October 18, 2010

Block sites using the HOSTS file

While I know this isn’t anything new, I have been asked 3 times this week how to easily block sites.  It’s really simple.  It revolves around DNS and it’s basic principles.  There are ways to subvert this technique, but it should suffice for parents trying to lock down a certain website on a child’s laptop.  It’s is better to look at your other options though.  I’d suggest using Parental Controls for a more robust solution.

Why not show the Parental Controls?

I’d then have to have it installed…  I don’t need it!  Like I said, this is for a quick easy win.  Let’s jump into it.  Open Windows Explorer and navigate to this folder: C:\Windows\System32\drivers\etc  or for you geeks: “%windir%\System32\drivers\etc”.  Within this folder is a file called hosts.

image

Right click the hosts file and select Open.  This will prompt you to choose which program to use.  Simply select Notepad from the list and press OK.

image

This will open up the hosts file and allow you to make your changes.  If you have never seen this file before, let me explain it a bit.  This file used to be the backbone of the internet.  The domain name you’d type into your browser would check this host file and know where to go in order to find the web site.  When the internet became too large a better solution was needed, hence DNS.  What some people don’t know, is your computer checks this file first before querying any DNS server for an IP address.  So a quick edit here, will allow you to redirect all traffic to, let’s say: Facebook.com. 

Nice!  What do I type?

When you first open the hosts file, it should look just like this:

image

What is nice, is there are some examples on how to use the hosts file.  All of these lines are already commented by: So as long as that line has an #, any text will not have any effect.  What you need to do is type an IP address that isn’t capable of internet traffic.  I typically always use: 127.0.0.1.  I’ll leave it up to you to find out why I use that address.  So all we have to do is add this line:

127.0.0.1         facebook.com

As soon as you save this hosts file, all traffic bound for facebook.com, will now be routed to 127.0.0.1.  It’s just that easy…  Here’s a screenshot of what the file should look like after the edits:

image

Technorati Tags: ,,

No comments: