How does one clear dig's DNS cache on Ubuntu?

6

1

I'm trying to use dig to verify some DNS information, but I'm only seeing old results. From what I've read, Ubuntu doesn't cache DNS by default at an OS level. If that's true, then the dig command has its own DNS cache. Presumably, installing a universal DNS cache like NSDC would not prevent dig from using its own cache, so my question is how do I clear the cache used by the dig command?

I realize that DNS information may not propagate right away, but if I dig @8.8.8.8 for example, I get updated results. However, using dig normally on the same domain multiple times will reveal that all results besides the first take 0ms, so clearly there is caching going on at some level.

Edit: Here is the summary from dig superuser.com on the first try:

;; Query time: 233 msec
;; SERVER: 208.109.188.1#53(208.109.188.1)
;; WHEN: Tue Apr 24 10:09:19 2012
;; MSG SIZE  rcvd: 113

and the second try:

;; Query time: 0 msec
;; SERVER: 208.109.188.1#53(208.109.188.1)
;; WHEN: Tue Apr 24 10:09:58 2012
;; MSG SIZE  rcvd: 113

Zeus

Posted 2012-04-24T15:59:35.683

Reputation: 163

Answers

9

dig has no cache of its own, unless you run some caching daemon locally such as nsdc or dnsmasq etc. if you do you just need to restart these daemons to clear the local cache. you can use +trace to see exactly where the results are coming from.

johnshen64

Posted 2012-04-24T15:59:35.683

Reputation: 4 399

1If I use +trace, it skips the cache and gives me up-to-date results, so that doesn't help me figure out where the cache is. It does reinforce my knowledge of a cache though, since I can immediately try the request again without +trace and still get the old results. I've checked my running processes and checked whether every caching daemon I know of is installed and I'm not finding anything. – Zeus – 2012-04-24T17:01:17.447

if you have a local cache, dig result should show the local loop ip 127.0.0.1 or something similar. what is the output of a plain dig that you are seeing? – johnshen64 – 2012-04-24T17:06:14.160

Edit: I put the results in original question, since I can't do code blocks in comments. – Zeus – 2012-04-24T17:10:33.520

caching does not seem to be done on your local system so you don't have local dns cache, but at your dns server. – johnshen64 – 2012-04-24T17:13:30.970

If that's true, shouldn't a traced dig still give me the results cached on my DNS server? – Zeus – 2012-04-24T17:15:39.223

seems it should. i have local dns cache and +trace has the cache server result included, but while tracing it may have updated its cache? – johnshen64 – 2012-04-24T17:24:15.687

1It seems that it was indeed the server. I switched my DNS servers in /etc/resolv.conf to some with shorter cache lifetimes and now I get more up-to-date results. Thanks for your help. Upvote and accepted answer for you. – Zeus – 2012-04-24T17:30:47.787

0

If you see nameserver 127.0.0.1 in your /etc/hosts file, replace the line with another nameserver such as nameserver 8.8.4.4 and uninstall the package resolvconf (for Ubuntu: apt-get remove resolvconf). This worked for me.

Sorin Surdu Bob

Posted 2012-04-24T15:59:35.683

Reputation: 1