Ad blocking with LEDE

Ad blocking

This is a Utility script that downloads a custom HOSTS file from http://www.winhelp2002.mvps.org/ the purpose of this file is to block unwanted Ad's

"MVPS HOSTS now includes entries for most major parasites, hijackers and unwanted Adware/Spyware programs!"

NEW

This (which gives the possibility to add some custom hosts in /mnt/sda1/hosts or /mnt/sdb1/hosts)

dl_hosts.sh

#!/bin/sh

export DLHOSTS=/var/dlhosts_log
echo "" > $DLHOSTS
_rogue=0.0.0.0
echo -e "#!/bin/sh\nn=1\nwhile sleep 60\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/var/dlhosts\n" >/var/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /var/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet
n+=1\ndone\n[ -e /mnt/sda1/hosts ] && cat /mnt/sda1/hosts >>/var/dlhosts\n[ -e /mnt/sdb1/hosts ] && cat /mnt/sdb1/hosts >>/var/dlhosts\nkillall -HUP dnsmasq" >>/var/write_dlhosts
chmod +x /var/write_dlhosts
/var/write_dlhosts &
echo "Download Sequence Completed!" >> $DLHOSTS

NOTES:

Put dl_hosts.sh in /etc

Make dl_hosts.sh executable

Run "chmod +x /etc/dl_hosts.sh" from the command line

From Web UI add, Network > DHCP and DNS > Resolv and Hosts file > Additional Hosts files /tmp/dlhosts

Run "/etc/dl_hosts.sh &" from your startup

reboot

Enjoy!

This is a Utility script to download a custom HOSTS file from winhelp2002.mvps.org, the purpose of this file is to block unwanted Ad's

The hosts file is only used by the local machine. Wouldn't you need to load this
data into DNS to have it affect everything on your local network?

David Lang

Nope.

The script creates a file called "dlhosts" and the hosts "names" have a IP 0.0.0.0 then dnsmasq on the router uses IP 0.0.0.0 and blocks the host site.

There is a similar script in packages feed https://github.com/openwrt/packages/tree/master/utils/banhosts

And if you need more versatile ad blocking, there is the 'adblock' package with LuCI support from luci-app-adblock

That package makes browsers to behave nicely with the blocked sites, as it serves pixel links for the blocked sites via uhttpd instances.

Hi, I am just trying this, and the script works fine and generates the file. However I am not sure that dnsmasq is reading the /var/dlhosts file, or if there is a way to make it read it? It doesn't appear to prevent access to any of the listed domains so far.
I'm actually trying to use this as a way of blocking social media sites for set periods, to stop my kids (and myself!) from accessing them :slight_smile: