How To Block A Website

by Brian on January 22, 2010

I have started using Google Chrome over the last few weeks and although it is a very fast browser, the downside is that it lacks the number of quality extensions as Firefox has plugins. One of the plugins that I was able to use with Firefox allowed me to block certain sites. This is great if people have kids, but helped me with productivity as I was able to reduce access certain sites while I needed to be productive.

Until that extension is available for Chrome, another option is to restrict access to those sites using your HOSTS files if you are using a Windows operating system. Windows uses a HOSTS (located in c:/windows/system32/drivers/etc) file to maintain a personal list of web addresses and associated IP addresses for accessing them. This is can be used when setting up a new site and DNS setting have not propagated the internet entirely. When a request is made for a URL, the HOSTS file will be checked first. If a corresponding address is found, it will direct you to that IP without first consulting a DNS Server. The original intent of this file was to define where sites exist, but in this case I am using it to restrict access and direct all DNS calls back to my system drive.

Lets first look at a HOSTS file entry

127.0.0.1 localhost

This is the loopback address for your machine for those cases where an application needs to reference the local machine by IP address- the loopback address will always be valid. This entry should never be changed.

Now lets add an entry to block

127.0.0.1 www.facebook.com

We are telling our local machine that Facebook actually exists on the local machine, so when it looks to open the website in the browser, it does not go to the internet, but only references the local machine.. Any request for www.facebook.com will be directed to the local machine and therefore effectively blocked. You could also use the IP of another website if you wanted to be creative.

A HOSTS file entry will disregard the transfer protocol so it isn’t needed. However, the host does play an important role. A webmaster may choose to define a host for his/her website. “WWW” has become the universal standard for the default host. It is just as common to define a site with no host as well. This means that as far as DNS goes www.facebook.com & facebook.com are two totally different sites, even though they resolve to the same place.  Because of this to effectively block the all parts of a domain including the subdomains, you must also block all hosts. Each subdomain would have to be added separately. This would usually mean:

127.0.0.1 yahoo.com

127.0.0.1 www.yahoo.com

There are probably other methods to block sites like filtering the IP address through your router, but that is tough as the IP address for many sites change or rotate. Hopefully, an extension becomes available for Chrome and this will no longer be necessary.

I really appreciate that you keep coming back to my site, it's loyal people like you that make what I do worth it. If you have any questions feel free to email me. Oh and since you obviously like our site it'd be great if you could share it with a friend... They'll love you for it!

{ 1 comment… read it below or add one }

Alex June 17, 2010 at 12:13 pm

Another coolstuff to block the website with the hostfile is the following:

list your blocked website in the hostfile. redirect to your ip address instead of the localhost (127.0.0.1).
install IIS in your computer. Create a simple website and rename it as default.htm

With the above setup, everytime you try to access to your blocked website, an specific webpage created by you loads, instead of the blocked website.

Leave a Comment

CommentLuv Enabled

Previous post:

Next post: