Aug
28
2014
dnsmasq with custom hosts file

Title: dnsmasq with custom hosts file - aka ban sites with dnsmasq

I ‘ve already said it too many times, but dnsmasq is a beautiful project for SOHO (small office/home office) environment.

I am using it as DNS caching server, DHCP server & tftpd (PXE) server and it’s amazing.

One thing i do with the dns section is that i “BAN” urls i dont like. Think something like AdBlock on firefox.
Two configuration changes:

A.

as root


wget http://winhelp2002.mvps.org/hosts.txt -O /etc/hosts.txt && 

and

B.

in /etc/dnsmasq.conf


addn-hosts=/etc/hosts.txt

You can also put the wget cmd in your crontab with the @monthly scheduler but you need to restart the dnsmasq every month!

Another amazing thing is that you can add your one entries:


echo 0.0.0.0 www.facebook.com >> /etc/hosts.txt

restart your dnsmasq service and check it:


# dig www.facebook.com @localhost +short
0.0.0.0
Tag(s): dnsmasq