Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Last active September 4, 2023 18:28
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bsodmike/1d9da5ff882ea6c95381fd1c1d97bcea to your computer and use it in GitHub Desktop.
Save bsodmike/1d9da5ff882ea6c95381fd1c1d97bcea to your computer and use it in GitHub Desktop.
HOWTO Ubiquity EdgeMAX Ad Blocking Content Filtering using EdgeRouter

Ubiquity EdgeMAX Ad Blocking Content Filtering using EdgeRouter

This is based on a guide on the Ubnt forums.

Log into your Edgerouter and run the following - sudo -i && vi /config/user-data/update-adblock-dnsmasq.sh This will switch you to the root user and open up vi.

#!/bin/bash

ad_list_url="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext"
#The IP address below should point to the IP of your router or to 0.0.0.0
pixelserv_ip="0.0.0.0"
ad_file="/etc/dnsmasq.d/dnsmasq.adlist.conf"
temp_ad_file="/etc/dnsmasq.d/dnsmasq.adlist.conf.tmp"

curl -s $ad_list_url | sed "s/127\.0\.0\.1/$pixelserv_ip/" > $temp_ad_file

if [ -f "$temp_ad_file" ]
then
        #sed -i -e '/www\.favoritesite\.com/d' $temp_ad_file
        mv $temp_ad_file $ad_file
else
        echo "Error building the ad list, please try again."
        exit
fi

/etc/init.d/dnsmasq force-reload
sudo -i
chmod a+x /config/user-data/update-adblock-dnsmasq.sh
sh /config/user-data/update-adblock-dnsmasq.sh
(crontab -l ; echo "56 4 * * 6  /config/user-data/update-adblock-dnsmasq.sh") | crontab -

Visit the following sites to confirm the ad-blocker is working:

References

This is based on a YouTube video by Willie Howe.

@martinsohn
Copy link

Thank you for this. I've forked it, and updated it to:

  • Include high risk malware domains from DShield. Although many of the domains are already blocked by most browsers.
  • Temp files are stored in /tmp and removed afterwards. Reason: any file in /etc/dnsmasq.d/ will be read as a config file (with some exceptions)
  • Removing duplicate domains (because of multiple sources)
  • Update the blocklists every day instead of once per week

@Taz-crypto
Copy link

thanks it worked on Edgerouter ER-X I recommend not touching DNS on DHCP Server-Lan

@JMRROCHA
Copy link

JMRROCHA commented Apr 5, 2021

thanks it worked on Edgerouter ER-X I recommend not touching DNS on DHCP Server-Lan

Same here, works very well on a erpoe-5 for a few hours, and then crashes dns forwarder.

@Sir1980
Copy link

Sir1980 commented Aug 30, 2021

Forgive my ignorance but how do I enter the script above in my EdgeRouter X? I've tried the CLI and I guess I'm not doing something right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment