Block Ads using dnsmasq – Synology

DNSMasq is a very light-weight DNS server that is perfectly suited to run on low power home appliances like NAS devices or routers running custom firmware.
The script below pulls ad blocking host files from 3 different providers and combines them to use as a DNSMasq resolver file.

Here is the script – it can be used verbatim on a Synology NAS running the DNSMasq package from http://syndnsmasq.the-ninth.com/.

Edit the DNSMasq file to add an entry ‘addn-hosts’ to point to the hosts file that was just created – for example:
addn-hosts=/root/AdBlock/adblock.uniq

#!/bin/sh
cd ~/AdBlock</code>

echo "# Generated on: $(date +"%D %T")" &gt; adblock

echo "Downloading file from YoYo.org"
wget -O yoyo http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&amp;showintro=0
wait
echo "Processing YoYo.org file"
cat yoyo | grep "127.0.0.1" | awk '{ print "0.0.0.0\t"$2 }' &gt;&gt; adblock
wait

echo "Downloading file from SomeoneWhoCares.org"
wget -O swc http://someonewhocares.org/hosts/zero/
wait
echo "Processing SomeoneWhoCares.org file"
cat swc | grep "0.0.0.0" | awk '{ print "0.0.0.0\t"$2 }' | grep -v "#" &gt;&gt; adblock
wait

echo "Downloading file from MVPS.org"
wget -O mvps http://winhelp2002.mvps.org/hosts.txt
wait
echo "Processing MVPS.org file"
cat mvps | grep 0.0.0.0 | grep -v "# 0.0.0.0" | awk '{ print "0.0.0.0\t"$2 }' &gt;&gt; adblock
wait

echo "Downloading file from HPHosts"
wget -O hphosts http://hosts-file.net/download/hosts.txt
wait
echo "Processing HPHosts file"
cat hphosts | grep "127.0.0.1" | awk '{ print "0.0.0.0\t"$2 }' &gt;&gt; adblock
wait

echo "Writing changes to zone file"
tr '[A-Z]' '[a-z]' &lt; adblock | sort -f | uniq &gt; adblock.uniq
wait

echo "Reloading DNS Server"
/var/packages/dnsmasq/scripts/start-stop-status stop
/var/packages/dnsmasq/scripts/start-stop-status start
/var/packages/dnsmasq/scripts/start-stop-status status



No Comments


You can leave the first : )



Leave a Reply

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

*