I don't know about you, but I am getting sick and tired of the obnoxious ads being splashed all over the web these days. After doing a little playing around I have found that using iptables to block off this garbage from my computer to be a good solution. Ofcourse there is no magic bullet for filtering out these ads yet, but using Firefox's ability to block images from specific servers plus this script makes a big difference in my daily internet surfing. Firefox (as of version 0.8) cannot block Macromedia Flash ads, so this is where the script kicks in.

The script is available to download HERE, and I have printed it out below for reference


#!/bin/bash
# blocks obnoxious ads from well-known online advertising domains
# There are 2 ways to run this script:
# 1) type "# sh block_ads.sh" or:
# 2) type "# chmod 755 block_ads.sh" and then "# ./block_ads.sh"
# Tracking domains to be blocked can be done many ways, though I have used dig and ethereal mostly
# to track down the IPs of the offenders.

#flush previous chains
#iptables -F INPUT

# sets iptables to block all packets from doubleclick.net and associates
#start blocking
iptables -A INPUT -s 203.147.254.136 -j DROP
iptables -A INPUT -s 204.253.104.0/24 -j DROP
iptables -A INPUT -s 204.253.105.0/24 -j DROP
iptables -A INPUT -s 205.138.3.0/24 -j DROP
iptables -A INPUT -s 208.10.202.0/24 -j DROP
iptables -A INPUT -s 63.160.54.0/24 -j DROP
iptables -A INPUT -s 63.166.98.0/24 -j DROP
iptables -A INPUT -s 208.228.86.0/24 -j DROP
iptables -A INPUT -s 208.32.211.0/24 -j DROP
iptables -A INPUT -s 63.251.188.0/24 -j DROP
iptables -A INPUT -s 63.251.189.0/24 -j DROP
iptables -A INPUT -s 63.251.190.0/24 -j DROP
iptables -A INPUT -s 63.251.191.0/24 -j DROP
iptables -A INPUT -s 63.168.198.0/25 -j DROP
iptables -A INPUT -s 213.86.246.0/24 -j DROP
iptables -A INPUT -s 208.184.29.0/24 -j DROP
iptables -A INPUT -s 209.68.38.104 -j DROP
iptables -A INPUT -s 209.67.38.106 -j DROP
iptables -A INPUT -s 216.73.85.0/24 -j DROP
iptables -A INPUT -s 216.73.86.0/24 -j DROP
iptables -A INPUT -s 216.73.87.0/24 -j DROP
iptables -A INPUT -s 206.65.183.20 -j DROP
iptables -A INPUT -s 65.205.8.0/24 -j DROP


# sets up blocking of yahoo ads
# *** current setup with these makes browsing yahoo.com reeeeally slow ***
# *** it is better to have firebird block these ads ***
#iptables -A INPUT -s 63.215.198.33 -j DROP
#iptables -A INPUT -s 209.247.153.136 -j DROP
#iptables -A INPUT -s 209.247.153.182 -j DROP
#iptables -A INPUT -s 63.215.198.32 -j DROP
#iptables -A INPUT -s 63.215.198.25 -j DROP
#iptables -A INPUT -s 63.215.198.184 -j DROP
#iptables -A INPUT -s 63.215.198.155 -j DROP
#iptables -A INPUT -s 63.215.198.153 -j DROP
#iptables -A INPUT -s 209.247.153.166 -j DROP
#iptables -A INPUT -s 209.247.153.137 -j DROP
#iptables -A INPUT -s 63.215.198.6 -j DROP
#iptables -A INPUT -s 63.215.198.16 -j DROP
#iptables -A INPUT -s 209.247.153.153 -j DROP
#iptables -A INPUT -s 63.215.198.30 -j DROP

# block from ads.osnews.com
iptables -A INPUT -s 207.44.212.20 -j DROP