Ad-blocking with DD-WRT

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3 ... 17, 18, 19
Author Message
liverpoolatnight
DD-WRT User


Joined: 29 May 2008
Posts: 243
Location: United Kingdom

PostPosted: Wed Feb 10, 2010 13:50    Post subject: Reply with quote
Code:
wget -O - http://hphosts.gt500.org/hosts.txt | grep 127.0.0.1 | sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /etc/hosts
logger "$0: Hosts-file downloaded"

stopservice dnsmasq
startservice dnsmasq
logger "$0: DNSMasq restarted"


NOTE!!!! PUT NOT PUT THIS ON A 4MB ROUTER!!!!

Im using this on my linksys wrt600n v1 Smile


Last edited by liverpoolatnight on Thu Apr 14, 2011 15:33; edited 1 time in total
Sponsor
onemyndseye
DD-WRT Novice


Joined: 01 Aug 2009
Posts: 36

PostPosted: Fri Jun 11, 2010 21:04    Post subject: Reply with quote
Is there any way to make this work when static leases are setup?


Also this works GREAT coupled with pixelserv. Keep in mind that pixelserv takes over port 80 on your router so the ddwrt web admin must be disabled or moved to a alternate port.

I saved pixelserv as /mcc/bin/pixelserv.bin and use a script like this to start pixselserv and move httpd to 8080:
/mmc/bin/pixselserv
Code:

#!/bin/sh

killall -9 pixelserv.bin
HTTP_PORT=8080
if [ `nvram get http_lanport` -eq 80 ] ; then
  nvram set http_lanport=${HTTP_PORT}
  nvram commit
  stopservice httpd
  startservice httpd
fi
pixelserv.bin




The version of pixelserv I am using is a 10k precompiled bin compile and offered by the user mstombs. More info is available here. Anyone interested can also retrieve a copy from my DropBox: http://dl.dropbox.com/u/1397571/pixelserv

It could ofc be retrieve at startup and saved to /tmp by adding something like this to your startup script:
Code:

wget -O /tmp/pixelserv http://dl.dropbox.com/u/1397571/pixelserv

#!/bin/sh

killall -9 pixelserv
HTTP_PORT=8080
if [ `nvram get http_lanport` -eq 80 ] ; then
  nvram set http_lanport=${HTTP_PORT}
  nvram commit
  stopservice httpd
  startservice httpd
fi
/tmp/pixelserv

aviad_ra
DD-WRT User


Joined: 17 Jun 2006
Posts: 103

PostPosted: Fri Jul 16, 2010 19:46    Post subject: Reply with quote
my script is the combination of a lot of suggestions from here and other threads.

i have been using it for some time now, and its working gr8.

if anyone is interested, its detailed on my wiki...
http://hotfortech.wikispaces.com/How+to+remove+advertisements+with+pixelserv+on+DD-WRT
liverpoolatnight
DD-WRT User


Joined: 29 May 2008
Posts: 243
Location: United Kingdom

PostPosted: Tue Apr 12, 2011 12:03    Post subject: linksys WRT54GS v4 under DNSMasq Reply with quote
DNSMasq (This worked on my linksys WRT54GS v4

address=/googlesyndication.com/127.0.0.1
address=/ads.msn.com/127.0.0.1
address=/advertising.microsoft.com/127.0.0.1

and you see it redirects to 127.0.0.1 so edit 127.0.0.1 if you wont redirect to another ip maybe a webserver



dnsmasq Ads Domains

My list of dnsmasq ads


Last edited by liverpoolatnight on Tue Jun 14, 2011 12:54; edited 9 times in total
<Kong>
DD-WRT Guru


Joined: 15 Dec 2010
Posts: 4339
Location: Germany

PostPosted: Tue Apr 12, 2011 13:24    Post subject: Reply with quote
I'm just waiting for someone to hack mvps.org modifying the hosts text, the posted script here is completely insecure. Just modify the downloaded hosts and add the line:

74.125.39.104 microsoft.com # 127.0.0.1

running:

grep 127.0.0.1 | sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//'

will add:

74.125.39.104 microsoft.com

to your hosts file:-)

I can't believe people are blindly downloading a foreign hosts file without simple checks.

