Create your own Internet Filter with the Windows Hosts file

Jan. 6th, 2008 By Mark O'Neill

The internet has lots of benefits but on the other hand, it has its downsides that we all love to hate. The most common one is pop-up ads but if you have young kids who like to surf the net, then as a parent, you will want to protect them from porn sites and any other sites you deem undesirable for such young impressionable minds - such as the Teletubbies.

Well you may not know that it is relatively easy to set up your own internet filter to stop certain websites and pop-up windows from being accessed and shown on your computer - and it already resides on your Windows operating system in the form of the Hosts file. Just adding a line to the file can stop a website or a pop-up window in its tracks.

The Hosts file is located at Windows\system32\drivers\etc\hosts. The file has no file format so when you double-click on it, you’ll be asked how you want to open it. Just choose Notepad to open the file as a text file. If you are not so experienced in dealing with the Hosts file, you may want to make a backup of this file before you start altering anything.

When it is opened, this is what you will see :

windows-hosts-file.gif

The first thing you have to notice is the line 127.0.0.1 local host at the bottom. That’s your computer.

To block a website from your browser is very easy. Say you suddenly develop an overwhelming hatred for Google and you want to banish them to the internet graveyard. Time to give it the Hosts file treatment!

On the bottom line of the file (underneath 127.0.0.1 local host), just type :

127.0.0.1 www.google.com

Save it and close the file. But there are three things to make sure of to ensure this works properly :

  • Make sure that the file is still called “hosts” (without a file format at the end such as “hosts.txt”). If Windows attempts to assign a file format to the file, remove it.
  • Do NOT add “http” at the start of the URL. Doing so makes the entry invalid. Just “www” is enough.
  • You will probably have to re-start your browser for the changes to start working and in some cases, it may take a minute or two for the URL to be blocked.

Now try to access the site in question. You’ll see that you now get a blank page. Totally inaccessible. Every attempt to access the URL just gets automatically bounced back to you with the blank page.

windows-hosts-file.gif If you suddenly decide you’re madly in love with Google again, just open up the Hosts document again and delete the line you just inputted. Save and close the file, then re-start the browser. Google will suddenly become available again.

So how does this stop block-up ads? Well when the ad comes up on your screen, take a note of the URL that it is coming from and add it to your Hosts file. Save and close then go back to the website in question. You’ll suddenly find that pop-up ad doesn’t appear anymore!

Now you’re probably saying that with pop-up blockers being standard in browsers these days, what’s the point of this? But pop-up blockers are not 100% perfect. I know of one website that overpowers the pop-up blocker and loads up pop-up windows without any resistance from Firefox or the Google toolbar pop-up blocker. So sometimes you need a little more than your browser to stop those nasty critters.

If you do a Google search, you’ll find people who have compiled lists of malicious URL’s that you can add to your Hosts list. This includes pop-up ads, spyware, trojan horses and porn. But I prefer to just add to the Hosts file myself on a site-by-site basis. Creators of these URL lists can get a bit carried away with privacy and end up giving us URL’s that can block sites we may consider legitimate. So I think it’s best to do it yourself.

So if you have essential sites constantly popping ads up at you or if you want to filter out naughty sites from your kids, the Hosts file is a fairly simple way of doing it.

Enjoyed the article? Subscribe to MakeUseOf to get daily updates on new cool websites and programs in your email for free. You'll also get free printable cheat sheets to your favorite programs

Your Email:

Add MakeUseOf to:



19 Comments Add Comment
2008-01-06 21:44:01
Captain Slog

You neglect to add one very important fact. A HOSTS file is zero footprint; it uses no memory. As opposed to all those toolbars that help to swamp a system’s resources (Hey under Vista we don’t have enough as it is) a HOSTS file is a great way to block unnecessary pages dead. Also, a great idea is to have a backup of your HOSTS file as well as to set it to read only.

2008-01-06 22:26:07

You’re right Captain Slog, it is a perfect zero footprint solution.

FYI:
After saving changes to the hosts file, you should also be able to use nbtstat -R which purges and reloads the remote cache name table to avoid having to restart your browser or computer.

Start -> Run “nbtstat -R”

2008-01-08 21:23:07
Brainiac

Thanks for the useful tip

2008-01-06 23:06:53

That was a great info. Thx

2008-01-08 11:54:58
John

I use hostsman to manage my hosts file and keep it updated with many hosts file sources for site blocking
http://www.abelhadigital.com/

Since adblock plus, my net surf has never been better…

2008-01-08 21:27:24

I am a bit confused. Why would you use both of these tools? As it seems to me both of them do the same thing. :?

2008-01-12 00:34:55
earlofpeatrig

Alternatively, you could give this a try:
http://www.scrubit.com/

2008-01-12 11:24:54

Yes, that is a possibility but do you really want other people / companies deciding for you what’s a “suitable site” and what isn’t? Everyone has their own tastes / standards / opinions.

I much prefer to make that distinction for myself by manually blocking sites on my own.

2008-05-03 08:27:09
John

I tried this and it says

“Cannot create the C:\Windows\system32\drivers\etc File.
Make sure the path and file name are correct”

Can anyone offer some help? I’m running Vista and am the Administrator on the computer.

2008-05-03 08:47:16

John : I don’t have Vista as my OS so I can’t say where that message has come from. However I am confused. You would normally open and edit the Hosts file using a text editor. So where is that error message coming from?

2008-05-03 09:05:18
John

Well, I opened the file using Notepad, typed the entry in, then clicked Save and that popped up.

2008-05-03 09:58:58

Sorry John, not having Vista, I can’t help you out there. I am totally mystified. I’ll ask Karl who may be able to help.

2008-05-03 10:57:28

John - are you logged in as an administrator? What version of Vista are you running?

2008-05-04 07:33:31
John

I am logged in as the administrator, yes. And it’s Vista Home Premium.

2008-05-09 11:34:36
John

Well, I took the advice of the above other John and am now using Hostsman to manage the Hosts file. It works fine. Thank you for your help, anyway, much appreciated!

2008-06-10 01:26:43
sandy

Hey friends, that is fine for blocking URL’s. But if I want to add URL for gmail for resolving the names in HOSTS file itself what needs to be done?

2009-04-21 00:05:55
Caleb

How do you add more than one? I’m running windows xp pro and i added the first site, and everything worked, then i hit enter, retyped the ip address then typed another website, it looked exactly the same as the first one, just a line under it, and it won’t block the second site. looks like this

127.0.0.1 http://www.firstwebsite.com
127.0.0.1 http://www.secondwebsite.com

the first site is blocked, the second is not, any ideas?

2009-04-21 00:07:34
Caleb

well this page made my fakewebsites into links, but i just strictly had w w w . f i r s t w e b s i t e . c o m
without the spacing

2009-06-22 14:03:24
Hades
Subscribed to comments via email

Do you want to edit the hosts file under Vista?
Start > All Programs > Accessories > right-click on notepad > Run as administrator.
Then open the hosts file by browsing to the file location: C:\Windows\system32\drivers\etc
Make sure all files are shown, not just txt files. Now you can simply open, edit and save the hosts file.

Reply

You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.