Ad-blocking software is great, but there are an increasing number of ways to detect and prevent people from viewing the site content.

I found that by creating an ad-blocking DNS resolver, this would effectively simulate a connection issue when communicating with one of the advert servers, therefore not triggering this software, albeit having a few broken images on a page, etc.

Its pretty easy to do, and with my auto update script (available below) hosted on BitBucket, it can be built, updated and running within a few minutes.

To build this wonder, you need to install PowerDNS. For Ubuntu based machines, you can run the following:

sudo apt-get install mysql-server mysql-client \
pdns-server pdns-backend-mysql

..and follow the on-screen instructions. This will install and configure powerDNS and also set up mysql if you have not got it installed and configure the appropriate tables.

After this step, create a new database user in MySQL for the update script using the MySQL command line (type mysql -uroot -p on the command line, followed by your MySQL root password):

GRANT ALL ON pdns.* TO 'pdnsadmin'@'' IDENTIFIED BY 'password';FLUSH PRIVILEGES;

The username (pdnsadmin) and the password (please dont use ‘password‘) are required for the update script. This can be downloaded from my repo here:

Updating the line:

$mysqli = new mysqli('', '**MYSQL USERNAME**', '**MYSQL PASSWORD**', 'pdns');

with your MySQL login details.

Next, you need to edit /etc/powerdns/pdns.conf, and make the following changes:

Find: allow_recursion=, uncomment it and set your IP range you wish to serve to, or leave set to if you are behind a firewall.
Find: recursor=no, uncomment it (if it is commented out), and replace ‘no‘ with the IP address of a trusted DNS resolver (eg or for OpenDNS).

Save the changes and restart powerDNS:

service pdns restart

Next, run the update script. This will download a mahoosive file from hpHosts and convert it into the DNS records required for powerDNS.

php update.php

That’s it. All you need to do now is to set your computer / router / DNS server to resolve from your box, and the majority of adverts and malware will disappear!

Categories: Linux

Leave a Reply

Your email address will not be published. Required fields are marked *