Categories
BSD/Linux Computer Tech

Ad Blocking with DNS

Easy to ad block with your own DNS server if you don’t want to trust adblock or other plugins.

1 – you need a web server to host a blank image

2 – Get blacklist

Get the blacklist from http://pgl.yoyo.org/adservers/

Choose for the bind 8 config format.

I had to change the file so that the records read like this:

zone "101com.com" IN { type master; notify no; file "/etc/bind/null.zone.file"; };

by adding the “IN” between the domain name and the “{ type master ….” part. Use your vi-skills for this.

Give this file a easy name, like ‘blacklist’. Now create a line in /etc/bind/named.conf.local:

include "/etc/bind/blacklist";

Create the null zone file

Create a file /etc/bin/null.zone.file with the following contents:

$TTL    86400   ; one day

@       IN      SOA     nds.example.com. hostmaster.example.com. (
            2002061000       ; serial number YYMMDDNN
            28800   ; refresh  8 hours
            7200    ; retry    2 hours
            864000  ; expire  10 days
            86400 ) ; min ttl  1 day
        NS      nds.example.com

        A       192.168.1.100

@               IN      A       192.168.1.100
*               IN      A       192.168.1.100

and replace example.com by your internal domain name and replace 192.168.1.100 by the name of your web server. The above format allow for the use of wildcards. This means that you do not have to care about the subdomains.

Restart bind (Ubuntu version)

service bind9 restart

2 is copied from here for posterity: https://box.matto.nl/dnsadblok.html

3 – use a different DNS source if you want

If you want to use a different DNS server (say you don’t trust your ISP or Google to know every site you query) you can find others here:

https://www.opennic.org

And then in /etc/bind/named.conf.options add the forward to the dns servers:

 forwarders {
 69.195.152.204;
 96.47.228.108;
 96.90.175.167;
 };

Leave a Reply

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