Ad-Blocking with BIND9 and NGINX

Optional: Use 3rd Party Adserver List

yoyo.org

There is a list of known zones that serve ads available from yoyo.org („yoyo Internet Services“). This can easily be transformed into my format for zones.adblock:

~# curl http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml |
    while read zone ; do
        echo "zone \"$zone\" IN { type master; notify no; file \"/etc/bind/db.adblock\"; };"
    done >> /etc/bind/zones.adblock
~# rndc reload

easyList

The following, more complex approach assumes that a line such as the following has been included for example in /etc/bind/zones.adblock:

include "/etc/bind/zones.adblock.easyList";

The following script will fetch the most recent list of reported ad-servers from „easyList“, converts it into the zone configuration format used in this document and rebuilds the file /etc/bind/zones.adblock.easyList:

#!/bin/sh

url="https://hg.adblockplus.org/easylist/raw-file/tip/easylist/easylist_adservers.txt"
config="/etc/bind/zones.adblock.easyList"

# clear previous content
echo -n > "$config"

curl $url | while read line ; do
    # strip prefix, paths and qualifiers
    zone=$(echo $line | sed 's/^||//;s/[\^\/].*//' )

    # skip entries starting with "!" (comments)
    if echo $zone | grep '^\!' > /dev/null ;  then
        echo "INFO: skipped non-zone \"$zone\"." >&2
    # stripped of paths, qualifiers, zone can appear more than once
    elif ! fgrep "zone \"$zone\"" "$config" > /dev/null ; then 
        echo "zone \"$zone\" IN { type master; notify no; file \"/etc/bind/db.adblock\"; };" \
            >> "$config"
    fi
done

rndc reload
Imprint RSS