Blocking ad servers and malicious websites is a tough task these days. There are so many tools out there to keep ads blocked, remove spyware, and scan for viruses. Most of this unwanted content comes from known ad servers and known malicious websites. You can harness the power of the Windows’ HOSTS file to actually block some of this stuff. I’ve been doing this for years, and I’m still surprised how well it works.
In a nutshell
For your version of Windows, the HOSTS file is located in
Windows XP:C:\WINDOWS\system32\drivers\etc\
Windows 2000:C:\WINNT\system32\drivers\etc\
Windows 98/ME:C:\WINDOWS\
It does not have an extension — it is just called hosts. The purpose of the HOSTS file is to allow you to manually enter IP addresses associated with websites, so the DNS server can quickly resolve an address. Say you know that google.com is the IP address 64.233.187.99 — you could enter that into the HOSTS file so when your machine requests google.com, it will immediatly know to go to http://64.233.187.99/. Instead, we can take known ad servers, and tell them their IP addresses are 127.0.0.1. For those of you that don’t know, 127.0.0.1 is your local machine, if you were running a server on it. So say, some ad server hosts a banner ad at http://www.adsite.com/ads/23bh3.jpg. If you redirect this server to your lcoal machine in the HOSTS file, when a website calls that hosted image from the ad server, it will try to load http://127.0.0.1/ads/23bh3.jpg. Since that folder and that image don’t exist on your computer, the image won’t show, and you’ve blocked the ad from showing on that website.
Putting it together
This first line of the HOSTS file should list the local IP address:
127.0.0.1 localhost
That tells the rest of the file, 127.0.0.1 is your local machine, like I explained above. You could also use 0.0.0.0 instead of 127.0.0.1 — either will work, but whatever you use for localhost, use below. After that, enter known ad servers and use your local IP (whichever you chose at the top). You can find maintained HOSTS files online or start to build your own. Here’s a little snippit of what my HOSTS file looks like:
127.0.0.1 localhost
127.0.0.1 92.132.206.rev.adknowledge.com
127.0.0.1 a-con1.adknowledge.com
127.0.0.1 a-lbs.adknowledge.com
127.0.0.1 a-pwr.adknowledge.com
127.0.0.1 a-sw1.adknowledge.com
127.0.0.1 aa1-1.adknowledge.com
127.0.0.1 aa1.adknowledge.com
127.0.0.1 aa2-1.adknowledge.com
127.0.0.1 aa2.adknowledge.com
127.0.0.1 aa3-1.adknowledge.com
Extra step: Windows XP/2000 only
In XP and 2000, the DNS Client (a system service), will make your machine come to a grinding hault if your HOSTS file is too large. This service is unnecessary and can be stopped and disabled. Go to Start > Run > enter “services.msc” then hit [Enter]
Navigate to DNS Client, right-click it, select Properties, under Start-up Type, select Manual. Click Apply. Then below that, click the Stop button. You should do this before you save a large list of servers to your HOSTS file.
Disabling/Enabling the HOSTS blocking
If you ever need to disable the blocking, just rename the hosts file to anything. I usually rename it to hosts.disable. After you do that, you need to restart your browser to see the changes. To enable it again, just rename it back to hosts.
You could also write a script to do this for you. An example called disable.bat:
cd C:\WINDOWS\system32\drivers\etc && ren hosts hosts.disable
And another example called enable.bat:
cd C:\WINDOWS\system32\drivers\etc && ren hosts.disable hosts
More info about HOSTS
To get a HOSTS file already full of servers, you may go to MVPs.org. To learn more about the HOSTS file, check this site out; it’s where I learned about it. Also, I posted this tip a while back, at Of Zen and Computing.
No comments:
Post a Comment