ad-blocking with DD-WRT revisited (simple)

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13, 14  Next
Author Message
makaveli101
DD-WRT Novice


Joined: 17 May 2010
Posts: 44

PostPosted: Wed May 30, 2012 19:46    Post subject: Reply with quote
http://www.dd-wrt.com/wiki/index.php/Ad_blocking

administration>commands>save startup

Code:

#!/bin/sh
logger WAN up script executing
sleep 2
if test ! -s /tmp/dlhosts
then
   cat >/tmp/dlhosts <<"EOF"
logger Downloading http://www.mvps.org/winhelp2002/hosts.txt
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 |
   sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |
   grep -v localhost | tr ' ' '\t' |
   tr -s '\t' | tr -d '\015' | sort -u >/tmp/hosts0
grep addn-hosts /tmp/dnsmasq.conf ||
   echo "addn-hosts=/tmp/hosts0" >>/tmp/dnsmasq.conf
logger Restarting dnsmasq
killall dnsmasq
dnsmasq --conf-file=/tmp/dnsmasq.conf
EOF
   chmod 777 /tmp/dlhosts
   /tmp/dlhosts
fi
grep -q '/tmp/dlhosts' /tmp/crontab ||
   echo "45 23 * * 5 root /tmp/dlhosts" >>/tmp/crontab


doesn't seem to be working for me on dir-615 Sad
Sponsor
toXiclabs
DD-WRT Novice


Joined: 12 Aug 2012
Posts: 3

PostPosted: Mon Aug 13, 2012 15:10    Post subject: Reply with quote
is it possible to combine easy list from the adblock plugin and the hosts together?
https://easylist.adblockplus.org/en/

thanks
osos
DD-WRT Novice


Joined: 31 Jul 2008
Posts: 8

PostPosted: Wed Aug 15, 2012 15:25    Post subject: Reply with quote
If you want to combine the mvps list with the yoyo list from http://pgl.yoyo.org/as/

Also added preliminary check for internet connection.

Code:
#!/bin/sh
logger WAN up script executing
sleep 2
if test ! -s /tmp/dlhosts
then
   cat >/tmp/dlhosts <<"EOF"

# Uncomment to enable waiting for internet connection to come up
#while ! ping www.google.com -c 1 > /dev/null ; do
#   logger "waiting for the internet connection to come up"
#   sleep 5
#done

logger Downloading http://www.mvps.org/winhelp2002/hosts.txt
wget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 |
   sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |
   grep -v localhost | tr ' ' '\t' |
   tr -s '\t' | tr -d '\015' | sort -u >/tmp/hosts0
wget -O - "http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" | grep 127.0.0.1 |
   sed '2,$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' |
   grep -v localhost | tr ' ' '\t' |
   tr -s '\t' | tr -d '\015' | sort -u >>/tmp/hosts0
grep addn-hosts /tmp/dnsmasq.conf ||
   echo "addn-hosts=/tmp/hosts0" >>/tmp/dnsmasq.conf
logger Restarting dnsmasq
killall dnsmasq
dnsmasq --conf-file=/tmp/dnsmasq.conf
EOF
   chmod 777 /tmp/dlhosts
   /tmp/dlhosts
fi
grep -q '/tmp/dlhosts' /tmp/crontab ||
   echo "45 23 * * 5 root /tmp/dlhosts" >>/tmp/crontab
Oldschool2012
DD-WRT Novice


Joined: 29 Aug 2012
Posts: 4

PostPosted: Wed Aug 29, 2012 20:06    Post subject: Reply with quote
calee4nyaboy wrote:
MKruer wrote:
Donny:
This should run on all builds.
What is does is takes any request from a system and checks it against the list of URLS. If the URL matches, it returns the IP 0.0.0.0 instead of passing it though and getting the ad.


This is incorrect information. It does NOT run on micro builds. Runs on mini or standard.


The Wiki has been updated with new instructions on ad-blocking with the DD-WRT Micro build.

