DNS Caching in Linux

Introduction

Many new Linux adopters are surprised to find that most Linux distributions do not cache DNS look-ups by default. You can easily install a DNS caching program yourself and reap the performance benefits that comes with it. I have decided to use the popular lightweight program, Dnsmasq, with a configuration for use with a desktop Linux system. There are other tools to accomplish DNS caching such as: pdnsd, that you may want to research[1]. I choose to use Dnsmasq since there have been releases as recent as May 2016.

Dnsmasq

Dnsmasq is available on most Linux distributions. The Arch wiki has a great article about the configuration needed to get it up and running. You may need to set listen-address=127.0.0.1 in /etc/dnsmasq.conf to only listen on your localhost.

Tweaking for Performance

The default configuration only stores 150 of the latest DNS results in the cache. You may raise this number by editing /etc/dnsmasq.conf and un-commenting the line cache-size and setting it to a more appropriate number, like 5000. I also un-commented the lines for domain-needed and bogus-priv.

Additional Links

Man Page


  1. Comparison of DNS server software (Wikipedia) ↩︎