Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ubuntu Desktop 12.04 uses dnsmasq to perform DNS lookups, but it is not configured to cache these results. (I have checked this by using dig to resolve names and I do not see a large improvement in the response time after the first lookup.) How do I configure the NetworkManager-controlled dnsmasq to cache the results of DNS lookups?

share|improve this question

In Ubuntu 12.10 you can enable the cache of the NetworkManager-controlled dnsmasq instance by putting the line


(with your preferred number of names instead of 1000) in a new file in /etc/NetworkManager/dnsmasq.d/. To activate this change you must then do

sudo stop network-manager
sudo killall dnsmasq
sudo start network-manager

or reboot.

share|improve this answer
Thank you for your info. For Ubuntu 16.04 (and 15.10 since systemd was introduced), use "sudo service network-manager stop/start" rather than "sudo stop/start network-manager" – Fumisky Wells Jun 12 at 1:59

I was able to enable DNS caching in Linux Mint 13 (based on Ubuntu 12.04) using the method described in the first answer. I created a file /etc/NetworkManager/dnsmasq.d/cachedns containing the line cache-size=100, then restarted network-manager. Even though dnsmasq is executed by network-manager with a hard-coded --cache-size=0 on its command line, setting the cache-size in a config file overrides that value. You can verify that it works by doing this:

sudo killall -USR1 dnsmasq
tail /var/log/syslog

You should see a line that looks like this in the syslog, showing the cache size:

dnsmasq[17808]: cache size 100, 0/2 cache insertions re-used unexpired cache entries.
share|improve this answer
I wondered how network-manager's hard-coded --cache-size=0 was affected, but your post makes me clear. Thank you! – Fumisky Wells Jun 12 at 1:53

I didn't want to upgrade from 12.04, but still wanted dnsmasq managed by NetworkManager with caching enabled, but as the other answer said, --cache-size=0 is hard-coded and can't be changed with configuration.

So what I ended up doing was the following, as root:

mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.real

and then creating a new file, /usr/sbin/dnsmasq with the following content:

args=$(echo "$@" | sed 's/--cache-size=0/--cache-size=1000/')
/usr/sbin/dnsmasq.real $args

make sure you chmod +x /usr/sbin/dnsmasq, and change the cache-size from 1000 to whatever you want, enjoy your LTS release with a DNS cache!

share|improve this answer

in 12.04 dnsmasq is started by NetworkManager with hard-coded (i.e. not configurable) parameter --cache-size=0.

manpages for dnsmasq says setting cache-size to zero disables caching. If you want to enable caching, you will probably have to disable the dnsmasq-plugin for NetworkManager to prevent NetworkManager from starting dnsmasq and start your own instance of dnsmasq with cache-size greater then zero.

here you can read how to disable dnsmasq-plugin for NetworkManager:

share|improve this answer

To re-enable the cache (with a NetworkManager version that has the /etc/NetworkManager/dnsmasq.d directory), it is actually sufficient to drop a file in that directory with content "cache-size=X" (with X being 150 for the default dnsmasq would have). The files in there override the hard-coded parameters given on the commandline.

share|improve this answer

In Ubuntu 14.04, I had to edit /etc/default/dnsmasq and set ENABLED=1

I also put cache-size=1000 there and in all the other dnsmasq config files that I found.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.