What's new

DNS blocking script

  • 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!

Travison

Occasional Visitor
A daily crontab can be used to run and update the list daily.

You need to add the line "addn-hosts=/jffs/block.hosts" in /etc/dnsmasq.conf for blocking to work. I used the web interface to add additional hosts file so it will be saved in reboots. Not sure if you manually add the line in command if it will be saved upon reboot.

But to manually add it you can run this command (not sure if it will be saved in next reboot, safer to use web interface and add it there):
echo "addn-hosts=/jffs/block.hosts" >> /etc/dnsmasq.conf

-------------------------------

#!/bin/sh


# This scripts gathers lists from various sources used for DNS blocking.

# Grab lists from mvps.org / hosts-file.net / yoyo.org / someonewhocares.org and malwaredomainlist.com.
# Replaces
127.0.0.1 with 0.0.0.0 or adds 0.0.0.0 to the list.

wget -qO- http://www.mvps.org/winhelp2002/hosts.txt | awk '/^0.0.0.0/' >> /tmp/block.build.list
wget -qO-
http://www.malwaredomainlist.com/hostslist/hosts.txt | awk '{sub(/^127.0.0.1/, "0.0.0.0")} /^0.0.0.0/' >> /tmp/block.build.list
wget -qO- "
http://hosts-file.net/.\ad_servers.txt" | awk '{sub(/^127.0.0.1/, "0.0.0.0")} /^0.0.0.0/' >> /tmp/block.build.list
wget -qO- "
http://hosts-file.net/.\exp.txt" | awk '{sub(/^127.0.0.1/, "0.0.0.0")} /^0.0.0.0/' >> /tmp/block.build.list
wget -qO- "
http://hosts-file.net/.\emd.txt" | awk '{sub(/^127.0.0.1/, "0.0.0.0")} /^0.0.0.0/' >> /tmp/block.build.list
wget -qO- "
http://pgl.yoyo.org/as/serverlist.php?showintro=0;hostformat=hosts" | awk '{sub(/^127.0.0.1/, "0.0.0.0")} /^0.0.0.0/' >> /tmp/block.build.list
wget -qO-
http://someonewhocares.org/hosts/zero | awk '/^0.0.0.0/' >> /tmp/block.build.list

# Add your custom list, if you have one then uncomment next line.
#cat /jffs/custom.list >> /tmp/block.build.list


# Remove duplicate lines, ascii coded lines and sort into alphabetical order into block.hosts.
awk '{sub(/\r$/,"");print $1,$2}' /tmp/block.build.list | sort -u > /jffs/block.hosts


# Cleanup.
rm /tmp/block.build.list


# Restart DNSMASQ.
service restart_dnsmasq
 
Last edited:

Sign Up For SNBForums Daily Digest

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