-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
AutoUpdate on OpenWRT based box (also works on LEDE)
Run this commands on a device flashed with OpenWRT based firmware that acts as router (with internet conected and dnsmasq serving dns) to have hosts filtering working for entire local network:
Create the update script:
cat<<'EOF' > /etc/adblock.sh
#!/bin/sh
#thisfile: /etc/adblock.sh
rm -f /tmp/block.hosts
logger "Updating /tmp/block.hosts"
wget -O /tmp/block.hosts http://devices.mydomain.com/openwrt/block-lite.hosts?box=HomeRouter
logger "Updated /tmp/block.hosts"
/etc/init.d/dnsmasq restart
exit 0
EOF
#make executable
chmod +x /etc/adblock.sh
The logger
entries could be checked running logread
You could link to http://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
, but I recommend link to your own url for more control.
If busybox
wget
complains about redirect to https you should install full wget
support with opkg update && opkg install wget
Add block.hosts
to dnsmasq:
uci delete dhcp.@dnsmasq[0].addnhosts && uci commit dhcp
uci add_list dhcp.@dnsmasq[0].addnhosts='/tmp/block.hosts'
uci commit dhcp
Create a hotplug wan-ifup script (will run adblock.sh
every time it reconnects to internet when device reboot)
cat<<'EOF' > /etc/hotplug.d/iface/99-adblock-ifup-wan
#!/bin/sh
#thisfile: /etc/hotplug.d/iface/99-adblock-ifup-wan
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
logger "Detected ifup-wan, running /etc/adblock.sh"
sleep 10
sh -x /etc/adblock.sh
}
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wwan" ] && {
logger "Detected ifup-wwan, running /etc/adblock.sh"
sleep 10
sh -x /etc/adblock.sh
}
exit 0
EOF
chmod +x /etc/hotplug.d/iface/99-adblock-ifup-wan
Make a crontab entry to execute an update at 4:00am Sundays and Wednesdays in every month.
cat<<'EOF' >> /etc/crontabs/root
0 4 * * 0,3 sh -x /etc/adblock.sh >/dev/null 2>&1
EOF
cat<<'EOF' > /etc/crontabs/cron.update
root
EOF
/etc/init.d/cron enable
/etc/init.d/cron start
Run for first time:
/etc/adblock.sh