Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

(I am aware that googling this question gives me tons of stuff, but literally none worked) I'm looking for a way to flush the local DNS cache on a Centos 6 system, it is not running any DNS server or anything. I wish to let every DNS query go out to the configured nameserver, even for the duplicate ones. 90% of what I found tells me to

service nscd restart
or reload or
nscd -i hosts
. Well none seems to flush the cache. So I'm wondering if anyone has an idea of how do I do this? Is there some kind of switch in the kernel I need to flip? Or any kind of work around is fine as well. Thanks a lot!

share|improve this question
    
What are you doing to check if the cache has been flushed or not? –  John Mar 11 '13 at 19:18
    
ok it's a bit complicated, I have a program on my system listening on port 53 and forward the DNS queries in certain way, and also a http proxy using localhost as 'DNS server'; on the first query (say wget -e 'http_proxy=localhost:3128' xxx.com) I can see the query is being forwarded correctly, but all subsequent ones are not. If I wait long enough (cache expires), then it'll work again. –  michael.z Mar 11 '13 at 19:24
    
And also I've configured the proxy (squid) to not cache any object, so I'd assume it's the system still caching the answer somehow –  michael.z Mar 11 '13 at 19:27
    
nscd -i hosts -> works everytime. I restarted nscd 3 times in a row and it didn't want to clear the cache. –  Danie Mar 14 '13 at 9:59

3 Answers 3

I'm almost certain it's not the system caching the response - that part (system caching) is only handled by the nscd daemon. Restarting (or stopping entirely) that daemon resets or eliminates OS caching of name service request responses. I'll offer two possibilities, though the custom listener you've set up on port 53 muddies the waters considerably: A)Your system is issuing queries upstream, but the immediate upstream name resolver is caching the response based on either it's settings or the record's TTL. B) Your custom listener is caching responses internally and just handing that response right back to the system when it gets asked again before the cache time has expired.

share|improve this answer
    
Thanks for the input, but the listener does nothing but forward the query and response, it's only like 200 lines of code after all. So shouldn't be the second case; also the listener is printing out everything it receives, so I'm sure it's indeed not getting anything :| –  michael.z Mar 11 '13 at 19:55

Its not your local box which is caching the DNS requests but it is the DNS resolver which you are using in your /etc/resolv.conf who is caching.

To prevent to get those cached queries reply:

  1. Change the resolver.

    $ dig @<resolve-ip> www.google.com

  2. Flush the DNS cache on the resolver, if you can access the DNS server.

    $ sudo /etc/init.d/bind restart

share|improve this answer
    
Hmm but I have set dns_nameservers 127.0.0.1 in proxy config file, and the listener only forwards queries to preconfigured name server, shouldn't it be the case that resolv.conf is not even consulted? –  michael.z Mar 11 '13 at 20:18

Even after refresh or flush of DNS cache on client machine if it doesn't work then look your server or client machine is bound to any NIS server if yes then change the "hosts: files nis dns" to "hosts: files dns nis" entry in /etc/nsswitch.conf file and also you need to change the ip address in NIS master server hosts list.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.