Friday, October 28, 2016
How to block advertisement using OpenWRT
How to block advertisement using OpenWRT
Blacklist Ad Content Delivery Domains
This is how I block advertisement at DNS level on OpenWRT.Blocking at DNS level is advisable because it does not impact bandwidth and latency.
Simply said it tricks your computer that your loopback address is where adserver are located but cannot be found so adservers are ignored totally.
AdServers are becoming more and more of a nuisance.
- They serve up malware advertisement,
- They load flash advertisements which waste bandwidth and increase latency.
- They run javascripts to try and "take over" your web browser via redirection and popups.
Fortunately OpenWRT makes this easy with the use of dnsmasq.
My web surfing experience has since greatly improved since
Here is how to do it in 2 steps(Yes it is that simple and powerful with Linux):
- SSH into your router
- Copy and paste this Command into the terminal
wget -O /etc/dnsmasq.conf "http://pgl.yoyo.org/as/serverlist.php?hostformat=dnsmasq&showintro=1&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext" && /etc/init.d/dnsmasq restart
What this script does is telling your Router to http://pgl.yoyo.org/adservers/
to get a list of known adservers in a dnsmasq friendly format and save it to /etc/dnsmasq.conf if that command is successful then restart dnsmasq.After that you will soon notice the disappearance of many irritating advertisement when using the web .
Hopefully this improves your web surfing experience as well as let you realise and embrace the power of shell scripting.
If you want to point the ip address to 0.0.0.0 (invalid ip) instead of 127.0.0.1(loopback)
sed -e s/127.0.0.1/0.0.0.0/g -i /etc/dnsmasq.conf && /etc/init.d/dnsmasq restart
Blacklist Malware Delivery Domains
Copy the ads list to temporary directorycp /etc/dnsmasq.conf /tmp/adlist.txt
Change to temporary directorycd /tmp/
Download the Malware Domain List from malwaredomains.comwget http://mirror1.malwaredomains.com/files/domains.txt
Filter the file to match the format dnsmasq requiresawk { print $1 } domains.txt | grep . | sed s/^/address=//g | sed s/$//0.0.0.0/g > malwarelist.txt
Combine the files sed -i -e $a adlist.txt &&
cat adlist.txt malwarelist.txt > combinelist.txt
Sort the files sort combinelist.txt > dnsmasq.conf
Copy back the final file and restart dnsmasq mv dnsmasq.conf /etc/dnsmasq.conf && /etc/init.d/dnsmasq restart && rm *.txt
Unblock a particular domain
Assuming there is this domain "example.com" that falls into the blacklist but you know you need it, so how do you unblock it? This example uses vi but you can use any text editor, the idea is the same remove the line and it will be unblocked.Edit the file using the text editor vi
vi /etc/dnsmasq.confSearch the file for the block domain
type
"/example.com"Delete the line navigate to the line using arrow then
type
"dd"The line should dissppear
Press escape to return to command mode then
type
:wqto save and quit
Restart the DNS Service
/etc/init.d/dnsmasq restartReload the browser with Ctrl + F5 and the domain should be unblocked.
Go to link Download
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment