Install and use pdnsd for name service caching

The man pages describe pdnsd as a dns proxy daemon capable of saving the contents of its DNS cache to the disk on exit.

The Install

wget http://li.nux.ro/download/nux/misc/el6/x86_64/pdnsd-1.2.9a-par.x86_64.rpm
yum install pdnsd-1.2.9a-par.x86_64.rpm
cp /etc/pdnsd.conf.sample /etc/pdnsd.conf

Edit the /etc/pdnsd.conf file.  Under server, change the ip value to your DNS server.

server {
label= "myisp";
ip = 192.168.1.1,8.8.8.8; # Put your ISP's DNS-server address(es) here.

Edit the /etc/resolv.conf to point the server to itself. For my test, I commented out everything and only added the one line.

nameserver 127.0.0.1

The files

  • /etc/pdnsd.conf is the pdnsd configuration file. The file format and configuration options are described in the pdnsd.conf(5) man page. You can find examples of almost all options in /etc/pdnsd.conf.sample.
  • /var/cache/pdnsd/pdnsd.cache
  • /var/cache/pdnsd/pdnsd.status is the status control socket, which must be enabled before you can use pdnsd-ctl.
  • /etc/init.d/pdnsd (the name and location of the start-up script may be different depending on your distribution.)
  • /etc/resolv.conf
  • /etc/defaults/pdnsd contains additional parameters or options which may be passed to pdnsd at boot time. This saves the hassle of fiddling with initscripts (not available on all distributions).

Start the service and make it autostart.

service pdnsd start
chkconfig pdnsd on

A few ways to test things.

# Run the folling command twice.  See the difference in time it takes to return results.
time nslookup www.google.com
# dig should return results.
dig @127.0.0.1 google.com
# netstat should show that port 53 is listening.
netstat -antp | grep 53
# This command will dump to the screen the cache that has been collected.
pdnsd-ctl dump

[root@test]# pdnsd-ctl dump
Opening socket /var/cache/pdnsd/pdnsd.status
mirror.datto.com.
07/26 11:52:23 A 198.49.95.5

lehigh.edu.
07/26 11:52:35 SOA rover.cc.lehigh.edu. hostmaster.lehigh.edu. 2016072050 3600 600 1209600 86400

mirror.beyondhosting.net.
07/26 11:52:26 A 8.29.132.68

centos.mirrors.wvstateu.edu.
07/26 11:52:23 A 192.73.23.18

Succeeded.

Unlike ncsd, where a restart of the service will delete the cache, the following command will do the trick.  In other words, restarting pdnsd will not delete the cache.

pdnsd-ctl empty-cache

For help.

man pdnsd
pdnsd-ctl help

Source(s)

https://pkgs.org/centos-6/nux-misc-x86_64/pdnsd-1.2.9a-par.x86_64.rpm.html
http://unix.stackexchange.com/questions/6238/dns-queries-not-using-nscd-for-caching
https://tektab.com/2013/03/21/howto-pdnsd-on-redhatcentos-from-source/