Use Synology as an ad-blocker

Today I wondered if it was possible to use my Synology as an ad blocker.

I got the following steps from a thread at the synology forum: http://forum.synology.com/enu/viewtopic.php?f=39&t=78126

I combined these steps and tested them succesfully using my DS211+ with DSM 5.2 (update 3)

GUI Settings

  1. Install the DNS Server package on your Synology.
  2. Under “Zones”, “Create” a new “Master zone”
  3. Domain type: “Forward Zone”
  4. Domain name: “null.zone.file”
  5. Master DNS Server: Your-Synology-IP-Address (Ex: “192.168.1.2”)
  6. Serial format: “Date (YYYYMMDDNN)”
  7. Activate resolutions just in case the requested ip address can’t be resolved by the DNS Server. I am using alternate DNS addresses from Opennic

Telnet /SSH settings

  1. Download the ad-blocker.sh script from: https://www.dropbox.com/s/xz1i7hxb9sfug36/ad-blocker.sh?dl=0
  2. Copy the script to your NAS in the following directory: /var/packages/DNSServer/target/script/ad-blocker.sh
  3. Give the script execute permissions: chmod +x /var/packages/DNSServer/target/script/ad-blocker.sh
  4. Run the following command to execute the script: sh /var/packages/DNSServer/target/script/ad-blocker.sh

Now the DNS server is installed and configured on the NAS.

How to use the DNS Server?

There are several options. You can set the new DNS address on every single device you’re using.

But it is easier to reconfigure the DNS address centrally. In my case I decided to set the new DNS address on my router.

So, there you go, no more annoying ads!

Credits go to nebulus and dMajo

Use Synology as an ad-blocker

16 thoughts on “Use Synology as an ad-blocker

    1. If you want to add an ip address manually, you have to add it to the file ad-blocker.db.
      It is located in /var/packages/DNSServer/target/named/etc/zone/data

      Like

      1. Henk says:

        This only works until the next reload. The unix shell script (ad-blocker.sh) deletes the current ad-blocker.db and replaces it with the newly fetched (with wget) blacklist.
        If you want to permenantly add domain names to the blacklist, change the ad-blocker.sh script contain the following:

        # Add custom blacklist to ad-blocker.db
        wget “<>/ad-blocker-custom.txt”
        cat ad-blocker-custom.txt >> ad-blocker.db
        rm “ad-blocker-custom.txt”

        Add this right before the # Include the new zone data section.

        The “cat” command merges your own blacklist with the existing one.

        Like

  1. Hi.

    Could someone point me in the direction on how to modify the script so I can download the ad-blocker.db from my own webspace? I want to run the script daily and it would be easier to edit the ad-blocker.db to add new hosts.

    Like

  2. Martin says:

    /etc/zone/data/ad-blocker.db:2342: writeable file ‘/etc/zone/master/null.zone.file’: already in use: /etc/zone/data/null.zone.file:3
    is the error on DMS6.0

    This error is there for every rule in the ad-blocker.db

    As far as i can tell you can’t reuse the zone file.

    Like

    1. Ken J says:

      I’m using DSM 6.0 (latest update as of today’s date) and this script works fine for me. I just added a custom domain to the script and re-ran it. Everything works for me.

      Liked by 1 person

  3. Thierry says:

    Hello,
    This still works fine in 2019, on my DSM 6.2.1. Thank you for the job.
    But it seems that ads are not blocked when the client uses IPV6.
    Is it possible to add IPV6 support ?

    Like

  4. HenBe says:

    Works awesomely on my DS216j (June 2019). The only flaw I can find is that I apparently can’t use wildcards like “zone “*.cloudfront.net” {…}” or regular expressions in the db file. Did anyone manage to do this?

    Like

Leave a comment