http://www.dd-wrt.com/wiki/index.php/Ad_blocking#Ad_Blocking_with_Micro_build

Sorry for the late bump, but I came across this posting while searching for information on Micro build ad-blocking. (I'm stuck with a WRT54Gv2.)
Pamela
DD-WRT Novice


Joined: 21 May 2010
Posts: 35

PostPosted: Wed May 08, 2013 19:09    Post subject: Reply with quote
Hello Everyone,

Is there a command I can use via terminal to verify the Ad blocking script is working?

I am not good at terminal so I will need specific instructions.
Got my thinking/learning hat on so I 'm ready to get some Ad blocking done.
Smile

T.I.A.
mac913
DD-WRT Guru


Joined: 02 May 2008
Posts: 1375
Location: Canada

PostPosted: Thu May 09, 2013 1:16    Post subject: Reply with quote
If you go to the 1st page it describes how to test it.
_________________
Home Network on Telus PureFibre - Wired GigaBit Backbone
| 2x DNSCrypt-Proxy V2 | DHCPv4/v6 via DNSMasq | Telus-IPv6 |
| USB Storage - Scripts Only | 7x VLANs/BRs | WiFi 5x SSIDs |
| 3x OpenVPN-Clients | QoS | SSH | Entware | YAMon3 | Ad-Blocking |

R7800 Gateway & VPN1 - KONGAT 39855M Release 2019-05-25
R7800 WiFi & VPN2 & VPN3 - KONGAT 39855M Release 2019-05-25

______________________
YAMon 3.4 | Ad-Blocking for DD-WRT | DNSCrypt-Proxy V2
DD-WRT Beta Builds | KONG Builds
CloneVince's copies of Kong's Arm Firmware
Pamela
DD-WRT Novice


Joined: 21 May 2010
Posts: 35

PostPosted: Thu May 09, 2013 1:23    Post subject: Reply with quote
Thank you mac913 Smile
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 435

PostPosted: Sun Dec 08, 2013 18:37    Post subject: No Longer Working With Lastest Update of MVPS Hosts Reply with quote
I have verified that with the newest update of the mvps hosts file, my to routers no longer block ads.

I have a WRT310N and a WZR-600DHP and neither are doing any redirects. I have not changed a thing. I did notice some new tags in the hosts file that I have not seen before with reference to IPV6.

I have been using this for years without fault until now. Running the mvps hosts file locally works fine.

Any thoughts frater?
tilo
DD-WRT Novice


Joined: 22 Jun 2010
Posts: 13

PostPosted: Sun Dec 08, 2013 23:45    Post subject: Re: No Longer Working With Lastest Update of MVPS Hosts Reply with quote
RCShadows wrote:
I have verified that with the newest update of the mvps hosts file, my to routers no longer block ads.

I have a WRT310N and a WZR-600DHP and neither are doing any redirects. I have not changed a thing. I did notice some new tags in the hosts file that I have not seen before with reference to IPV6.

I have been using this for years without fault until now. Running the mvps hosts file locally works fine.

Any thoughts frater?


they change the format look here: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=786012
RCShadows
DD-WRT User


Joined: 17 Aug 2008
Posts: 435

PostPosted: Sun Dec 08, 2013 23:48    Post subject: Reply with quote
Frater,

Yep. I changed the Startup script and replaced 127.0.0.1 to 0.0.0.0 in two places and it works now. I posted another thread with my change if you want to have a look. I hope it is correct but seems to have solved the problem.
selenia
DD-WRT Novice


Joined: 16 Jul 2014
Posts: 2

PostPosted: Wed Jul 16, 2014 6:19    Post subject: Thank you Reply with quote
Thank you sir. I updated my DD-WRT build due to some old bugs I was sick and tired of. The new build is awesome and bug-free, but the trade-off was lack of flash space to make a jffs partition like the small one I had before(need big build for features I value like IPv6 support). Combined with a previously tested compile script to compile pixelserv on the fly and this script, my router is happily blocking ads with pixelserv, despite having no jffs partition available. Was considering cifs but I don't want my PC to have to run when it does not have to for any other purpose.
nashton
DD-WRT Novice


Joined: 06 Jul 2014
Posts: 23

PostPosted: Wed Jul 16, 2014 8:34    Post subject: Reply with quote
I'm a bit lost - where are the current, working scripts? I am running a different setup than what I've seen in this thread (you can find what I'm using, based on Matthew Headlee's buildhosts script, herehttp://www.dd-wrt.com/phpBB2/viewtopic.php?t=257686&sid=cdc60d04778f675fac7393c5c5df5369)

The size of the files that are produced seems to cause a problem in sed - I'm having to run this on a local PC and then have the router use wget.

But I digress, I like this simple method, excepting that I want to have a set of these ad blocking sites' host files compiled.
selenia
DD-WRT Novice


Joined: 16 Jul 2014
Posts: 2

PostPosted: Mon Jul 28, 2014 7:03    Post subject: This works very well! Reply with quote
I took the man's original format and modded it. I have not enough room for jffs on my lowly E2000 but plenty of RAM. His method does work on this shiny new build, unlike what's in the wiki. Of course, if you want to exactly copy me, grab the custom.txt from this thread https://secure.dd-wrt.com/phpBB2/viewtopic.php?p=434120&highlight= and save it as a custom script.

Replace anywhere I put 192.168.1.1 with the IP you wish to redirect to. In my case, pixelserv compiled by that custom.txt when router boots. Uncheck http and https for the router admin if you run pixelserv or it will interfere.

You can put httpd -p 81 after the killall httpd and sleep 1 if you want to have the GUI. I personally admin over ssh and leave off the heavy GUI to let it do what it does best-routing. I call the GUI as needed by going in with ssh and typing httpd -p 81 More secure I feel as I only use RSA keys for ssh and no password authentication is possible for getting in to my router. Just make sure you can ssh in first lol.

For your startup(with pixelserv)

while ! ping www.google.com -c 1 > /dev/null ; do
logger "waiting for the internet connection to come up"
sleep 5
done
while [ ! -e "/tmp/custom.sh" ]; do
sleep 1 # wait till /tmp/custom.sh gets generated
done
/tmp/custom.sh
killall httpd
sleep 1
/tmp/pixelserv
echo -e "#!/bin/sh\nkillall pixelserv\nsleep 1\n/tmp/pixelserv" > /tmp/pixelserv.sh
chmod +x /tmp/pixelserv.sh
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n\twget -q -O - http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://adblock.gjtech.net/?format=hostfile | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://www.malwaredomainlist.com/hostslist/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://someonewhocares.org/hosts/zero/hosts | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

Startup (Without pixelserv)
while ! ping www.google.com -c 1 > /dev/null ; do
logger "waiting for the internet connection to come up"
sleep 5
done
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n\twget -q -O - http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://adblock.gjtech.net/?format=hostfile | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://www.malwaredomainlist.com/hostslist/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://someonewhocares.org/hosts/zero/hosts | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

In your DNSMasq config under Services, put addn-hosts=/tmp/dlhosts

Now if you run pixelserv, it will hang a lot, at least for my router though there have been other reports too. So in cron, put * * * * * root /bin/sh /tmp/pixelserv.sh as my quick and dirty fix.

Reboot and watch the magic. Give it a few minutes then try some domains in the lists.

Yes, I really hate ads and probably some overlap in all these files. Still not as overkill as the hphosts file, which likely would only fit in a 64MB model comfortably. Hope this helps Smile
FrancYescO
DD-WRT Novice


Joined: 22 Oct 2013
Posts: 30

PostPosted: Mon Mar 30, 2015 23:53    Post subject: Re: This works very well! Reply with quote
selenia wrote:
I took the man's original format and modded it. I have not enough room for jffs on my lowly E2000 but plenty of RAM. His method does work on this shiny new build, unlike what's in the wiki. Of course, if you want to exactly copy me, grab the custom.txt from this thread https://secure.dd-wrt.com/phpBB2/viewtopic.php?p=434120&highlight= and save it as a custom script.

Replace anywhere I put 192.168.1.1 with the IP you wish to redirect to. In my case, pixelserv compiled by that custom.txt when router boots. Uncheck http and https for the router admin if you run pixelserv or it will interfere.

You can put httpd -p 81 after the killall httpd and sleep 1 if you want to have the GUI. I personally admin over ssh and leave off the heavy GUI to let it do what it does best-routing. I call the GUI as needed by going in with ssh and typing httpd -p 81 More secure I feel as I only use RSA keys for ssh and no password authentication is possible for getting in to my router. Just make sure you can ssh in first lol.

For your startup(with pixelserv)

while ! ping www.google.com -c 1 > /dev/null ; do
logger "waiting for the internet connection to come up"
sleep 5
done
while [ ! -e "/tmp/custom.sh" ]; do
sleep 1 # wait till /tmp/custom.sh gets generated
done
/tmp/custom.sh
killall httpd
sleep 1
/tmp/pixelserv
echo -e "#!/bin/sh\nkillall pixelserv\nsleep 1\n/tmp/pixelserv" > /tmp/pixelserv.sh
chmod +x /tmp/pixelserv.sh
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n\twget -q -O - http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://adblock.gjtech.net/?format=hostfile | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://www.malwaredomainlist.com/hostslist/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://someonewhocares.org/hosts/zero/hosts | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

Startup (Without pixelserv)
while ! ping www.google.com -c 1 > /dev/null ; do
logger "waiting for the internet connection to come up"
sleep 5
done
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n\twget -q -O - http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://adblock.gjtech.net/?format=hostfile | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://www.malwaredomainlist.com/hostslist/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n\twget -q -O - http://someonewhocares.org/hosts/zero/hosts | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"192.168.1.1\\\t\"\$2}' | tr -d '\\\015' >>/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

In your DNSMasq config under Services, put addn-hosts=/tmp/dlhosts

Now if you run pixelserv, it will hang a lot, at least for my router though there have been other reports too. So in cron, put * * * * * root /bin/sh /tmp/pixelserv.sh as my quick and dirty fix.

Reboot and watch the magic. Give it a few minutes then try some domains in the lists.

Yes, I really hate ads and probably some overlap in all these files. Still not as overkill as the hphosts file, which likely would only fit in a 64MB model comfortably. Hope this helps Smile

awesame script 1 missing thing .. remove duplicate from generated dlhosts file Smile
FrancYescO
DD-WRT Novice


Joined: 22 Oct 2013
Posts: 30

PostPosted: Wed Apr 01, 2015 21:32    Post subject: Reply with quote
My "revision"

Code:
while ! ping 8.8.8.8 -c 1 > /dev/null ; do
logger "waiting for the internet connection to come up for starting ad-blocking script..."
sleep 5
done
echo -e "#!/bin/sh\n\twget -O - 'http://www.mvps.org/winhelp2002/hosts.txt' 'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&mimetype=plaintext' 'http://adblock.gjtech.net/?format=hostfile' 'http://www.malwaredomainlist.com/hostslist/hosts.txt' 'http://someonewhocares.org/hosts/zero/hosts' | grep -E '127.0.0.1|0.0.0.0' | sed '2,\$s/127.0.0.1/0.0.0.0/g; s/[[:space:]]*#.*$//g;' | grep -v localhost | tr ' ' '\\\t' | tr -s '\\\t' | tr -d '\\\015' | sort -u >/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts.sh
chmod +x /tmp/write_dlhosts.sh
/tmp/write_dlhosts.sh &
Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13, 14  Next Display posts from previous:    Page 10 of 14
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum