The purpose of the tutorial is to setup an ads blocking using Bind9 DNS Server. Tutorial is divided into 2 section: Setup Pixelserv and Setup AdBlock script for Bind9.
1. Setup Pixelserv
Pixelserv is a super minimal webserver, it’s one and only purpose is serving a 1×1 pixel transparent gif file. We will redirect web requests, for adverts, to our pixelserv (running in the same bind9 server).
Install Pixelserv
cd /usr/local/bin/ curl http://proxytunnel.sourceforge.net/files/pixelserv.pl.txt > pixelserv chmod 755 pixelserv
We now need a simple init script for starting/stopping pixelserv, as /etc/init.d/pixelserv.
#! /bin/sh # /etc/init.d/pixelserv # # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting pixelserv " /usr/local/bin/pixelserv & ;; stop) echo "Stopping script pixelserv" killall pixelserv ;; *) echo "Usage: /etc/init.d/pixelserv {start|stop}" exit 1 ;; esac exit 0
chmod 755 /etc/init.d/pixelserv
Add pixelserv to startup
update-rc.d pixelserv defaults
Run pixelserv
/etc/init.d/pixelserv start
2. AdBlock for Bind9
Create new file, /etc/bind/update.sh
curl "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=bindconfig&showintro=0&mimetype=plaintext" | sed 's/null.zone.file/\/etc\/bind\/nullzonefile.txt/g' > ad-blacklist
Make it executable
chmod +x update.sh
Execute update.sh to download adservers file
./update.sh
Verify file content, make sure the path is changed from:
zone "24pm-affiliation.com" { type master; notify no; file "null.zone.file"; };
to zone "24pm-affiliation.com" { type master; notify no; file "/etc/bind/nullzonefile.txt"; };
Create adblock zone file, we named it as nullzonefile.txt
$TTL 86400 ; one day @ IN SOA ads.example.com. hostmaster.example.com. ( 2014090102 28800 7200 864000 86400 ) NS my.dns.server.org A $YOUR_DNS_SERVER_IP @ IN A $YOUR_DNS_SERVER_IP * IN A $YOUR_DNS_SERVER_IP
Reload bind9 configuration
rndc reload
Test your DNS Server
dig @localhost 24pm-affiliation.com
Should returned your own server ip address.
Reference:
https://charlieharvey.org.uk/page/adblocking_with_bind_apache
http://box.matto.nl/dnsadblok.html
http://www.deer-run.com/~hal/sysadmin/dns-advert.html
http://prefetch.net/blog/index.php/2006/05/27/using-bind-to-reduce-ad-server-content/
Incoming search terms:
- bind9 block ads
- adblock dns linux
- adblock ubuntu server
- adblock сервер дебиан
- debian adblock server