_________________
KONG PB's: http://www.desipro.de/ddwrt/
KONG Info: http://tips.desipro.de/
liverpoolatnight
DD-WRT User


Joined: 29 May 2008
Posts: 243
Location: United Kingdom

PostPosted: Tue Apr 12, 2011 16:23    Post subject: Reply with quote
<Kong> wrote:
I'm just waiting for someone to hack mvps.org modifying the hosts text


you have a point there.
facsi
DD-WRT User


Joined: 27 Nov 2010
Posts: 213

PostPosted: Wed May 18, 2011 3:47    Post subject: Reply with quote
Hi guys
I use openDNS and we can add some domains for blocking. But we should pressure opendns to make this idea http://ideabank.opendns.com/story.php?title=allow_to_upload_own_hosts_file_for_domains_blocking_purpose-

Which is upload your own host for domain blocking.
facsi
DD-WRT User


Joined: 27 Nov 2010
Posts: 213

PostPosted: Thu Jun 30, 2011 2:29    Post subject: Reply with quote
Could someone update the code for ad blocking to work with the VPN service?
liverpoolatnight
DD-WRT User


Joined: 29 May 2008
Posts: 243
Location: United Kingdom

PostPosted: Sun Jul 10, 2011 17:14    Post subject: Reply with quote
facsi wrote:
Could someone update the code for ad blocking to work with the VPN service?

what VPN service are you using?

If you have your own VPS / Dedicated server you could try using a squid proxy server to forward the traffic Idea Very Happy

#!/bin/sh
PROXY_IP= VPS / Dedicated Server IP [only use one]
PROXY_PORT=3128
LAN_IP=`nvram get lan_ipaddr`
LAN_NET=$LAN_IP/`nvram get lan_netmask`

iptables -t nat -A PREROUTING -i br0 -s $LAN_NET -d $LAN_NET -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i br0 -s ! $PROXY_IP -p tcp --dport 80 -j DNAT --to $PROXY_IP:$PROXY_PORT
iptables -t nat -I POSTROUTING -o br0 -s $LAN_NET -d $PROXY_IP -p tcp -j SNAT --to $LAN_IP
iptables -I FORWARD -i br0 -o br0 -s $LAN_NET -d $PROXY_IP -p tcp --dport $PROXY_PORT -j ACCEPT
iptables -t nat -I PREROUTING -i br0 -s 192.168.1.8 -j ACCEPT

Replace 192.168.1.8 thats hightlighted to bypass the squid proxy (such as xbox 360 / Wii / Media receivers ) You can use it to add as many exceptions as you like Laughing

http://www.dd-wrt.com/phpBB2/viewtopic.php?t=62222
http://www.dd-wrt.com/wiki/index.php/Transparent_web_proxy

_________________
TP-Link TL-WDR3600 v1 [EU]: r36330 (07/16/18 )
D-Link DIR-615 D2 [EU]: r36330 (07/16/18 )
Mikrotik RB750r2 (OpenWrt 17.01.4)
EE BrightBox 1 aka A4001N (OpenWrt 17.01.4)
Sagemcom FAST@5364 (VDSL2,FTTC (Fibre to the Cabinet) Synced 65/17

Twitter: @francisuk1989
---------------------------------
Found a bug? Report it http://svn.dd-wrt.com
DD-WRT Official FB Group: https://www.facebook.com/groups/493762527744455
as320
DD-WRT Novice


Joined: 14 Dec 2011
Posts: 3

PostPosted: Wed May 02, 2012 13:51    Post subject: Reply with quote
My Solution

Code:
nvram set [b]no_crossdetect=1[/b]
nvram commit
Masterman
DD-WRT Guru


Joined: 24 Aug 2009
Posts: 2070
Location: South Florida

PostPosted: Wed May 02, 2012 18:06    Post subject: Reply with quote
<Kong> wrote:
I'm just waiting for someone to hack mvps.org modifying the hosts text, the posted script here is completely insecure. Just modify the downloaded hosts and add the line:

74.125.39.104 microsoft.com # 127.0.0.1

running:

grep 127.0.0.1 | sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//'

will add:

74.125.39.104 microsoft.com

to your hosts file:-)

I can't believe people are blindly downloading a foreign hosts file without simple checks.



An accepted risk I was living with for awhile, but I've since changed the url in pixelserv to:

