Note that Ubuntu uses systemd-resolve from 17.04 and onwards so this answer doesn't apply anymore to recent Ubuntu versions. See "flush DNS cache in Ubuntu 17.04 and higher (18.04)"
By default, DNS is not cached in Ubuntu < 17.04 (but it might be cached in the network or application)
To confirm one way or the other whether
dnsmasq is caching, run
ps ax | grep dnsmasq and look at the running command. Here's a breakdown of my default 13.10 machine:
/etc/NetworkManager/dnsmasq.d is empty by default. So there aren't any overrides coming in there and just to check
--cache-size=0 means what we think it means (instead of an unlimited cache),
man dnsmasq shows:
Set the size of dnsmasq's cache. The default is 150 names.
Setting the cache size to zero disables caching.
dnsmasq can cache DNS, it isn't caching out the box. You can check your machine and various configuration directories to check you're on the same page.
If you are seeing cache issues, this is likely happening in one of a few places:
- Upstream from your computer. Some routers cache. Many corporate networks will cache DNS. Many ISP-run DNS servers and will use their own caches. The only way to guarantee against a network cache is to use a cache you can manually refresh. This is why I like OpenDNS.
- In the client application (notably browsers). Applications can do all sorts of their own caching that Ubuntu has no effect on. How Firefox caches DNS. How to clear Chrome's DNS cache. Other browsers (and applications) might have their own mechanisms.
I'm scraping the barrel here but perhaps you've installed a non-standard DNS server in Ubuntu instead of turning caching on in
dnsmasq. There are many:
dnscache (aka TinyDNS),
pdnsd, Bind9 (and its variants), and more I can't even remember. These will probably be evidenced in
/etc/resolv.conf (with config in /etc/resolvconf/` to autogen that file). The following shows an locally intercepted DNS query:
$ nslookup askubuntu.com
If you're not hitting 126.96.36.199 (or whatever you expect your DNS server to be), check what you are hitting instead. In my case I can see this is just
dnsmasq set up to mirror DNS queries back for LXC, but in your case it might be doing bad cachey things.
If you have done of the listed caches, the process for clearing each varies:
sudo /etc/init.d/nscd reload # nscd
sudo /etc/init.d/named restart # bind9
On a slightly related note, see this to enable caching in