Ad blocking

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 06:44, 30 June 2011 (edit)
Sash (Talk | contribs)

← Previous diff
Revision as of 10:32, 2 August 2012 (edit) (undo)
Sash (Talk | contribs)
(shorten the script. keep it more simple. download at startup and once a day.)
Next diff →
Line 9: Line 9:
#!/bin/sh #!/bin/sh
logger WAN up script executing logger WAN up script executing
-sleep 2+if test -s /tmp/hosts0
-if test ! -s /tmp/dlhosts+
then then
- cat >/tmp/dlhosts <<"EOF"+ rm /tmp/hosts0
 +fi
 + 
logger Downloading http://www.mvps.org/winhelp2002/hosts.txt logger Downloading http://www.mvps.org/winhelp2002/hosts.txt
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 |
Line 23: Line 24:
killall dnsmasq killall dnsmasq
dnsmasq --conf-file=/tmp/dnsmasq.conf dnsmasq --conf-file=/tmp/dnsmasq.conf
-EOF 
- chmod 777 /tmp/dlhosts 
- /tmp/dlhosts 
-fi 
-grep -q '/tmp/dlhosts' /tmp/crontab ||  
- echo "45 23 * * 5 root /tmp/dlhosts" >>/tmp/crontab 
</pre> </pre>
</code> </code>
- +...and this into cron:
 +<code>
 +<pre>
 +* 1 * * * root /tmp/.rc_startup
 +</pre>
 +</code>
Enable DNSMasq and Local DNS in Services tab; no Additional DNSMasq options necessary. Enable DNSMasq and Local DNS in Services tab; no Additional DNSMasq options necessary.

Revision as of 10:32, 2 August 2012

This script, courtesy of several people on the forums, who probably should be named, will enable host-based ad blocking via dns.

Maybe this script will not work on every device or it might crash your router when ther is not enough free ram.

Just put this script into "Startup":

#!/bin/sh
logger WAN up script executing
if test -s /tmp/hosts0
then
        rm /tmp/hosts0
fi

logger Downloading http://www.mvps.org/winhelp2002/hosts.txt
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 |
	sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |
	grep -v localhost | tr ' ' '\t' |
	tr -s '\t' | tr -d '\015' | sort -u >/tmp/hosts0
grep addn-hosts /tmp/dnsmasq.conf ||
	echo "addn-hosts=/tmp/hosts0" >>/tmp/dnsmasq.conf
logger Restarting dnsmasq
killall dnsmasq
dnsmasq --conf-file=/tmp/dnsmasq.conf

...and this into cron:

* 1 * * * root /tmp/.rc_startup

Enable DNSMasq and Local DNS in Services tab; no Additional DNSMasq options necessary.

Ensure cron is enabled.