{"id":1061,"date":"2018-07-23T15:47:39","date_gmt":"2018-07-23T19:47:39","guid":{"rendered":"http:\/\/vitamin-max.com\/word\/?p=1061"},"modified":"2018-07-23T15:47:39","modified_gmt":"2018-07-23T19:47:39","slug":"synology-rt2600ac-router-ad-block-script","status":"publish","type":"post","link":"https:\/\/vitamin-max.com\/word\/2018\/07\/synology-rt2600ac-router-ad-block-script\/","title":{"rendered":"Synology RT2600AC Router Ad-Block Script"},"content":{"rendered":"<p>Most of the scripts online such as <a href=\"https:\/\/gist.github.com\/rtgibbons\/999dd7fb7519df69ae92#file-updateblacklist-sh\">this<\/a>, <a href=\"https:\/\/forum.synology.com\/enu\/viewtopic.php?t=118988&amp;start=60\">this<\/a>, and <a href=\"https:\/\/synologytweaks.wordpress.com\/2015\/08\/23\/use-synology-as-an-ad-blocker\/\">this<\/a>, are written for Synology DSM or their NAS. I have been having some issues using these scripts on my Synology Router. Synology does not publish as many official packages for their router as their NAS anyways.&nbsp;<\/p>\n<p>I think these scripts do not work well because the shell in their router is busybox ash rather than a more advanced shell. My theory is based on the execution errors I get. It appears some functions and syntax that work for others on NAS does not work on the router.&nbsp;<\/p>\n<p>However I managed to combine a couple of scripts to make it work decently.&nbsp;<\/p>\n<p>Just scp and upload the following shell script as update blacklist.sh to your Synology Router, to the folder &#8220;\/var\/packages\/DNSServer\/target\/script\/&#8221;, and execute the shell as root after you SSH in, and it should work.&nbsp;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n# Name: updateblacklist.sh\r\n# Author: Ryan Gibbons &lt;rtgibbons23 @ gmail.com&gt;\r\n# Date: 20160214\r\n# Description: Updated a blacklist data file for Bind that will point a null zone to route each domain to 0.0.0.0\r\n# Inspiration and Thanks:\r\n# \t* http:\/\/www.wilderssecurity.com\/threads\/a-script-for-updating-your-hosts-file.343978\/\r\n# \t* http:\/\/someonewhocares.org\/hosts\/\r\n#       * http:\/\/pgl.yoyo.org\/adservers\/\r\n#       * http:\/\/winhelp2002.mvps.org\/\r\n#       * http:\/\/hosts-file.net\/\r\n# Modified by Jeremy Yan &lt;jeremy at yansc dot com&gt;\r\n# Credit: Ryan Gibbons, dMajo, and Gerzon\r\n\r\n# Process URLs if they offer a zip we'll use it to save them bandwidth. \r\n# Not using host-file.net b\/c it ~350K objects and causes named to consume over 2GB ram\r\nZIP_URLS=&quot;http:\/\/winhelp2002.mvps.org\/hosts.zip&quot; # http:\/\/hosts-file.net\/download\/hosts.zip&quot;\r\nPLAIN_URLS=&quot;http:\/\/someonewhocares.org\/hosts\/host http:\/\/pgl.yoyo.org\/as\/serverlist.php?hostformat=hosts&amp;showintro=1&amp;mimetype=plaintext&quot;\r\n\r\n# Use a temporary directory to store the downloads and working files\r\nTMPDIR=\/volume1\/@appstore\/DNSServer\/named\/tmp\/updateblacklist\r\nTMPFILE=$(head -c 50 \/dev\/urandom | tr -dc 'a-zA-Z0-9')\r\n\r\nBLACKLISTFILE=\/volume1\/@appstore\/DNSServer\/named\/etc\/zone\/data\/blacklist.db\r\n\r\nmkdir -p $TMPDIR\r\n\r\ni=1\r\n\r\nfor url in $ZIP_URLS; do\r\n\t# Silent curl on each URL comparing the last-modified-since before attempting to downlaod\r\n        curl -s -z $TMPDIR\/$i.zip -o $TMPDIR\/$i.zip $url\r\n        # Unzip to stdout, sed to remove windows newliens and domains ending with period,\r\n        # The $ before the first sed expression is to process the string in bash b\/c version of sed with DSM5.2 doesn't recongize \\r\r\n        # then for each entry in a host file pointing to 127.0.0.1 or 0.0.0.0 create a BIND formated zone statement\r\n        unzip -c $TMPDIR\/$i.zip | sed -e $'s\/\\r\/\/' -e 's\/\\.$\/\/' | awk '\/^(0.0.0.0|127.0.0.1)\/{print &quot;zone \\&quot;&quot;$2&quot;\\&quot; { type master; notify no; file \\&quot;\/etc\/zone\/master\/null.zone.file\\&quot;; };&quot;}' &gt;&gt; $TMPDIR\/$TMPFILE\r\n        i=$((i + 1))\r\ndone\r\n\r\nfor url in $PLAIN_URLS; do\r\n        curl -s -z $TMPDIR\/$i -o $TMPDIR\/$i $url\r\n        cat $TMPDIR\/$i | sed -e $'s\/\\r\/\/' -e 's\/\\.$\/\/' | awk '\/^(0.0.0.0|127.0.0.1)\/{print &quot;zone \\&quot;&quot;$2&quot;\\&quot; { type master; notify no; file \\&quot;\/etc\/zone\/master\/null.zone.file\\&quot;; };&quot;}' &gt;&gt; $TMPDIR\/$TMPFILE\r\n        i=$(( i + 1))\r\ndone\r\n\r\n# Strip out localhost, localdomain, broadcasthost, localhost.localdomain entries, and install the blacklist\r\ncat $TMPDIR\/$TMPFILE | sed -e '\/&quot;\\(local\\|broadcast\\)\\(host\\)\\?\\(.localdomain\\)\\?&quot;\/d' | sort -fu &gt; $BLACKLISTFILE\r\n\r\nrm $TMPDIR\/$TMPFILE\r\n\r\n\r\n# Include the new zone data\r\n# This section is adopted from dMajo's script\r\nWorkDir=&quot;\/var\/packages\/DNSServer\/target\/named\/etc\/zone\/data&quot;\r\ncd ${WorkDir}\r\n\tif &#x5B; -f blacklist.db ] &amp;&amp; &#x5B; -f null.zone.file ]; then\r\n\t\t#grep -q 'include &quot;\/etc\/zone\/data\/ad-blocker.db&quot;;' null.zone.file || echo 'include &quot;\/etc\/zone\/data\/ad-blocker.db&quot;;' &gt;&gt; null.zone.file\r\n\t\t# Rebuild data null.zone.file\r\n\t\techo 'zone &quot;null.zone.file&quot; {'\t\t\t\t\t&gt; null.zone.file\r\n\t\techo '\ttype master;'\t\t\t\t\t\t\t&gt;&gt; null.zone.file\r\n\t\techo '\tfile &quot;\/etc\/zone\/master\/null.zone.file&quot;;'&gt;&gt; null.zone.file\r\n\t\techo '\tallow-transfer {any;};'\t\t\t\t\t&gt;&gt; null.zone.file\r\n\t\techo '\tallow-update {none;};'\t\t\t\t\t&gt;&gt; null.zone.file\r\n\t\techo '\tallow-query {any;};'\t\t\t\t\t&gt;&gt; null.zone.file\r\n\t\techo '};'\t\t\t\t\t\t\t\t\t\t&gt;&gt; null.zone.file\r\n\t\techo 'include &quot;\/etc\/zone\/data\/blacklist.db&quot;;'\t&gt;&gt; null.zone.file\r\n\tfi\r\n\r\n# reload the zone entries\r\n\/volume1\/@appstore\/DNSServer\/script\/reload.sh\r\n\r\n<\/pre>\n<p>Note the pre-requisites:<\/p>\n<ul>\n<li>You must have DNSServer package installed<\/li>\n<li>You should create a master zone called &#8220;null.zone.file&#8221; in the Zones. See the screenshot below<\/li>\n<\/ul>\n<p>Then you should be okay.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1068\" src=\"https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM.png\" alt=\"\" width=\"1218\" height=\"1208\" srcset=\"https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM.png 1218w, https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM-150x150.png 150w, https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM-300x298.png 300w, https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM-768x762.png 768w, https:\/\/vitamin-max.com\/word\/wp-content\/uploads\/2018\/07\/Screen-Shot-2018-07-23-at-3.47.07-PM-1024x1016.png 1024w\" sizes=\"auto, (max-width: 1218px) 100vw, 1218px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the scripts online such as this, this, and this, are written for Synology DSM or their NAS. I have been having some issues using these scripts on my Synology Router. Synology does not publish as many official packages for their router as their NAS anyways.&nbsp; I think these scripts do not work well&hellip; <a class=\"more-link\" href=\"https:\/\/vitamin-max.com\/word\/2018\/07\/synology-rt2600ac-router-ad-block-script\/\">Continue reading <span class=\"screen-reader-text\">Synology RT2600AC Router Ad-Block Script<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1061","post","type-post","status-publish","format-standard","hentry","category--general","entry"],"_links":{"self":[{"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/posts\/1061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/comments?post=1061"}],"version-history":[{"count":7,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/posts\/1061\/revisions"}],"predecessor-version":[{"id":1069,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/posts\/1061\/revisions\/1069"}],"wp:attachment":[{"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/media?parent=1061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/categories?post=1061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vitamin-max.com\/word\/wp-json\/wp\/v2\/tags?post=1061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}