Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Synology script to update blacklist for DNSServer (based on bind9)
# Name:
# Author: Ryan Gibbons <
# Date: 20160214
# Description: Updated a blacklist data file for Bind that will point a null zone to route each domain to
# Inspiration and Thanks:
# *
# *
# *
# *
# *
# Process URLs if they offer a zip we'll use it to save them bandwidth.
# Not using b/c it ~350K objects and causes named to consume over 2GB ram
ZIP_URLS="" #"
# Use a temporary directory to store the downloads and working files
TMPFILE=$(head -c 50 /dev/urandom | tr -dc 'a-zA-Z0-9')
mkdir -p $TMPDIR
for url in $ZIP_URLS; do
# Silent curl on each URL comparing the last-modified-since before attempting to downlaod
curl -s -z $TMPDIR/$ -o $TMPDIR/$ $url
# Unzip to stdout, sed to remove windows newliens and domains ending with period,
# 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
# then for each entry in a host file pointing to or create a BIND formated zone statement
unzip -c $TMPDIR/$ | sed -e $'s/\r//' -e 's/\.$//' | awk '/^(|{print "zone \""$2"\" { type master; notify no; file \"/etc/zone/master/\"; };"}' >> $TMPDIR/$TMPFILE
i=$((i + 1))
for url in $PLAIN_URLS; do
curl -s -z $TMPDIR/$i -o $TMPDIR/$i $url
cat $TMPDIR/$i | sed -e $'s/\r//' -e 's/\.$//' | awk '/^(|{print "zone \""$2"\" { type master; notify no; file \"/etc/zone/master/\"; };"}' >> $TMPDIR/$TMPFILE
i=$(( i + 1))
# Strip out localhost, localdomain, broadcasthost, localhost.localdomain entries, and install the blacklist
cat $TMPDIR/$TMPFILE | sed -e '/"\(local\|broadcast\)\(host\)\?\(.localdomain\)\?"/d' | sort -fu > $BLACKLISTFILE
# reload the zone entries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.