Edit Your HOSTS File to Block Web Sites

By | June 6, 2012

Terri’s son spends far too much time on Facebook
Hi TC and EB — Thanks for all your wonderful help over the years and all the great products and software that you recommend, of which I have bought quite a few 🙂 I have a problem with my son and Facebook, he’s on it all the time and I’m beyond done with the arguing over it. I have moved the computer to my room, tried blocking it with the content blocking advisor, even editing the host file, yet he still manages to sneak on, It’s driving me batty. I came across this program http://www.bluecoat.com/products/k9-web-security and wondered if you knew anything about it or could recommend one that would work but not cost an arm and a leg. Thank you so much and keep up the brilliant work!!

Our answer
Hi Terri. Thanks so much. We took a look at the program and it looks like much more than just a content blocker. It looks like it tries to be a little bit of everything. It’s not necessary to download a program like that to block a site from being accessed. If you’re willing to delve into a little Windows file editing (it’s easy) we can show you how to block whatever site or site you want. It takes nothing more than a few minutes of your time and a little attention to detail.

There’s a file on every Windows computer, it’s called HOSTS or hosts – it has no extension. That’s right it has no extension. It’s located in C:\Windows\System32\Drivers\etc . Here’s what you need to do.

Open the file in the etc folder called hosts – with Notepad (access notepad by pressing the Windows Key plus the R key and typing Notepad.exe .Make sure you select “all files” not Text documents or you won’t see it. You’ll find the selector to change from Text documents to all files on the right.

Now Your hosts file should look like this (if you’re using Windows Vista or Windows 7  it may look slightly different):

# Copyright (c) 1993-2004 Microsoft Corp.
#
# AutoGenerated by Microsoft (R) Malware Protection Engine.
# 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:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
::1 localhost

To block access to Facebook add the following line right under 127.0.0.1 localhost

127.0.0.1 www.facebook.com

Before you save the host file make sure it looks like this at the very bottom:

127.0.0.1 localhost
127.0.0.1 www.facebook.com
::1 localhost

Now, here’s where you have to be very careful. When choosing “Save as” make sure you don’t select an extension. As you did above, make sure you change “Text documents” in the “Save as” dialog to “All files”. Now save your new hosts file over the old one. You’ll get a warning you’re about to replace your hosts file. That’s OK, that’s what you want to do.

If you find that Notepad’s formatting does not look like the above (sometimes Notepad can really mung up text). Download a free text editor called MetaPad. It’s the one I use for almost all text editing, and the one I used to edit my hosts file to make sure this tip works (and it does). It comes in a small zip file. Simply unzip it and run metapad.exe – you don’t need to install it. You can download it directly from here. http://liquidninja.com/metapad/downloads/metapad36.zip (It’s a very small download – around 100KB).

If you want to read more about it, go to http://liquidninja.com/metapad/ .

Again, make sure when you open the folder “etc” where the hosts file is stored, you switch Metapad from Text files to “all file” (at the bottom). Also when you save the edited hosts file you don’t save it as a text file – so change Metapad to “all files” again when saving it.

No one will be able to access www.facebook.com from your computer. If the time comes when you want your son to access Facebook again, simply remove the line you added to hosts file and re-save it.

This tip will work with Windows XP as is. If you’re using Windows Vista or Windows 7, you’ll need to right-click on the hosts file and change permissions before you can edit it.

Since you’re using Windows XP, Terri, you should be able to dig right in and edit without any problem. You’ll have Facebook blocked without downloading what looks to be a very large program.

2 thoughts on “Edit Your HOSTS File to Block Web Sites

  1. Bob

    Would this also work for pop-under ads?
    If so, would I just need the domain name for it to work?

    Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *