Blocking tracking, ad, spyware sites from router

Want to share your OpenWrt / Gargoyle knowledge? Implemented a new feature? Let us know here.

Moderator: Moderators

Post Reply
bouwew
Posts: 30
Joined: Sat Aug 25, 2012 6:24 am

Blocking tracking, ad, spyware sites from router

Post by bouwew »

Would like to bring this to your attention, found it on the OpenWRT forum:

https://forum.openwrt.org/viewtopic.php?id=35023&p=2

Look at the bottom of the page for the latest "version"

Works well on Gargoyle :)

tapper
Moderator
Posts: 1071
Joined: Sun Oct 13, 2013 5:49 pm
Location: Stoke-on-trent UK

Re: Blocking tracking, ad, spyware sites from router

Post by tapper »

this is what i did

block quote
First File: /etc/firewall.user (Make a copy of the file before editing)
Add this 2 lines:
iptables -t nat -I PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
block quote end

Add these lines to the bottom of the file away from everything else if you have anything already in there

4)

phuque99 wrote:
block quote
Add the following line into /etc/config/dhcp, under the section "config dnsmasq":
block quote end

(modified to make it permanent on reboot)

list addnhosts '/etc/block.hosts'

5)Create the file /etc/adblock.sh and copy and paste this into it (modified version of phuque99's script)

#Script to grab and sort a list of adservers and malware

#Delete the old block.hosts to make room for the updates
rm -f /etc/block.hosts

#Download and process the files needed to make the lists
wget -qO- http://www.mvps.org/winhelp2002/hosts.txt|grep "^127.0.0.1" > /tmp/block.build.list
wget -qO- http://www.malwaredomainlist.com/hostsl ... s.txt|grep "^127.0.0.1" >> /tmp/block.build.list
wget -qO- http://updates.it-mate.co.uk/hphosts/ad ... s.asp|grep "^127.0.0.1" >> /tmp/block.build.list

#Sort the lists
sort /tmp/block.build.list|uniq -u >/tmp/block.sorted

#Remove the carriage return ^M on windows created files
sed -e 's/\r//g' /tmp/block.sorted > /etc/block.hosts

#Delete files used to build list to free up the limited space
rm -f /tmp/block.sorted
rm -f /tmp/block.build.list

#Restart dnsmasq
/etc/init.d/dnsmasq restart

exit 0


This script automates the whole process and if you read the remarks you'll see how it works. It also tidies up after itself to save space. If you wish
to add more host file sources the format is:

wget -qO- <http: online source here minus the <> >|grep "^127.0.0.1" >> /tmp/block.build.list

6) From the command line type

chmod +x /etc/adblock.sh

7) To generate the file for the first time and make sure you have no errors type in

sh /etc/adblock.sh

If you find errors make sure you've copied and pasted everything correctly and so on.

8) Two ways to schedule this so I'm going to show the easy way from luci:

a) Go to System>Scheduled Tasks.

b)Copy and paste the following into it then click on Submit on the bottom

00 4 * * 0,3 sh /etc/adblock.sh

This automates the updates of your block.hosts to be run by cron every Sunday and Wednesday at 4am which should be plenty enough for most needs.

I used winSCP to edit my files and i put the cron rule in cron root
Linksys WRT1900AC V2 Gargoyle 1.11
Linksys WRT3200ACM OpenWrt Snapshot

netweaver
Posts: 8
Joined: Wed Jun 12, 2013 6:27 am

Re: Blocking tracking, ad, spyware sites from router

Post by netweaver »

Hi,
This would make a verrry nice addition to standard Gargoyle, if there is a good webinterface for enable/disable and maintenance of the whitelist.
Everything to make the general browsing experience faster and 'safer' is good, with possibility to allow the odd server in a whitelist.

thanks for bringing it up and maybe it's getting picked up by Eric for inclusion in a next version.

sheriffy
Posts: 13
Joined: Thu Oct 17, 2013 2:18 pm

Re: Blocking tracking, ad, spyware sites from router

Post by sheriffy »

I have had this running on gargoyle and dd-wrt but it is not perfect.
Some websites do not load, they seem to hang and if you refresh they load ok (without the ads of course)
For example http://www.nu.nl without the adblock loads ok everytime you click the different links on it. With the adblock enbaled pages often do not load, you have to refresh to get the page on your screen.
I have been trying to get adblocking to work with pixelserv or privoxy but cannot get it to work. There are lots of pages about these adblock solutions but none seem to work for gargoyle.

teffalump
Posts: 2
Joined: Fri Nov 08, 2013 7:05 pm

Re: Blocking tracking, ad, spyware sites from router

Post by teffalump »

I agree, some sites have problems. Hopefully the whitelist will help with some of that, but, definitely, still are problems: kwakd, privoxy, pixelserv, etc do help (I run kwakd setup on my laptop). For example, someone was browsing on their tablet and found that thumbnails weren't appearing in some shopping app. Lo and behold, it was that a248.e.akamai.net url. Whitelisted and it worked, but some other sites are just temperamental, as you noted - some hang, refuse to load, etc. I was thinking of writing a plugin. I'd need some help definitely, lol. =-)

Hercules
Posts: 23
Joined: Sun Sep 29, 2013 6:58 pm

Re: Blocking tracking, ad, spyware sites from router

Post by Hercules »

Hi Guys,

tefflump firstly thanks for your efforts over on gist. I have that all up and working. However, I have noticed the hanging webpage problem which is an issue. I am wondering if redirecting to 0.0.0.0 is the problem? It seems quite a few of the problems are because some javascript is waiting for the website to return data. Could we adjust this and send the redirect somewhere else that returns some data so the webpage continues to load?

I'm a bit of a noob here so any explanation or help is appreciated!

EDIT: I have changed all the redirects to 127.0.0.1 and I am not seeing any hanging anymore in my limited testing. That might be the issue?

Post Reply