How to increase DNS queries performance with DNSMasq

I decide to try to improve DNS queries performance (and traffic) on our SQUID proxy server using dnsmasq as cache. All DNS queries should go to dnsmasq, while dnsmasq forward the queries to upstream DNS servers.

First install DNSMASQ:

apt-get update
apt-get install dnsmasq

Edit /etc/dnsmasq.conf adding your preferred DNS and the interface:

bogus-priv
server=8.8.8.8
server=8.8.4.4

listen-address=127.0.0.1

“bogus-priv” tells dnsmasq never forward reverse-lookup queries which have local subnet ip rage to upstream. Which means ‘nslookup 192.168.0.1’ will not be forwarded to upstream instead dnsmasq will try to resolv itself. If it doesn’t find hostname for 192.168.0.1 in /etc/hosts then it will send back ‘no such domain’ response.

On /etc/resolv.conf whatever you put on /etc/network/interfaces you will find your loop-back interface as DNS. This because resolvconf put 127.0.0.1 when dnsmasq start.
Tu append some other nameserver entries on resolv.conf after 127.0.0.1 edit the file /etc/resolvconf/resolv.conf.d/tail:

nameserver 192.168.1.1

and then run

resolvconf -u

to update the configuration.
If you whant to append nameserver entrie before 128.0.0.1, use instead this file:
/etc/resolvconf/resolv.conf.d/head

For testing purposes, run can run dnsmasq with this options:

dnsmasq --no-daemon --log-queries

Via: https://wiki.debian.org/HowTo/dnsmasq
https://wiki.archlinux.org/index.php/Dnsmasq
https://mohan43u.wordpress.com/2012/08/06/dnsmasq-for-home-user/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s