http://support.it-mate.co.uk/downloads/HOSTS.txt

From this site:

http://hosts-file.net/?s=Download

Which includes PGP encryption, MD5 and Sha-1 hashing..

Code:
root@None:/opt/etc/pixelserv# ls -altr
total 7704
-rw-r--r--  1 root root       0 Oct 24  2011 hosts.exclude
-rw-r--r--  1 root root     253 Apr 25 01:10 hosts.include
drwxr-xr-x  2 root root    4096 May  2 12:44 .
-rw-r--r--  1 root root 7860147 May  2 12:44 blacks
drwxr-xr-x 13 root root    4096 May  2 14:00 ..
root@None:/opt/etc/pixelserv#



Other than your Privoxy service you integrated into your builds (which is hard to understand), what else would you recommend?

Thanks,

-Masterman

_________________
Optware, the Right Way
Asus RT-AC68U
Asus RT-N66U
Asus RT-N10
Asus RT-N12
Asus RT-N16 x5
Asus WL520gU
Engenious ECB350
Linksys WRT600Nv1.1
Linksys WRT610Nv1
Linksys E2000
Netgear WNDR3300
SonicWall NSA220W
SonicWall TZ215W
SonicWall TZ205W
SonicWall TZ105W
Oldschool2012
DD-WRT Novice


Joined: 29 Aug 2012
Posts: 4

PostPosted: Wed Aug 29, 2012 19:48    Post subject: Re: good ;) Reply with quote
es1013 wrote:
Quote:

If you DON'T have jffs it gets more tricky.....you would need to store your additional hosts somewhere the router DOES have access to and modify the script to grab them after grabbing yours. A dirty version without error checking would be:

rogue=0.0.0.0
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \$1\"\\\t\"\$2}' | sed -e 's/127.0.0.1/$rogue/g' | tr -d '\\\015' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\ntwget -q -O - http://MYFILEHERE >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


Micro doesn't have jffs. Someone in a previous post mentioned that frater's script DOES work in the Mini version. However, most commands in Micro have been stripped - sed, awk, nwget, ntwget, etc..
For the record, here are the commands listed in 2.4sp1 micro:
Code:

BusyBox v1.11.1 (2008-07-27 19:40:27 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

\u@\h:\w\$ help

Built-in commands:
-------------------
. : [ alias bg break cd chdir command continue eval exec exit export false fg getopts hash help jobs kill let local pwd read readonly return set shift source test times trap true type ulimit umask unalias unset wait


I won't hold my breath for a solution. Will probably just try to find a non-neutered router instead.


I added a section to the Wiki with a makeshift solution for transmitting a hosts file into a router with the Micro build. (Sorry for such a late bump, but I'm still using a WRT54Gv2, which only can accommodate Micro, and came to the posting/question while trying to figure this out.)

http://www.dd-wrt.com/wiki/index.php/Ad_blocking#Ad_Blocking_with_Micro_build
ydrol
DD-WRT Novice


Joined: 06 Feb 2011
Posts: 3

PostPosted: Wed Oct 31, 2012 23:59    Post subject: Reply with quote
I'm using a slight modification of the wiki script:

EDITED
Code:

hin='http://www.mvps.org/winhelp2002/hosts.txt'
hout="/tmp/hosts0"
conf="/tmp/dnsmasq.conf"

logger "Downloading $hin to $hout"
rm -f "$hout"

wget -O - "$hin" | sed '/localhost/ d ;
s/127.0.0.1/0.0.0.0/g ;
s/[[:space:]][[:space:]]*/ /g ;
s/ \?#.*// ;
s/ $//' > "$hout"
 
grep addn-hosts "$conf" || echo "addn-hosts=$hout" >>"$conf"
logger Restarting dnsmasq
killall dnsmasq
dnsmasq --conf-file="$conf"


Also the wiki currently says add this to crontab
Code:

* 1 * * * root /tmp/.rc_startup

which *I think* means run every minute from 1:00 to 1:59 ??

I think it is probably best run once a day at some unsociable hour... eg "30 4 * * *"
Goto page Previous  1, 2, 3 ... 17, 18, 19 Display posts from previous:    Page 19 of 19
Post new topic   Reply to topic    DD-WRT 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