Skip to content

Instantly share code, notes, and snippets.

@Razuuu
Created June 11, 2026 15:48
Show Gist options
  • Select an option

  • Save Razuuu/fab19b0773b284e162e68e512f964337 to your computer and use it in GitHub Desktop.

Select an option

Save Razuuu/fab19b0773b284e162e68e512f964337 to your computer and use it in GitHub Desktop.
Named DNS Adblocker
#!/bin/bash
# Crontab
# $ crontab -e
# Update named adblock every day at 4am
# 0 4 * * * /opt/named-adblock/update.sh
# Named
# Write this into your named.conf file
# include "/etc/bind/named.conf.adblock";
# Write this into your named.conf.options file
#options {
# directory "/var/cache/bind";
#
# allow-recursion {
# localhost;
# localnets;
# };
#
# dnssec-validation no;
#
# listen-on-v6 { any; };
#};
# Drop this into your /etc/bind directory
# File > null.zone.file
# $TTL 86400
# @ IN SOA ns1.randomdomainname.adm. dns-admin.randomdomainname.adm. 2026061101 28800 7200 864000 86400
#
# ; ################ NAMESERVER ################
# @ IN NS ns1.randomdomainname.adm.
# The actual script
# Vars
HEREAMI="$(dirname "$(readlink -f "${0}")")" # e.g /opt/named-adblock
URL="https://pgl.yoyo.org/adservers/serverlist.php?hostformat=bindconfig&showintro=0&zonefilename=/etc/bind/null.zone.file&mimetype=plaintext"
# Download adblock file
curl -s ${URL} -o /etc/bind/named.conf.adblock
# Set last updated in file, or commit out for no logs.
echo "Last updated: $(date +%d.%m.%Y) at $(date +%H:%M:%S)" > ${HEREAMI}/last_updated.txt
# Restart bind9/named
/usr/bin/systemctl restart named
# Exit script
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment