Setup a persistent local DNS cache on Ubuntu Jaunty with pdnsd and OpenDNS
Discalimer: I take no responsibility if you screw up your computer or can’t connect to the internet after following this! If you do mess things up, do what I do, head on over to Ubuntu Forums and ask for help.
This howto will show you how to setup your Ubuntu Jaunty 9.04 machine to use OpenDNS to resolve DNS names, and keep local cache that will survive machine reboots. It’s a modified set of instructions that I first posted here.
There are several reasons why you’d want to to this.The quick one-liner: faster, more reliable web browsing. For a little more detailed response read on, otherwise, you can skip straight to the How below.
Need more info, okay. First, it might be a good idea to know what DNS is. Basically, it’s the address service that translates the domain google.com into it’s IP address 188.8.131.52. People generally find it easier to remember domain names than IP addresses. But the computer needs the IP address to load websites, so when you make a request for any files on google.com, your computer asks a DNS server for Google’s IP address. 99.9% of the time, your ISP provides DNS servers for your computer to use, and you don’t have to think about it.
But this address lookup takes time. Over the course of loading just one file, you might not notice it, but when browsing a web page, you’re probably loading dozens of files (images, scripts, etc.) This can mean lots of DNS requests if the files are on different servers. And ISP-run DNS servers don’t always have the best track records on being the fastest or the most reliable. Ever have your router tell you that you have an internet connection, but you can’t get to any websites? Usually, it’s because the ISP’s DNS server is having issues. So yes, technically your computer can access the internet, but you can’t really use it, unless you happen to know the IP addresses of everywhere you want to go. But, most of us get to Google through google.com, not by remembering 184.108.40.206.
So why use OpenDNS? Because generally it provides a faster, more reliable DNS service than what your ISP service provides. OpenDNS lets you setup filters, and much, much more. And why a persistent local DNS cache? Because even requests to OpenDNS take some time. And most websites rarely change their IP address, so why constantly lookup an address that isn’t changing? By using a local cache, your computer won’t have to keep asking the DNS server for addresses, because it will remember addresses that you’ve already been to. Sure, every now and then your computer will need to ask a real DNS server for an address, like when you go to a new website, or even occasionally for sites you visit often, just in case their IP address has changed.
Otherwise, even if your computer only remembers an address for 15 minutes, that’ll improve your browsing experience significantly. So, ready for faster browsing?
Okay, so we’re going to install the local DNS server called pdnsd, and a support package called resolvconf. Pdnsd will be responsible for remembering DNS addresses, and resolvconf is responsible for letting your computer know to use pdnsd.
In a Terminal window, run the following to install both resolvconf and pdnsd in the correct order:
sudo apt-get update && sudo apt-get install resolvconf && sudo apt-get install pdnsd
When prompted during the pdnsd install, select “Use resolvconf”. Then run the following to create a config file for resolvconf:
gksudo gedit /etc/resolvconf/run/interface/opendns
In the new document, paste the following so that resolvconf will know how to use OpenDNS:
nameserver 220.127.116.11 nameserver 18.104.22.168
Finally save the document, exit gedit, and run this command in the Terminal:
sudo resolvconf -u
Congratulations, welcome to faster browsing. To check that everything is working, try the following:
Verify that the SERVER line shows 127.0.0.1#53(127.0.0.1), which means you’re pointed at your local cache. Look at the Query time, which should show how long it took to ask for google’s IP address from OpenDNS the first time.
Now, if you run that command again:
You should see a significant time drop, like Query time: 0 msec. That means that everything is working, that instead of asking OpenDNS for the IP address, pdnsd responded with the cached information, which took no measurable time.