http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&action=history&feed=atom Blocking URL's/IP's - Revision history 2024-03-29T05:31:50Z Revision history for this page on the wiki MediaWiki 1.10.1 http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=42987&oldid=prev Glenn: Redirecting to Blocking URLs/IPs 2012-06-22T19:03:25Z <p>Redirecting to <a href="/wiki/index.php/Blocking_URLs/IPs" title="Blocking URLs/IPs">Blocking URLs/IPs</a></p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 19:03, 22 June 2012</td> </tr> <tr><td colspan="2" align="left"><strong>Line 1:</strong></td> <td colspan="2" align="left"><strong>Line 1:</strong></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">This page could not be linked to due to the apostrophes in the title so it is now here:</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"><ins style="color: red; font-weight: bold; text-decoration: none;">#redirect [[</ins>Blocking_URLs/IPs<ins style="color: red; font-weight: bold; text-decoration: none;">]]</ins></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">http://www.dd-wrt.com/wiki/index.php/</del>Blocking_URLs/IPs</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> </table> Glenn http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=40797&oldid=prev Donny: Replacing page with 'This page could not be linked to due to the apostrophes in the title so it is now here: http://www.dd-wrt.com/wiki/index.php/Blocking_URLs/IPs' 2011-07-05T11:52:24Z <p>Replacing page with 'This page could not be linked to due to the apostrophes in the title so it is now here: http://www.dd-wrt.com/wiki/index.php/Blocking_URLs/IPs'</p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 11:52, 5 July 2011</td> </tr> <tr><td colspan="2" align="left"><strong>Line 1:</strong></td> <td colspan="2" align="left"><strong>Line 1:</strong></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">__TOC__</del></td><td>+</td><td style="background: #cfc; font-size: smaller;">This <ins style="color: red; font-weight: bold; text-decoration: none;">page could </ins>not be <ins style="color: red; font-weight: bold; text-decoration: none;">linked </ins>to <ins style="color: red; font-weight: bold; text-decoration: none;">due </ins>to the <ins style="color: red; font-weight: bold; text-decoration: none;">apostrophes </ins>in the <ins style="color: red; font-weight: bold; text-decoration: none;">title so </ins>it is <ins style="color: red; font-weight: bold; text-decoration: none;">now </ins>here:</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;">http://www.dd-wrt.com/wiki/index.php/<ins style="color: red; font-weight: bold; text-decoration: none;">Blocking_URLs/IPs</ins></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">==Block URLs with an Automatically Downloaded Host File==</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">I have kept the original script, which is below this one. </del>This <del style="color: red; font-weight: bold; text-decoration: none;">one is much shorter, but does even more checking than the other one.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">It tries to download the file at least 5 times after startup</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">An even better solution is offered in my set of optware scripts where it will also run pixelserv on the router.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">I didn't like the cronjob approach because the list is quite static.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">frater</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;pre&gt;_rogue=127.0.0.1</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">echo -e &quot;n=1\nwhile ! wget -q -O /tmp/hsts http://www.mvps.org/winhelp2002/hosts.txt ; do\n\t[ \$n -gt 5 ] &amp;&amp; break\n\tlet n+=1\n\tsleep 60\ndone\ngrep \&quot;^127.0.0.1\&quot; /tmp/hsts | grep \&quot;^127.0.0.1\&quot; | grep -v localhost | awk '{print \&quot;$_rogue\\\t\&quot;\$2}' | tr -d '\\\015' &gt;/tmp/dlhosts\nrm /tmp/hsts\nkillall -HUP dnsmasq&quot; &gt;/tmp/wh</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">sh /tmp/wh &amp;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;/pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">IMHO the following script is deprecated, but I left it for comparison.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">This was originally taken from mraneri from the Linksys forum, but was heavily modified.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#!/bin/sh</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">logger WAN up script executing</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">sleep 5</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">if test ! -s /tmp/dlhosts</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">then</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> cat &gt;/tmp/dlhosts &lt;&lt;&quot;EOF&quot;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#!/bin/sh</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">logger Downloading http://www.mvps.org/winhelp2002/hosts.txt</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">wget -O - http://www.mvps.org/winhelp2002/hosts.txt |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> grep 127.0.0.1 |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> grep -v localhost |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> tr ' ' '\t' |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> tr -s '\t' |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> tr -d '\015' |</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> sort -u &gt;/tmp/hosts0</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">grep addn-hosts /tmp/dnsmasq.conf ||</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">grep addn-hosts /tmp/dnsmasq.conf ||</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">logger Restarting dnsmasq</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">killall -HUP dnsmasq</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">dnsmasq --conf-file=/tmp/dnsmasq.conf</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">EOF</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> chmod 777 /tmp/dlhosts</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> /tmp/dlhosts</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">fi</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">grep -q '/tmp/dlhosts' /tmp/crontab || </del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> echo &quot;45 23 * * 5 root /tmp/dlhosts&quot; &gt;&gt;/tmp/crontab</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;/pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">This script automatically downloads a host file from: &quot;http://www.mvps.org/winhelp2002/hosts.txt&quot; and redirects all the URLs in that file to 127.0.0.1.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">All those URLs are common malware or advertisement sites so is better to block them.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">You can also download the file, modify it with new URLs that you want to block or delete the ones you don't want to block and then upload to a web site and change the URL in the code to your custom one.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">Be aware that the more URLs in the file the more RAM that you will be eating from your router. Check the file size and your free memory to see if it will suit you. If </del>not <del style="color: red; font-weight: bold; text-decoration: none;">just erase some URLs...</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">If you want to block all URLs since the router boots then just placed in the startup scripts.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">--Brueggmann 10.17.2010 - I've modified the &quot;killall&quot; line as sending a HUP didn't reread the configuration file for me. Please see the dnsmasq man page.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">'''Update''' by Aviad (A.K.A. Hotfortech): While the above works just fine, there are two main disadvantages of the above method:</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">1. The blocked content will </del>be <del style="color: red; font-weight: bold; text-decoration: none;">shown as &quot;page cannot be displayed&quot; within the websites advertisement segments and will cause the page </del>to <del style="color: red; font-weight: bold; text-decoration: none;">not load until the browser gives up on the missing object.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">2. If you want </del>to <del style="color: red; font-weight: bold; text-decoration: none;">add sites to the block list, you have to do it on a per host bases... (tedious)</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">Enter shameless self promotion -&gt; I have created a script on my [http://hotfortech.wikispaces.com/How+to+remove+advertisements+with+pixelserv+on+DD-WRT wiki] that deals with the above and more by using </del>the <del style="color: red; font-weight: bold; text-decoration: none;">pixelserv method described </del>in the <del style="color: red; font-weight: bold; text-decoration: none;">forum.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">you can find the script and a detailed explanation on how </del>it <del style="color: red; font-weight: bold; text-decoration: none;">works on my wiki:</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">http://hotfortech.wikispaces.com/How+to+remove+advertisements+with+pixelserv+on+DD-WRT</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">Hope this helps anyone.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">BobLfoot - Edit Note : 2011-01-14 added line &quot;dnsmasq --conf-file=/tmp/dnsmasq.conf&quot; to the script as it was stopping dnsmasq, but not restarting it. Also found that adding &quot;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">grep addn-hosts /tmp/dnsmasq.conf ||</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">made sure that the dnsmasq.conf addition went on a new line. Script might be made leaner through \n usage but that </del>is <del style="color: red; font-weight: bold; text-decoration: none;">untested.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">==Global Blacklisting per MAC==</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">If you have a lot of DD-WRT routers, then denying of access for abusing users through the web interface of each router can be time consuming.&lt;p&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">Here is a small firewall script to automatically download MAC-addresses of computers that should be denied access. The format of the file is Unix textfile one MAC address per line. The script assumes that you have a jffs partition. You can run it at startup by saving it as /jffs/etc/config/wifi_bl.wanup</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#!/bin/sh</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">cd /jffs</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">rm wifi_blacklist.txt</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#Please modify the script to download the blacklist file from your web server</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">wget http://www.myserver.com/wifi_blacklist.txt</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">module_exists=`lsmod | grep ipt_mac`</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">if [ -z &quot;$module_exists&quot; ] ; then</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> insmod ipt_mac</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">fi</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#Deleting the old table</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">old_mac=`iptables -L | egrep &quot;..:..:..:..:..:..&quot; | sed &quot;s/.*\(..:..:..:..:..:..\).*/\1/&quot;`</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">for mac in $old_mac ; do</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> iptables -D FORWARD -p tcp -m mac --mac-source $mac -j REJECT --reject-with tcp-reset</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">done</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#Adding the table again</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">for mac in `cat /jffs/wifi_blacklist.txt` ; do</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"> iptables -I FORWARD -p tcp -m mac --mac-source $mac -j REJECT --reject-with tcp-reset</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">done</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;/pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">==White Listing==</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">If you want to create a white list to block access by default but allow certain traffic through, then you can use this script to do it. Remove any junk comment lines beginning with # to save nvram space. Discuss [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588 </del>here<del style="color: red; font-weight: bold; text-decoration: none;">].</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># IP Tables White Listing script by phuzi0n -Tek @ http</del>:<del style="color: red; font-weight: bold; text-decoration: none;">//www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Version 4. Please increment version number with subsequent modifications. GeeTek.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Set up the chain</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">iptables -N wanout</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">iptables -I INPUT -i `nvram get lan_ifname` -j wanout</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">iptables -I FORWARD -i `nvram get lan_ifname` -j wanout</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Create whitelist 'function' script</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">WOUT=&quot;/tmp/wanout&quot;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">echo 'iptables -I wanout -j ACCEPT' &gt; $WOUT</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">chmod 777 $WOUT</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Exempt Machine MAC</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># load xt_mac instead of ipt_mac on k2.6 builds</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">insmod ipt_mac</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-m mac --mac-source 00:30:18:A9:A9:C6'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Exempt Machine IP</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-s 192.168.1.2'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Allow everyone access to these sites (DNS lookup only happens once when rule is inserted and stays that single IP)</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d www.google.com'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d www.yahoo.com'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d www.dd-wrt.com'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Allow everyone access to these IP addresses/netmask</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d 74.125.67.100'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d 74.125.127.100'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d 74.125.45.100/24'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-d 209.131.36.158/29'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">#Allow everyone access to specific destination ports</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-p udp --dport 8000'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">$WOUT '-p tcp --dport 80'</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;"># Everything else gets blocked</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">&lt;/pre&gt;</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">http://www.dd-wrt.com/wiki/index.php/<del style="color: red; font-weight: bold; text-decoration: none;">Ad_blocking</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">&#160;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">[[Category:Traffic moderation]]</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> </table> Donny http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=38424&oldid=prev Phuzi0n: /* White Listing */ 2011-01-31T00:57:35Z <p><span class="autocomment">White Listing</span></p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 00:57, 31 January 2011</td> </tr> <tr><td colspan="2" align="left"><strong>Line 123:</strong></td> <td colspan="2" align="left"><strong>Line 123:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-s 192.168.1.2'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-s 192.168.1.2'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"># Allow everyone access to these sites</td><td>+</td><td style="background: #cfc; font-size: smaller;"># Allow everyone access to these sites <ins style="color: red; font-weight: bold; text-decoration: none;"> (DNS lookup only happens once when rule is inserted and stays that single IP)</ins></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.google.com'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.google.com'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.yahoo.com'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.yahoo.com'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.dd-wrt.com'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d www.dd-wrt.com'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"># Allow everyone access to these IP <del style="color: red; font-weight: bold; text-decoration: none;">Addresses</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"># Allow everyone access to these IP <ins style="color: red; font-weight: bold; text-decoration: none;">addresses/netmask</ins></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d 74.125.67.100'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d 74.125.67.100'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d 74.125.127.100'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-d 74.125.127.100'</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">$WOUT '-d 74.125.45.100'</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT '-d 74.125.45.100<ins style="color: red; font-weight: bold; text-decoration: none;">/24</ins>'</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">$WOUT '-d 209.131.36.158'</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT '-d 209.131.36.158<ins style="color: red; font-weight: bold; text-decoration: none;">/29</ins>'</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">#Allow everyone access to specific destination ports</td><td> </td><td style="background: #eee; font-size: smaller;">#Allow everyone access to specific destination ports</td></tr> </table> Phuzi0n http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=38000&oldid=prev BobLfoot: /* Block URLs with an Automatically Downloaded Host File */ 2011-01-15T05:09:53Z <p><span class="autocomment">Block URLs with an Automatically Downloaded Host File</span></p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 05:09, 15 January 2011</td> </tr> <tr><td colspan="2" align="left"><strong>Line 34:</strong></td> <td colspan="2" align="left"><strong>Line 34:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> tr -d '\015' |</td><td> </td><td style="background: #eee; font-size: smaller;"> tr -d '\015' |</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> sort -u &gt;/tmp/hosts0</td><td> </td><td style="background: #eee; font-size: smaller;"> sort -u &gt;/tmp/hosts0</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">grep addn-hosts /tmp/dnsmasq.conf ||</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">grep addn-hosts /tmp/dnsmasq.conf ||</td><td> </td><td style="background: #eee; font-size: smaller;">grep addn-hosts /tmp/dnsmasq.conf ||</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf</td><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">logger Restarting dnsmasq</td><td> </td><td style="background: #eee; font-size: smaller;">logger Restarting dnsmasq</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">killall -HUP dnsmasq</td><td> </td><td style="background: #eee; font-size: smaller;">killall -HUP dnsmasq</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">dnsmasq --conf-file=/tmp/dnsmasq.conf</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">EOF</td><td> </td><td style="background: #eee; font-size: smaller;">EOF</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> chmod 777 /tmp/dlhosts</td><td> </td><td style="background: #eee; font-size: smaller;"> chmod 777 /tmp/dlhosts</td></tr> <tr><td colspan="2" align="left"><strong>Line 64:</strong></td> <td colspan="2" align="left"><strong>Line 67:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">Hope this helps anyone.</td><td> </td><td style="background: #eee; font-size: smaller;">Hope this helps anyone.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">BobLfoot - Edit Note : 2011-01-14 added line &quot;dnsmasq --conf-file=/tmp/dnsmasq.conf&quot; to the script as it was stopping dnsmasq, but not restarting it. Also found that adding &quot;</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">grep addn-hosts /tmp/dnsmasq.conf ||</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">made sure that the dnsmasq.conf addition went on a new line. Script might be made leaner through \n usage but that is untested.</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">==Global Blacklisting per MAC==</td><td> </td><td style="background: #eee; font-size: smaller;">==Global Blacklisting per MAC==</td></tr> </table> BobLfoot http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=37375&oldid=prev Frater: /* Block URLs with an Automatically Downloaded Host File */ 2010-11-29T20:39:35Z <p><span class="autocomment">Block URLs with an Automatically Downloaded Host File</span></p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 20:39, 29 November 2010</td> </tr> <tr><td colspan="2" align="left"><strong>Line 3:</strong></td> <td colspan="2" align="left"><strong>Line 3:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">==Block URLs with an Automatically Downloaded Host File==</td><td> </td><td style="background: #eee; font-size: smaller;">==Block URLs with an Automatically Downloaded Host File==</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">I have kept the original script, which is below this one. This one is much shorter, but does even more checking than the other one.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">It tries to download the file at least 5 times after startup</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">An even better solution is offered in my set of optware scripts where it will also run pixelserv on the router.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">I didn't like the cronjob approach because the list is quite static.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">frater</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">&lt;pre&gt;_rogue=127.0.0.1</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">echo -e &quot;n=1\nwhile ! wget -q -O /tmp/hsts http://www.mvps.org/winhelp2002/hosts.txt ; do\n\t[ \$n -gt 5 ] &amp;&amp; break\n\tlet n+=1\n\tsleep 60\ndone\ngrep \&quot;^127.0.0.1\&quot; /tmp/hsts | grep \&quot;^127.0.0.1\&quot; | grep -v localhost | awk '{print \&quot;$_rogue\\\t\&quot;\$2}' | tr -d '\\\015' &gt;/tmp/dlhosts\nrm /tmp/hsts\nkillall -HUP dnsmasq&quot; &gt;/tmp/wh</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">sh /tmp/wh &amp;</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">&lt;/pre&gt;</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">IMHO the following script is deprecated, but I left it for comparison.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">This was originally taken from mraneri from the Linksys forum, but was heavily modified.</td><td> </td><td style="background: #eee; font-size: smaller;">This was originally taken from mraneri from the Linksys forum, but was heavily modified.</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">&lt;pre&gt;</td><td> </td><td style="background: #eee; font-size: smaller;">&lt;pre&gt;</td></tr> <tr><td colspan="2" align="left"><strong>Line 25:</strong></td> <td colspan="2" align="left"><strong>Line 37:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf</td><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">logger Restarting dnsmasq</td><td> </td><td style="background: #eee; font-size: smaller;">logger Restarting dnsmasq</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">killall <del style="color: red; font-weight: bold; text-decoration: none;">dnsmasq</del></td><td>+</td><td style="background: #cfc; font-size: smaller;">killall -<ins style="color: red; font-weight: bold; text-decoration: none;">HUP </ins>dnsmasq</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"><del style="color: red; font-weight: bold; text-decoration: none;">dnsmasq --conf</del>-<del style="color: red; font-weight: bold; text-decoration: none;">file=/tmp/</del>dnsmasq<del style="color: red; font-weight: bold; text-decoration: none;">.conf</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">EOF</td><td> </td><td style="background: #eee; font-size: smaller;">EOF</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> chmod 777 /tmp/dlhosts</td><td> </td><td style="background: #eee; font-size: smaller;"> chmod 777 /tmp/dlhosts</td></tr> <tr><td colspan="2" align="left"><strong>Line 53:</strong></td> <td colspan="2" align="left"><strong>Line 64:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">Hope this helps anyone.</td><td> </td><td style="background: #eee; font-size: smaller;">Hope this helps anyone.</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2">&nbsp;</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2">&nbsp;</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">==Global Blacklisting per MAC==</td><td> </td><td style="background: #eee; font-size: smaller;">==Global Blacklisting per MAC==</td></tr> </table> Frater http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=36498&oldid=prev Sash: /* Global Management of Blacklists */ 2010-10-22T11:33:45Z <p><span class="autocomment">Global Management of Blacklists</span></p> <table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;"> <tr> <td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td> <td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 11:33, 22 October 2010</td> </tr> <tr><td colspan="2" align="left"><strong>Line 56:</strong></td> <td colspan="2" align="left"><strong>Line 56:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">==Global <del style="color: red; font-weight: bold; text-decoration: none;">Management of Blacklists</del>==</td><td>+</td><td style="background: #cfc; font-size: smaller;">==Global <ins style="color: red; font-weight: bold; text-decoration: none;">Blacklisting per MAC</ins>==</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">If you have a lot of DD-WRT routers, then denying of access for abusing users through the web interface of each router can be time consuming.&lt;p&gt;</td><td> </td><td style="background: #eee; font-size: smaller;">If you have a lot of DD-WRT routers, then denying of access for abusing users through the web interface of each router can be time consuming.&lt;p&gt;</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">Here is a small firewall script to automatically download MAC-addresses of computers that should be denied access. The format of the file is Unix textfile one MAC address per line. The script assumes that you have a jffs partition. You can run it at startup by saving it as /jffs/etc/config/wifi_bl.wanup</td><td> </td><td style="background: #eee; font-size: smaller;">Here is a small firewall script to automatically download MAC-addresses of computers that should be denied access. The format of the file is Unix textfile one MAC address per line. The script assumes that you have a jffs partition. You can run it at startup by saving it as /jffs/etc/config/wifi_bl.wanup</td></tr> <tr><td colspan="2" align="left"><strong>Line 79:</strong></td> <td colspan="2" align="left"><strong>Line 79:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">done</td><td> </td><td style="background: #eee; font-size: smaller;">done</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">&lt;/pre&gt;</td><td> </td><td style="background: #eee; font-size: smaller;">&lt;/pre&gt;</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2">&nbsp;</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2">&nbsp;</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2">&nbsp;</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">==White Listing==</td><td> </td><td style="background: #eee; font-size: smaller;">==White Listing==</td></tr> </table> Sash http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URL%27s/IP%27s&diff=36461&oldid=prev Sash: New page: __TOC__ ==Block URLs with an Automatically Downloaded Host File== This was originally taken from mraneri from the Linksys forum, but was heavily modified. <pre> #!/bin/sh logger WAN up ... 2010-10-22T10:46:38Z <p>New page: __TOC__ ==Block URLs with an Automatically Downloaded Host File== This was originally taken from mraneri from the Linksys forum, but was heavily modified. &lt;pre&gt; #!/bin/sh logger WAN up ...</p> <p><b>New page</b></p><div>__TOC__<br /> <br /> <br /> ==Block URLs with an Automatically Downloaded Host File==<br /> This was originally taken from mraneri from the Linksys forum, but was heavily modified.<br /> &lt;pre&gt;<br /> #!/bin/sh<br /> <br /> logger WAN up script executing<br /> sleep 5<br /> if test ! -s /tmp/dlhosts<br /> then<br /> cat &gt;/tmp/dlhosts &lt;&lt;&quot;EOF&quot;<br /> #!/bin/sh<br /> logger Downloading http://www.mvps.org/winhelp2002/hosts.txt<br /> wget -O - http://www.mvps.org/winhelp2002/hosts.txt |<br /> grep 127.0.0.1 |<br /> sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |<br /> grep -v localhost |<br /> tr ' ' '\t' |<br /> tr -s '\t' |<br /> tr -d '\015' |<br /> sort -u &gt;/tmp/hosts0<br /> grep addn-hosts /tmp/dnsmasq.conf ||<br /> echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt;/tmp/dnsmasq.conf<br /> logger Restarting dnsmasq<br /> killall dnsmasq<br /> dnsmasq --conf-file=/tmp/dnsmasq.conf<br /> EOF<br /> chmod 777 /tmp/dlhosts<br /> /tmp/dlhosts<br /> fi<br /> grep -q '/tmp/dlhosts' /tmp/crontab || <br /> echo &quot;45 23 * * 5 root /tmp/dlhosts&quot; &gt;&gt;/tmp/crontab<br /> &lt;/pre&gt;<br /> This script automatically downloads a host file from: &quot;http://www.mvps.org/winhelp2002/hosts.txt&quot; and redirects all the URLs in that file to 127.0.0.1.<br /> All those URLs are common malware or advertisement sites so is better to block them.<br /> You can also download the file, modify it with new URLs that you want to block or delete the ones you don't want to block and then upload to a web site and change the URL in the code to your custom one.<br /> Be aware that the more URLs in the file the more RAM that you will be eating from your router. Check the file size and your free memory to see if it will suit you. If not just erase some URLs...<br /> If you want to block all URLs since the router boots then just placed in the startup scripts.<br /> <br /> --Brueggmann 10.17.2010 - I've modified the &quot;killall&quot; line as sending a HUP didn't reread the configuration file for me. Please see the dnsmasq man page.<br /> <br /> '''Update''' by Aviad (A.K.A. Hotfortech): While the above works just fine, there are two main disadvantages of the above method:<br /> <br /> 1. The blocked content will be shown as &quot;page cannot be displayed&quot; within the websites advertisement segments and will cause the page to not load until the browser gives up on the missing object.<br /> <br /> 2. If you want to add sites to the block list, you have to do it on a per host bases... (tedious)<br /> <br /> Enter shameless self promotion -&gt; I have created a script on my [http://hotfortech.wikispaces.com/How+to+remove+advertisements+with+pixelserv+on+DD-WRT wiki] that deals with the above and more by using the pixelserv method described in the forum.<br /> you can find the script and a detailed explanation on how it works on my wiki:<br /> http://hotfortech.wikispaces.com/How+to+remove+advertisements+with+pixelserv+on+DD-WRT<br /> <br /> Hope this helps anyone.<br /> <br /> <br /> <br /> ==Global Management of Blacklists==<br /> If you have a lot of DD-WRT routers, then denying of access for abusing users through the web interface of each router can be time consuming.&lt;p&gt;<br /> Here is a small firewall script to automatically download MAC-addresses of computers that should be denied access. The format of the file is Unix textfile one MAC address per line. The script assumes that you have a jffs partition. You can run it at startup by saving it as /jffs/etc/config/wifi_bl.wanup<br /> &lt;pre&gt;<br /> #!/bin/sh<br /> cd /jffs<br /> rm wifi_blacklist.txt<br /> #Please modify the script to download the blacklist file from your web server<br /> wget http://www.myserver.com/wifi_blacklist.txt<br /> module_exists=`lsmod | grep ipt_mac`<br /> if [ -z &quot;$module_exists&quot; ] ; then<br /> insmod ipt_mac<br /> fi<br /> #Deleting the old table<br /> old_mac=`iptables -L | egrep &quot;..:..:..:..:..:..&quot; | sed &quot;s/.*\(..:..:..:..:..:..\).*/\1/&quot;`<br /> for mac in $old_mac ; do<br /> iptables -D FORWARD -p tcp -m mac --mac-source $mac -j REJECT --reject-with tcp-reset<br /> done<br /> #Adding the table again<br /> for mac in `cat /jffs/wifi_blacklist.txt` ; do<br /> iptables -I FORWARD -p tcp -m mac --mac-source $mac -j REJECT --reject-with tcp-reset<br /> done<br /> &lt;/pre&gt;<br /> <br /> <br /> <br /> <br /> ==White Listing==<br /> <br /> If you want to create a white list to block access by default but allow certain traffic through, then you can use this script to do it. Remove any junk comment lines beginning with # to save nvram space. Discuss [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588 here].<br /> <br /> &lt;pre&gt;<br /> # IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588<br /> # Version 4. Please increment version number with subsequent modifications. GeeTek.<br /> <br /> # Set up the chain<br /> iptables -N wanout<br /> iptables -I INPUT -i `nvram get lan_ifname` -j wanout<br /> iptables -I FORWARD -i `nvram get lan_ifname` -j wanout<br /> <br /> # Create whitelist 'function' script<br /> WOUT=&quot;/tmp/wanout&quot;<br /> echo 'iptables -I wanout -j ACCEPT' &gt; $WOUT<br /> chmod 777 $WOUT<br /> <br /> # Exempt Machine MAC<br /> # load xt_mac instead of ipt_mac on k2.6 builds<br /> insmod ipt_mac<br /> $WOUT '-m mac --mac-source 00:30:18:A9:A9:C6'<br /> <br /> # Exempt Machine IP<br /> $WOUT '-s 192.168.1.2'<br /> <br /> # Allow everyone access to these sites<br /> $WOUT '-d www.google.com'<br /> $WOUT '-d www.yahoo.com'<br /> $WOUT '-d www.dd-wrt.com'<br /> <br /> # Allow everyone access to these IP Addresses<br /> $WOUT '-d 74.125.67.100'<br /> $WOUT '-d 74.125.127.100'<br /> $WOUT '-d 74.125.45.100'<br /> $WOUT '-d 209.131.36.158'<br /> <br /> #Allow everyone access to specific destination ports<br /> $WOUT '-p udp --dport 8000'<br /> $WOUT '-p tcp --dport 80'<br /> <br /> <br /> # Everything else gets blocked<br /> iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable<br /> &lt;/pre&gt;<br /> <br /> http://www.dd-wrt.com/wiki/index.php/Ad_blocking<br /> <br /> <br /> [[Category:Traffic moderation]]</div> Sash