1. Install DNSMasq:
sudo apt-get install dnsmasq
2. Configure dnsmasq.conf
Press Alt + F2 and type:
gksu gedit /etc/dnsmasq.conf
Now search for "listen-address" (it's on line 90 on my Ubuntu Karmic installation), remove the "#" character in front of "listen-address" and add "127.0.0.1" after the "=" (all without the quotes). Basically, this is how the "listen-address" line should look like after editing it:
listen-address=127.0.0.1
(Optional) You can also edit the cache size if you want. Search for this in the same file: "#cache-size=150" (it's on line 432 on my Ubuntu Karmic installation), remove the "#" character in front of the line (this uncomments it) and change "150" with the size you want for you DNS cache. This is how the line should look after editing it:
cache-size=500
Obviously, "500" can be any number you want.
Don't forget to save the changes!
3. Edit dhclient.conf
Press Alt + F2 and type:
gksu gedit /etc/dhcp3/dhclient.conf
And modify the "prepend domain-name-servers" (it's on line 20 on my computer) to look like this:
prepend domain-name-servers 127.0.0.1;
4. Edit resolv.conf
Press Alt + F2 and paste this:
gksu gedit /etc/resolv.conf
Initially, this is how the resolv.conf file looks like:
nameserver ISP_DNS1
nameserver ISP_DNS2
Where ISP_DNS1 and ISP_DNS2 are your ISP domain name servers (or 8.8.4.4, etc if you are using Google DNS and so on).
Put this as the first line in your resolv.conf file:
nameserver 127.0.0.1
Which means this is how your resolv.conf file will look like:
nameserver 127.0.0.1
nameserver ISP_DNS1
nameserver ISP_DNS2
Again, ISP_DNS1 and ISP_DNS2 are your ISP domain name servers.
As an example, this is how my resolv.conf file looks like (using local DNS cache, a Google DNS and an OpenDNS DNS):
nameserver 127.0.0.1
nameserver 8.8.4.4
nameserver 208.67.220.220
4.1 If you are using a DSL connection, you need to make sure the ppp client will not overwrite your /etc/resolv.conf file. To do this, press Alt + F2, and paste this:
gksu gedit /etc/ppp/peers/dsl-provider
Search for "usepeerdns" and replace it with "#usepeerdns" (we used "#" to comment that line so it's ignored).
5. Restart your networking and dnsmasq:
-Networking:
sudo /etc/init.d/networking restart
-DNS:
sudo /etc/init.d/dnsmasq restart
Please note that you can use this last command at any time you want to restart your DNS cache (flush DNS, clear the cache - call it whatever you want) without restarting the computer.