11 May

AdBlocking using BIND DNS Server

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
echo "Starting pixelserv "
/usr/local/bin/pixelserv &
echo "Stopping script pixelserv"
killall pixelserv
echo "Usage: /etc/init.d/pixelserv {start|stop}"
exit 1

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


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. (
                    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.

The Best Ad Blocking Method

Incoming search terms:

  • bind9 block ads
  • ad blocking dns service
  • dns adblocker
  • dns for kids adblocker
  • free ad blocking dns servers
  • adblock dns server
  • free adblock dns Bind DNS Server
  • dns blocking services
  • ad blocker dns
  • dns ad blocker
  • bind9 block google ads
  • best free ad blocker dns
  • bind9 adblocker
  • bind pixelserv
  • ubuntu bind9 block
24 Mar

Logging Bind DNS Queries

Option 1 – Quick and Dirty

You can quickly turn on logging by typing in the following into the server shell:

[code]rndc querylog[/code]

Then you can follow the information in the standard syslog.

[code]tail -f /var/log/syslog[/code]

You should see output like the following letting you know that queries are now logged:

[code]Sep 14 22:23:20 ns01.companya.local named[7896]: query logging is now on[code]

<h3>Option 2 – Full and Stored Logs</h3>
If you want to store full logs that you can go back to at a later date you’ll need to make some changes to the BIND configuration.

Logon to your shell as usual, and type the following:
[code]nano /etc/bind/named.conf[/code]

Put in the following code at the bottom:

[code]logging {
channel query.log {
file “/var/log/query.log”;
severity debug 3;
category queries { query.log; };

Now we need to create the log:

[code]touch /var/log/query.log[/code]

Make it writable by the BIND process:

[code]chown named.named /var/log/query.log[/code]

Give BIND a reboot:

[code]service bind9 restart[/code]

And now you should be able to follow the queries as any other log:

[code]tail -f /var/log/query.log[/code]


How to Log BIND Queries on Ubuntu 12.10


Incoming search terms:

  • linux named bind tail log
  • bind9 loggin queries
  • bind9 query log
  • what is DNS query logging