Saturday, August 19, 2017

Blocking Ads with Squid and Unbound DNS Server

Read Up On The Following First To Understand What's Going On Blocking Ads With Squid http://pgl.yoyo.org/adservers/#withsquid Blocking Ads With Unbound DNS Server https://github.com/KhaineBOT/DNS-Unbound-Blocklist-Downloader I added this section to my squid configuration
## disable ads ( http://pgl.yoyo.org/adservers/ )
acl ads dstdom_regex  "/yoursquiddirectoryhere/ad_block.txt"
http_access deny ads
#deny_info TCP_RESET ads
I ran the script provided on the http://pgl.yoyo.org/adservers/scripts/squid/update-squid-adservers.txt With modifications for my squid proxy server and it restart squid. Ads blocked. While the proxy is good defense. Some of the ad networks are using https and dns to get around proxies and firewalls. So another way to block is using your dns server. I made a few modifications to my Unbound Config to add an include statement to now read the file from the python script
include: "/etc/unbound/local-blocking-data.conf"
I ran the python script and it restarts Unbound https://github.com/KhaineBOT/DNS-Unbound-Blocklist-Downloader To periodically update new domains that get added to the lists on the Adserver Lists, I added the scripts to the crontab to run nightly Crontab Entries
#ad block section
%nightly,random * 23-6 /root/ad_block.sh >> /dev/null 2>&1
%nightly,random * 23-6 /usr/bin/python /root/dns-unbound-blocklist-downloader.py

No comments: