#!/bin/bash
wget -qO- https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts \
| sort -u \
| awk '/^0/ {print;print ":: " $2}' \
> /tmp/ad-hosts
service dnsmasq reload
I know cycles are cheap but that doesn't mean we should be spaffing them up the wall when we can do things cheaper. This avoids double-processing the downloaded content.dnsmasq config as above.
I run dnsmasq on a pi as my ISP router is pretty limited. You can't even change the DNS servers, so the pi has to do DHCP too.
I use it to block other things like fixed banner overlays. With caching you can get it to work when you go off WiFi too [0].
Not sure I'd use Google's DNS servers though. Your ISP's are probably better for both speed and privacy. You can test the speed with an old Google project called namebench [1].
Unfortunately my ISP's (Sky, UK) DNS servers aren't particularly reliable. My devices are behind the DD-WRT router that forces its own DNS settings (other servers are intercepted), but the rest of the family connects directly to the ISP router[1]. Multiple times I've been browsing the Internet without issue, but other people have been unable to use the Internet. Changing their device to use Google's DNS server resolved the issue.
[1] Been meaning to merge the two for a while, but haven't got around to it yet
I use this with DD-WRT to get network-wide filtering. It's not perfect (only updates on router boot), but good enough for me.
Additional DNSMasq options:
Startup script: