What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Script: Auto-Update Dnscrypt Blocklist

Boji

Regular Contributor

This script automatically updates dnscrypt blocked-names.txt while allowing your custom rules to be maintained. Recommended: update to at least dnscrypt 2.1.9 and enable hot reloading in dnscrypt-proxy.toml so changes to blocklist are applied instantly without having to restart dnscrypt.

Download/Install
Code:
wget -O /jffs/scripts/update_dnscrypt.sh https://github.com/rugabunda/AsusWRTPurity/raw/refs/heads/master/Autoupdate_dnscrypt_blocklist.sh && chmod 755 /jffs/scripts/update_dnscrypt.sh

Add cron job to services-start: update blocklist every 6 hours
Code:
echo 'cru a update_dnscrypt "0 */6 * * * /jffs/scripts/update_dnscrypt.sh"' >> /jffs/scripts/services-start

Enable in current session without reboot
Code:
cru a update_dnscrypt "0 */6 * * * /jffs/scripts/update_dnscrypt.sh"

Ensure code matches blocked-names.txt path in dnscrypt-proxy.toml & preferred log path.

Important: If using custom entries at top of blocklist, you may change sed line number accordingly, if none, you may use 1. Reserve space by inserting empty lines eg. up to line 1000; update sed to match.

Code:
#!/bin/sh

# Script to update DNSCrypt blocklist
# Downloads latest domain list and replaces blocked-names.txt content after line 345

# Define file paths
BLOCKLIST="/jffs/addons/dnscrypt/blocked-names.txt"  # blocklist location
BACKUP_FILE="${BLOCKLIST}.backup"  # Fixed backup name (will overwrite previous backup)
DOWNLOADED_FILE="/jffs/addons/dnscrypt/oisd_big_domainswild.txt"

# Create a backup first (overwriting any previous backup)
cp "$BLOCKLIST" "$BACKUP_FILE"
if [ $? -ne 0 ]; then
    echo "Failed to create backup on $(date)" >> /jffs/addons/dnscrypt/update_dnscrypt.log
    exit 1
fi

# Download the latest blocklist
curl -s -o "$DOWNLOADED_FILE" "https://big.oisd.nl/domainswild"

# Check if download was successful
if [ $? -ne 0 ]; then
    echo "Failed to download blocklist on $(date)" >> /jffs/addons/dnscrypt/update_dnscrypt.log
    exit 1
fi

# Delete everything in blocked-names.txt after line 345 and append downloaded content
sed -i '346,$d' "$BLOCKLIST"
cat "$DOWNLOADED_FILE" >> "$BLOCKLIST"

# Reload DNSCrypt (uneeded after 2.1.9 if Hot-reloading is enabled, changes apply instantly)
#/jffs/dnscrypt/manager dnscrypt-start

echo "DNSCrypt blocklist updated successfully on $(date)" >> /jffs/addons/dnscrypt/update_dnscrypt.log
 
Last edited:
Thanks ... Useful to me.
:)
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top