Caching DNS

I move my GNU/Linux laptop bewteen different networks quite regularly, and I’ve never been totally happy with its configuration. Many other people do the same thing, and they have a few different methods for auto-configuring networking. But none of them seem perfect for me.

I used to use pdnsd, and it worked well when I knew the nameservers for each network I connected to. The pdnsd.conf contains a list of nameserver details, and allows you to configure tests to check if those servers are available. When I move between networks I could also use pdnsd-ctl to explicitly enable an appropriate set of nameservers. But this isn’t very useful when I connect to a new DHCP network where I don’t have the details of the nameservers until I connect. I could write a script to dynamically rewrite the pdnsd.conf, but this seems a bit messy.

After some research (in the Debian package list) I choose dnsmasq. It doesn’t have a persistant cache like pdnsd, and it won’t let me configure a whole set of nameservers like pdnsd, but it does allow me to easily change the default nameservers to use for forwarded queries.

By default, dnsmasq uses /etc/resolv.conf (like everything else) to get the addresses of nameservers to contact, so when dnsmasq is running on a firewall, the internal machines can use the firewall machine as nameserver. But I don’t want that. I want my resolv.conf to have the loopback address as the nameserver, and I want dnsmasq to read from another file. This is trivial to setup, and that is why I’m now using dnsmasq.

Published
Categorized as Uncategorized Tagged