4 ms·
dnsmasq can read from /etc/hosts so you can automate it just using `curl` (or other standard UNIX tools): # the first command is a one time only job cp -
by laumars 11y ago
dnsmasq can read from /etc/hosts so you can automate it just using `curl` (or other standard UNIX tools):
# the first command is a one time only job
cp -vip /etc/hosts /etc/hosts.default
# the following is the automation.
curl http://someonewhocares.org/hosts/hosts --silent > /etc/hosts.sowc
cat /etc/hosts.default /etc/hosts.sowc >> /etc/hosts
The other benefit of this is you can then just do a `dnsmasq reload` (since the hosts file is an external configuration file) rather than the full `dnsmasq restart` that dnsgate performs.
- creshal 11y agodnsmasq has an addn-hosts parameter, so you don't have to thrash your main hosts file.
- laumars 11y agoOh that's handy. Would also make the update even easier since you no longer need to preserve any host-specific entries so a simple one liner in `curl` or `wget` would be enough. Thanks for the recommendation.
- jakeogh 11y agoI'm trying to think of a use case for addn-hosts in dnsgate. If the user is not using dnsmasq, then they are stuck with /etc/hosts, if they are using dnsmasq then they might as well use a dnsmasq syntax file so '--block-at-tld' can be used. dnsmasq.conf has an include syntax: echo "conf-file=/etc/dnsgate/generated_blacklist.conf" >> /etc/dnsmasq.conf
- vive-la-liberte 11y agoBut having the entries in /etc/hosts should on Unix in most cases cause your computer to find it there right away without DNS lookup. Are you using dnsmasq locally on the host computer or to serve other computers as well? In the latter case, I see the point (though if I were to use dnsmasq I wouldn't intermix the hosts file).
- laumars 11y agoThere wouldn't be any point running dnsmasq only for a local machine :) RE intermixing hosts file: dnsmasq supports reading from additional hosts files other than /etc/hosts (thank to creshal for that suggestion: https://news.ycombinator.com/item?id=10580082 https://news.ycombinator.com/item?id=10580082)
- dylanh 11y agoI run dnsmasq locally (and silently redirect all traffic from a certain uid with an iptables rule) to do adblocking and ... minimal parental control on my son's laptop. it is pretty great, I don't have to worry about him using the neighbor's wifi to get around my rules. ;)
- lmm 11y agoSilently putting data fetched over unauthenticated HTTP into your hosts file doesn't sound like a great idea.
- laumars 11y agoGood point. Sadly that's pretty much how all adblockers keep up-to-date (albeit at least with TLS). Though pragmatically even if the update was manual, you still need to place some trust in the site when dealing with files of that size. Granted it would be better if those resources served TLS, but that would only prevent MITM and not the file being dodgy from source (eg site hacked). Thinking a little more about the problem you raised, I guess you could grep it for IPs that aren't localhost (ie exit the shell script before writing the new hosts if `grep` returns a zero exit code). Aside that, I'd genuinely be interested in any ideas you have for keeping the file updated in a secure way (if at all possible).
- h4waii 11y agohttps://gist.github.com/Holzhaus/ed4ac1675a57f11c3057 https://gist.github.com/Holzhaus/ed4ac1675a57f11c3057 contains a simple reverse grep for doing this. You should still have a modicum of trust towards the host you're pulling from, as they can also insert something to potentially break the parsing code, which opens up a whole 'nother host of issues.
- jakeogh 11y agoTrue. In dnsgate's case the domains are extracted and guaranteed (real hostname validation is on the todo) to point to 127.0.0.1 (or whatever '--dest-ip' is).
- jakeogh 11y agodnsmasq can read /etc/hosts, but /etc/hosts format can't do * blocking. So if you are using /etc/hosts (with dnsmasq) '--block-at-tld' wouldn't work. Moving /etc/hosts to /etc/hosts.default is much better than the 'hosts example'. Updated it. Thanks. Still experimenting with 'dnsmasq reload' but if it works as advertised that's more general than restarting the service.