Ad filtering setup for DD-WRT

In order to set up ad filtering by host blocking on DD-WRT, you can create a cron(1) script to download a hosts file and point dnsmasq(1) to it.

The first step is accomplished by a crontab entry in Administration, Cron like the following (line broken for readability). Note that this file is in cron.d format, i.e. the sixth field is the user name and the command is the seventh field.

0 0 * * * root mkdir -p /tmp/adhosts;
    i=0;
    for url in "http://hosts-file.net/download/hosts.txt";
    do
        /usr/bin/curl -s "$url" > /tmp/adhosts/$i;
        i=$((1 + i));
    done;
    kill -hup $(cat /var/run/dnsmasq.pid)

You can add any number of files to download, but since cron(1) does not support line continuation you will have to write the entire script in one line (or store it somewhere in the filesystem).

In order for dnsmasq to pick up the list, the following setting is needed in Services, DNSMasq:

addn-hosts=/tmp/adhosts

Comments