Easy, persistent, local DNS cache to reduce lookup times
Important Update!
Don’t use this method any more! I have a much easier way to do it in a more recent post.
But for posterity…
First install resolvconf and pdnsd: sudo apt-get install pdnsd resolvconf. Resolvconf handles the messy interaction between different programs fighting over the /etc/resolv.conf file, and pdnsd provides a persistent DNS daemon, which will cache the DNS lookups on your machine in order to make browsing faster.
Next, you just need to edit pdnsd’s configuration file, /etc/pdnsd.conf as root. Edit it to look like this:
global {
perm_cache=512;
cache_dir="/var/cache/pdnsd";
max_ttl=604800;
run_as="pdnsd";
paranoid=on;
# next setting allows ppp/ip-up update the name servers -- ABa / 20040213
status_ctl=on;
server_port=53;
server_ip="127.0.0.1";
}
#Edit these to be your own servers if wished:
server {
label = "OpenDNS";
ip=208.67.222.222,208.67.220.220;
proxy_only=on;
timeout=10;
}
# if you installed resolvconf, and status_ctl=on
server {
label="resolvconf";
}
source {
ttl=86400;
owner="localhost.";
# serve_aliases=on;
file="/etc/hosts";
}
And finally, restart pdnsd with sudo /etc/init.d/pdnsd restart to use the new settings. In the example above, I've used OpenDNS's servers, but you can change these to whatever you want. As far as actual results go:
~$ dig example.com; <<>> DiG 9.3.2 <<>> example.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17447
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:
;example.com. IN A;; ANSWER SECTION:
example.com. 172800 IN A 192.0.34.166;; Query time: 513 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Oct 5 15:24:19 2006
;; MSG SIZE rcvd: 45$ dig example.com
; <<>> DiG 9.3.2 <<>> example.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19338
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:
;example.com. IN A;; ANSWER SECTION:
example.com. 172799 IN A 192.0.34.166;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Oct 5 15:24:20 2006
;; MSG SIZE rcvd: 45

Thanks for this tip! Really speeds up my resolving time