Block ads, tracking and other garbage with dnsmasq

There is an automatically updated, moderated and optimized list available on GitHub for blocking ads, trackers and other online garbage:

https://github.com/notracking/hosts-blocklists

The list is designed for use with dnsmasq. There is also a validation script available at https://github.com/bahamas10/notracking. You can configure automatic update of the list by following these steps:

    1. Install Node.JS that is a requirement for the notracking validate script:
      $ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
      $ sudo apt-get install -y nodejs
    2. Clone the notracking repository:
      $ cd /opt/
      $ git clone git://github.com/bahamas10/notracking.git
    3. Configure crontab to download updated lists on a daily basis by creating the file /etc/cron.d/notracking with the following content:
      0 6 * * * root cd /opt/notracking;./update;mv /opt/notracking/*.txt /etc/dnsmasq.d/;/usr/sbin/service dnsmasq restart
    4. Disable the CONFIG_DIR option in /etc/default/dnsmasq by comment out the following row:
      #CONFIG_DIR=/etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new
    5. Add these two lines to the file /etc/dnsmasq.conf:
      conf-file=/etc/dnsmasq.d/domains.txt
      addn-hosts=/etc/dnsmasq.d/hostnames.txt

To get the configuration running immediately you can manually execute the commands from the cronjob or you can wait for it to run by it self at 06:00 the morning after you configured dnsmasq.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s