Use Google DNS With Open DNS And Local Fallback In Ubuntu Linux

Every web site resolves to an IP address. Domain names such as jasonsnider.com are mapped to an IP address in this case 173.45.227.188. DNS servers provide a directory of Domain names to their corresponding IP addresses. When you make a request to a web site, your system will query a DNS server, that DNS record will typically be cached on your local machine. All future queries will then use the cached entry to resolve it's IP address. Once the cache expires another query will be made to a DNS server. My preference for DNS is Google DNS and Open DNS. This tutorial will provide an example of configuring an Ubuntu Linux machine to use Google DNS by default while using Open DNS and you local domain (if applicable) as DNS fallbacks.

First, open your resolv.conf. I use VIM, if you don't replace vim with your editor. Probably gedit, nano or emacs.

sudo vim /etc/resolv.conf

If your system is on a domain your network manager has probably generated some default directives. They may look something like the following.

# Generated by NetworkManager
nameserver: 10.10.10.10 
domain example.com
search example.com

Remove the nameserver directive, leave any other generated directives as you found them. To add your nameservers simply add a stack of nameserver directives. You may add as many as you like, the first entry in the list will be the first server to be queried. It will move down the list until it finds a responsive server. The following assumes a local domain of example.com and local DNS servers at nameserver 10.10.110.2, 10.10.10.10 and 10.10.10.8.

# Generated by NetworkManager
domain example.com
search example.com

# Use Google as the primary DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

# Fallback to OpenDNS
nameserver 208.67.222.222
nameserver 208.67.220.220


# Use local DNS as a last resort
nameserver 10.10.110.2
nameserver 10.10.10.10
nameserver 10.10.10.8