Blocking URLs/IPs - Revision history http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&action=history Revision history for this page on the wiki en MediaWiki 1.10.1 Fri, 29 Mar 2024 05:47:28 GMT Ian5142: /* Block URLs with an Automatically Downloaded Host File */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=52970&oldid=prev <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 15:08, 13 November 2017</td> </tr> <tr><td colspan="2" align="left"><strong>Line 2:</strong></td> <td colspan="2" align="left"><strong>Line 2:</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;"><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;"><ins style="color: red; font-weight: bold; text-decoration: none;">Depreciated</ins>, </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</del>, <del style="color: red; font-weight: bold; text-decoration: none;">which is below this one. This one is much shorter, but does even more checking than the other one.</del></td><td>+</td><td style="background: #cfc; font-size: smaller;"><ins style="color: red; font-weight: bold; text-decoration: none;">* See </ins>[<ins style="color: red; font-weight: bold; text-decoration: none;">https</ins>://www.<ins style="color: red; font-weight: bold; text-decoration: none;">dd</ins>-<ins style="color: red; font-weight: bold; text-decoration: none;">wrt</ins>.<ins style="color: red; font-weight: bold; text-decoration: none;">com</ins>/<ins style="color: red; font-weight: bold; text-decoration: none;">wiki</ins>/<ins style="color: red; font-weight: bold; text-decoration: none;">index</ins>.<ins style="color: red; font-weight: bold; text-decoration: none;">php</ins>/<ins style="color: red; font-weight: bold; text-decoration: none;">Access_Restrictions</ins>#<ins style="color: red; font-weight: bold; text-decoration: none;">Filtering_Services</ins>.<ins style="color: red; font-weight: bold; text-decoration: none;">2FURLs</ins>.<ins style="color: red; font-weight: bold; text-decoration: none;">2FKeywords Access Restrictions</ins>]</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</del>[ <del style="color: red; font-weight: bold; text-decoration: none;">\$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;">Braian87b - Edit Note : 2013-02-03 The URL actually redirects to: http://winhelp2002.mvps.org/hosts.txt you could use it instead.</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 see the &quot;/tmp/dlhosts&quot; filepath? well you need to add that as &quot;addn-hosts=/tmp/dlhosts&quot; (without quotes) to &quot;Additional DNSMasq Options&quot; textbox and enable the three &quot;DNSMasq&quot;, &quot;Local DNS&quot;, &quot;No DNS Rebind&quot; checkboxes.</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;">Or you can add this line (it will add the addn-hosts setting to dnsmasq.conf 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;">&lt;pre&gt;grep addn-hosts /tmp/dnsmasq.conf || echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt; /tmp/dnsmasq.conf&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;">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</del>://www.<del style="color: red; font-weight: bold; text-decoration: none;">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 </del>-<del style="color: red; font-weight: bold; text-decoration: none;">O - http://www</del>.<del style="color: red; font-weight: bold; text-decoration: none;">mvps.org</del>/<del style="color: red; font-weight: bold; text-decoration: none;">winhelp2002</del>/<del style="color: red; font-weight: bold; text-decoration: none;">hosts</del>.<del style="color: red; font-weight: bold; text-decoration: none;">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</del>/<del style="color: red; font-weight: bold; text-decoration: none;">127.0.0.1/0.0.0.0/g; s/[[:space:]]*</del>#.<del style="color: red; font-weight: bold; text-decoration: none;">*$//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</del>.<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: #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 not 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 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.</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 to 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</del>] <del style="color: red; font-weight: bold; text-decoration: none;">that deals with the above and more by using the pixelserv method described in the 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 it 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 is 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;">Braian87b - Edit Note : 2013-02-03 In addition you can add this firewall script to Intercept all DNS requests to dnsmasq even if someone in network has manual added their own DNS addresses in their Device (PC, Laptop, Smart Phone, etc...).</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;"># Intercept &amp; Force all br0 DNS Requests to Router's DNS </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 -t nat -A PREROUTING -i br0 -p udp --dport 53 -j DNAT --to $(nvram get lan_ipaddr)</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 -t nat -A PREROUTING -i br0 -p tcp --dport 53 -j DNAT --to $(nvram get lan_ipaddr)</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: #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> Mon, 13 Nov 2017 15:08:43 GMT Ian5142 http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Jackykoning: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=45157&oldid=prev <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 14:54, 14 June 2013</td> </tr> <tr><td colspan="2" align="left"><strong>Line 188:</strong></td> <td colspan="2" align="left"><strong>Line 188:</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;"># Everything else gets blocked</td><td> </td><td style="background: #eee; font-size: smaller;"># Everything else gets blocked</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</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;"></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;">#modified script to work from (at least) build 21286. and decreasing required nvram space. (by jackykoning)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">#IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">#This Wiki Page http://www.dd-wrt.com/wiki/index.php/Blocking_URLs/IPs#White_Listing</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">#Version 6. Please increment version number with subsequent modifications. GeeTek.</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;">#Set up the chain</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -N wanout</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I INPUT -i `nvram get lan_ifname` -j wanout</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I FORWARD -i `nvram get lan_ifname` -j wanout</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;">#Create whitelist 'function' script</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">WOUT='iptables -I wanout -j ACCEPT'</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">MAC='-m mac --mac-source'</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;"># Exempt Machine MAC</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT $MAC 00:30:18:A9:A9:C6</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;">#Exempt Machine IP</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -s 192.168.1.2</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;">#Allow everyone access to these sites (DNS lookup only happens once when rule is inserted and stays that single IP)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d www.google.com</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d www.yahoo.com</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d www.dd-wrt.com</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;">#Allow everyone access to these IP addresses/netmask</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d 74.125.67.100</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d 74.125.127.100</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d 74.125.45.100/24</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -d 209.131.36.158/29</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;">#Allow everyone access to specific destination ports</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">$WOUT -p udp --dport 8000</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;">#Everything else gets blocked</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</td><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</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> </table> Fri, 14 Jun 2013 14:54:16 GMT Jackykoning http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Braian87b: Added more info after a fews hours reading and dealing in internet. http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=44408&oldid=prev <p>Added more info after a fews hours reading and dealing in internet.</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 23:45, 3 February 2013</td> </tr> <tr><td colspan="2" align="left"><strong>Line 13:</strong></td> <td colspan="2" align="left"><strong>Line 13:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">sh /tmp/wh &amp;</td><td> </td><td style="background: #eee; font-size: smaller;">sh /tmp/wh &amp;</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">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">Braian87b - Edit Note : 2013-02-03 The URL actually redirects to: http://winhelp2002.mvps.org/hosts.txt you could use it instead.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">You see the &quot;/tmp/dlhosts&quot; filepath? well you need to add that as &quot;addn-hosts=/tmp/dlhosts&quot; (without quotes) to &quot;Additional DNSMasq Options&quot; textbox and enable the three &quot;DNSMasq&quot;, &quot;Local DNS&quot;, &quot;No DNS Rebind&quot; checkboxes.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">Or you can add this line (it will add the addn-hosts setting to dnsmasq.conf file)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">&lt;pre&gt;grep addn-hosts /tmp/dnsmasq.conf || echo &quot;addn-hosts=/tmp/hosts0&quot; &gt;&gt; /tmp/dnsmasq.conf&lt;/pre&gt;</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;">IMHO the following script is deprecated, but I left it for comparison.</td><td> </td><td style="background: #eee; font-size: smaller;">IMHO the following script is deprecated, but I left it for comparison.</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 colspan="2" align="left"><strong>Line 72:</strong></td> <td colspan="2" align="left"><strong>Line 77:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</td><td> </td><td style="background: #eee; font-size: smaller;"> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf</td></tr> <tr><td> </td><td style="background: #eee; 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><td> </td><td style="background: #eee; 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 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;">Braian87b - Edit Note : 2013-02-03 In addition you can add this firewall script to Intercept all DNS requests to dnsmasq even if someone in network has manual added their own DNS addresses in their Device (PC, Laptop, Smart Phone, etc...).</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;"># Intercept &amp; Force all br0 DNS Requests to Router's DNS </td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -t nat -A PREROUTING -i br0 -p udp --dport 53 -j DNAT --to $(nvram get lan_ipaddr)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -t nat -A PREROUTING -i br0 -p tcp --dport 53 -j DNAT --to $(nvram get lan_ipaddr)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">&lt;/pre&gt;</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> Sun, 03 Feb 2013 23:45:54 GMT Braian87b http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Geetek: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=43937&oldid=prev <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 17:30, 27 October 2012</td> </tr> <tr><td colspan="2" align="left"><strong>Line 172:</strong></td> <td colspan="2" align="left"><strong>Line 172:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -d 7.0.0.0/8 -j ACCEPT </td><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -d 7.0.0.0/8 -j ACCEPT </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 specific destination ports <del style="color: red; font-weight: bold; text-decoration: none;">( Not working on Shibby / Asus RT-N12 )</del></td><td>+</td><td style="background: #cfc; font-size: smaller;">#Allow everyone access to specific destination ports</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -i `nvram get lan_ifname` -p udp --dport 24500 -j ACCEPT</td><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -i `nvram get lan_ifname` -p udp --dport 24500 -j ACCEPT</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> </table> Sat, 27 Oct 2012 17:30:33 GMT Geetek http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Geetek: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=43936&oldid=prev <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 17:16, 27 October 2012</td> </tr> <tr><td colspan="2" align="left"><strong>Line 177:</strong></td> <td colspan="2" align="left"><strong>Line 177:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"># Everything else gets blocked</td><td> </td><td style="background: #eee; font-size: smaller;"># Everything else gets blocked</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</td><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">&lt;/pre&gt;</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;">http://www.dd-wrt.com/wiki/index.php/Ad_blocking</td><td> </td><td style="background: #eee; font-size: smaller;">http://www.dd-wrt.com/wiki/index.php/Ad_blocking</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;">&lt;/pre&gt;</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;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Traffic moderation]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Traffic moderation]]</td></tr> </table> Sat, 27 Oct 2012 17:16:24 GMT Geetek http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Geetek: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=43935&oldid=prev <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 17:15, 27 October 2012</td> </tr> <tr><td colspan="2" align="left"><strong>Line 141:</strong></td> <td colspan="2" align="left"><strong>Line 141:</strong></td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</td><td> </td><td style="background: #eee; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</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">&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;">&lt;pre&gt;</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"># IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"># Version 1.1 for older chipsets and/or experimental firmware builds. Please freeze this version. GeeTek.</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"># URL for this Wiki Page http://www.dd-wrt.com/wiki/index.php/Blocking_URLs/IPs#White_Listing</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;"># Set up the chain </td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -N wanout </td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I FORWARD -i `nvram get lan_ifname` -j wanout </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;"># Exempt Machine MAC</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -m mac --mac-source 00:30:18:A9:A9:C6 -j ACCEPT</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;"># Exempt Machine IP</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -s 192.168.1.2 -j ACCEPT</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;"># Allow everyone access to these sites (DNS lookup only happens once when rule is inserted and stays that single IP)</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -d www.google.com -j ACCEPT </td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -d www.yahoo.com -j ACCEPT</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -d www.dd-wrt.com -j ACCEPT</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;"># Allow everyone access to these IP Addresses </td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -d 74.125.45.100 -j ACCEPT</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -I wanout -d 8.8.8.8 -j ACCEPT</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;"># Allow everyone access to these IP Address ranges</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -A wanout -m iprange --dst-range 4.1.2.3-4.5.6.7 -j ACCEPT</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;"># Allow everyone access to these Subnets</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -A wanout -d 7.0.0.0/8 -j ACCEPT </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;">#Allow everyone access to specific destination ports ( Not working on Shibby / Asus RT-N12 )</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -A wanout -i `nvram get lan_ifname` -p udp --dport 24500 -j ACCEPT</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;"># Everything else gets blocked</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;">iptables -A wanout -j REJECT --reject-with icmp-proto-unreachable</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;">http://www.dd-wrt.com/wiki/index.php/Ad_blocking</td><td> </td><td style="background: #eee; font-size: smaller;">http://www.dd-wrt.com/wiki/index.php/Ad_blocking</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;">&lt;/pre&gt;</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: #eee; font-size: smaller;">[[Category:Traffic moderation]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Traffic moderation]]</td></tr> </table> Sat, 27 Oct 2012 17:15:20 GMT Geetek http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Geetek: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=41579&oldid=prev <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 12:55, 13 December 2011</td> </tr> <tr><td colspan="2" align="left"><strong>Line 103:</strong></td> <td colspan="2" align="left"><strong>Line 103:</strong></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: #eee; font-size: smaller;"># IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td><td> </td><td style="background: #eee; font-size: smaller;"># IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td></tr> <tr><td colspan="2">&nbsp;</td><td>+</td><td style="background: #cfc; font-size: smaller;"># This Wiki Page http://www.dd-wrt.com/wiki/index.php/Blocking_URLs/IPs#White_Listing</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"># Version 5. Please increment version number with subsequent modifications. GeeTek.</td><td> </td><td style="background: #eee; font-size: smaller;"># Version 5. Please increment version number with subsequent modifications. GeeTek.</td></tr> <tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr> </table> Tue, 13 Dec 2011 12:55:01 GMT Geetek http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Geetek: /* White Listing */ http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=41578&oldid=prev <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 12:54, 13 December 2011</td> </tr> <tr><td colspan="2" align="left"><strong>Line 103:</strong></td> <td colspan="2" align="left"><strong>Line 103:</strong></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: #eee; font-size: smaller;"># IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td><td> </td><td style="background: #eee; font-size: smaller;"># IP Tables White Listing script by phuzi0n -Tek @ http://www.dd-wrt.com/phpBB2/viewtopic.php?t=56588</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;"># Version <del style="color: red; font-weight: bold; text-decoration: none;">4</del>. Please increment version number with subsequent modifications. GeeTek.</td><td>+</td><td style="background: #cfc; font-size: smaller;"># Version <ins style="color: red; font-weight: bold; text-decoration: none;">5</ins>. Please increment version number with subsequent modifications. GeeTek.</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;"># Set up the chain</td><td> </td><td style="background: #eee; font-size: smaller;"># Set up the chain</td></tr> <tr><td colspan="2" align="left"><strong>Line 136:</strong></td> <td colspan="2" align="left"><strong>Line 136:</strong></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> <tr><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-p udp --dport 8000'</td><td> </td><td style="background: #eee; font-size: smaller;">$WOUT '-p udp --dport 8000'</td></tr> <tr><td>-</td><td style="background: #ffa; font-size: smaller;">$WOUT '-p tcp --dport 80'</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;"># Everything else gets blocked</td><td> </td><td style="background: #eee; font-size: smaller;"># Everything else gets blocked</td></tr> </table> Tue, 13 Dec 2011 12:54:07 GMT Geetek http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs Donny: New page: __TOC__ ==Block URLs with an Automatically Downloaded Host File== I have kept the original script, which is below this one. This one is much shorter, but does even more checking than the... http://wiki.dd-wrt.com/wiki/index.php?title=Blocking_URLs/IPs&diff=40796&oldid=prev <p>New page: __TOC__ ==Block URLs with an Automatically Downloaded Host File== I have kept the original script, which is below this one. This one is much shorter, but does even more checking than the...</p> <p><b>New page</b></p><div>__TOC__<br /> <br /> <br /> ==Block URLs with an Automatically Downloaded Host File==<br /> 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.<br /> It tries to download the file at least 5 times after startup<br /> An even better solution is offered in my set of optware scripts where it will also run pixelserv on the router.<br /> I didn't like the cronjob approach because the list is quite static.<br /> <br /> frater<br /> &lt;pre&gt;_rogue=127.0.0.1<br /> 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<br /> sh /tmp/wh &amp;<br /> &lt;/pre&gt;<br /> IMHO the following script is deprecated, but I left it for comparison.<br /> <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; &quot; &gt;&gt;/tmp/dnsmasq.conf<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 -HUP 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 /> 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;<br /> grep addn-hosts /tmp/dnsmasq.conf ||<br /> echo &quot; &quot; &gt;&gt;/tmp/dnsmasq.conf<br /> made sure that the dnsmasq.conf addition went on a new line. Script might be made leaner through \n usage but that is untested.<br /> <br /> ==Global Blacklisting per MAC==<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 /> ==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 (DNS lookup only happens once when rule is inserted and stays that single IP)<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/netmask<br /> $WOUT '-d 74.125.67.100'<br /> $WOUT '-d 74.125.127.100'<br /> $WOUT '-d 74.125.45.100/24'<br /> $WOUT '-d 209.131.36.158/29'<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> Tue, 05 Jul 2011 11:48:51 GMT Donny http://wiki.dd-wrt.com/wiki/index.php/Talk:Blocking_URLs/IPs