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 126.96.36.199. 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 188.8.131.52.
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 184.108.40.206 nameserver 220.127.116.11
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.
7 thoughts on “Setup a persistent local DNS cache on Ubuntu Jaunty with pdnsd and OpenDNS”
That worked a treat. Thanks for sharing.
It doesn’t appear to be permanent. The symlink gets replaced with a file at some point in time and reverts back to the connection-provided DNS server instead of the local cache.
I get the following error when running ‘sudo resolvconf -u’
resolvconf: Error: /etc/resolv.conf must be a symlink
@Henry H: Yeah, I’ve since noticed that. It happens whenever the NetworkManager refreshes the ip address from dhcp. I’m on a desktop and go weeks between dhcp updates. I’m trying to figure out a persistent solution that minimizes the need to edit config files by hand.
This is way too useful to me! How do I get round the impermenance please? Is it the very act of DHCP renewal that causes the problem or a change in IP in a new lease? For me if it is just a problem of the DHCP lease carrying a new IP address, then I will tell the router to lock down my IP address to my MAC.
Anyway, thanks for sharing this solution, my ISP has decided to do DNS rerouting for commercial purposes and the performance hit is killing me.
It’s the NetworkManager. Every time Gnome asks for the IP, it overwrites the text file. Won’t matter if you tell the router to use the same address.
I currently don’t have it set up any more (fresh install of Karmic Koala), because I’ve found that my router already caches DNS requests, so I just set my router to use OpenDNS and let my machines point to it.
I tried this and works fine in karmic even on an IP renewal. One thing I did add since I done this almost similar setup using bind9 as local caching is to edit
and uncomment this line.
prepend domain-name-servers 127.0.0.1;