Smoothwall Firewall project

Sunday, 3 July 2011

DNSMASQ config on Ubuntu desktop for fast DNS lookups


Here is a quick rundown on how to use dnsmasq as a fast DNS cache. I was driven to set this up, as the DNS servers that my flat company supply are like treacle on a very cold day.

Help on installing DNSMASQ

Install the daemon, and then edit /etc/dnsmasq.conf to listen on port 127.0.0.1. You need to find the line that has #listen-address= and remove the hash and add the address.

Add this nameserver 127.0.0.1 into the top of /etc/resolv.conf file at the top, and restart the daemon. This is where Linux looks for it's DNS servers.

/etc/init.d/dnsmasq restart

Do a DNS lookup like this to test - dig google.com
Look at the time returned, and then do it again, and look at the time difference, a lot faster isn't it.

Advanced fun and games.

If you want to look at the contents of the cache that dnsmasq is curently storing (in memory)then you need add the -q parameter to the startup scipt, just tag it onto the end. The start-up script is in the /etc/init.d directory, and you need to scroll down to the start function. You will see a long list of parameters that get passed, just add the -q to the end.

Then restart the daemon.

To look at the cache we need to send the SIGUSR1 parameter to the kill command to dump the currently held cache into the /var/log/syslog file. Use the following command to do that.

kill -s USR1 1234 - for instance where 1234 is the PID number of the dnsmasq running daemon. You can find that with the ps -ef | grep dnsmasq command.

If you want to add static DNS entries into your cache, edit the /etc/hosts file and add your required , and often used DNS entries in there. These will be read when dnsmasq starts , and will be available immediately without reference to an upstream DNS resolver. So they will be extrememly quick, which is just what I wanted.

For a quick guide on DNS look here.

Quick guide to DNS

3 comments:

virendra yadav said...

Thanks a lot for sharing this nice post!You’ve done really excellent job!

virendra said...

online calculator

Thanks a lot for sharing this nice post!You’ve done really excellent job!

Keith Eckstein -A Taste of Garlic said...

PDNSD is also a good alternative - it's what we use; the advantage is that it writes the DNS cache to disk.

All the best

Keith