HOWTO: Persistent DNS Caching on Ubuntu with pdnsd
Posted by Kelvin on 27 Apr 2010 at 01:59 pm | Tagged as: programming, Ubuntu
sudo apt-get install pdnsd
If prompted, choose "Manual".
sudo gedit /etc/pdnsd.conf
Copy and paste this into the editor.
// Read the pdnsd.conf(5) manpage for an explanation of the options. /* Note: this file is overriden by automatic config files when /etc/default/pdnsd AUTO_MODE is set and that /usr/share/pdnsd/pdnsd-$AUTO_MODE.conf exists */ global { perm_cache=8192; cache_dir="/var/cache/pdnsd"; run_as="pdnsd"; server_ip = 127.0.0.1; // Use eth0 here if you want to allow other // machines on your network to query pdnsd. status_ctl = on; paranoid=on; // query_method=tcp_udp; // pdnsd must be compiled with tcp // query support for this to work. min_ttl=96h; // Retain cached entries at least 15 minutes. max_ttl=2w; // One week. timeout=10; // Global timeout option (10 seconds). proc_limit=60; procq_limit=60; par_queries=4; // Don't enable if you don't recurse yourself, can lead to problems // delegation_only="com","net"; } server { label="OpenDNS Plus"; ip= 208.67.222.222 , 208.67.220.220 , 12.213.224.61 , 192.228.79.201 , 192.33.4.12 , 128.8.10.90 , 192.203.230.10 , 192.5.5.241 , 192.112.36.4 , 128.63.2.53; timeout = 5; uptest = query; interval = 30m; // Test every half hour. ping_timeout = 300; // 30 seconds. purge_cache = off; exclude = .localdomain; policy = included; preset = off; } source { owner=localhost; // serve_aliases=on; file="/etc/hosts"; } rr { name=localhost; reverse=on; a=127.0.0.1; owner=localhost; soa=localhost,root.localhost,42,86400,900,86400,86400; }
Now edit /etc/default/pdnsd
sudo gedit /etc/default/pdnsd
Replace
AUTO_MODE=recurse
with
#AUTO_MODE=recurse
This disables AUTO_MODE and gets pdnsd to use our /etc/pdnsd.conf file.
Now edit the dhclient.conf file.
sudo gedit /etc/dhcp3/dhclient.conf
Replace
#prepend domain-name-servers 127.0.0.1;
With
prepend domain-name-servers 127.0.0.1;
(delete the # from the start of the line). Save and exit.
sudo /etc/init.d/pdnsd restart
Test out the DNS cache like so
dig google.com
Check that the SERVER line shows 127.0.0.1#53(127.0.0.1). This means you’re pointed at your local cache.
Now, if you run that command again:
dig google.com
You should see something like Query time: 0 msec.