Using a local DNS cache on Debian

Posted by robbiebow on 4 September, 2009 under geek, perl | Be the First to Comment

I created a very simple script to check a variety of sites are up and running (or at least not returning errors to HTTP requests), and run it as a cron job on three different servers. False positive responses started occurring, and this was down to DNS errors from $hosting_companies’ nameservers.

To reduce these I installed dnsmasq to act as a local DNS cache on each machine:

aptitude update
aptitude install dnsmasq

This also required adding the following line to /etc/resolv.conf to ensure my script (and other applications making DNS queries) used dnsmasq first:

nameserver 127.0.0.1

Making sure to put that above the other nameserver entries. Now DNS responses are 0-3ms instead of the ~ 70ms before and the false positive alerts have dried up.

See http://wiki.debian.org/HowTo/dnsmasq for more details on setting up dnsmasq

Add A Comment