How do I enable DNS caching in the NetworkManager-controlled dnsmasq?
In Ubuntu 12.10 you can enable the cache of the NetworkManager-controlled dnsmasq instance by putting the line
cache-size=1000
(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.
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.
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:
#!/bin/bash
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!