[Dnsmasq-discuss] Is there any method to flush dnsmasq's cache without interrupt service

Albert ARIBAUD albert.aribaud at free.fr
Fri Mar 21 08:36:58 UTC 2014


Le 21/03/2014 08:27, 胡文峰 a écrit :

(can you please reply after, rather than before, what you are replying 
to? This makes reading the whole discussion a lot easier.)

> Sorry Sir.
> But /etc/init.d/dnsmasq reload do not flush cache, neither do SIGHUP.
> I am using Centos 5.8 64bit with package dnsmasq-2.45-1.1.el5_3 .
> Searching the man dnsmasq, there seems one method: enable dnsmasq option
> --clear-on-reload and update /etc/resolv.conf file , but this is just a
> workaround!

Please add log-queries to your dnsmasq configuration, then try the 
following:

- restart dnsmasq

- query some domain name twice

- send SIGHUP to dnsmasq

- query the same domain name again twice

Then  verify in syslog how dnsmasq resolved the domain; you'll see which 
queries are forwarded and which ones are cached.

Instead of adding log-queries to your dnsmasq configuration and 
restarting it, you can also just stop the dnsmasq service then launch it 
manually with

	dnsmasq -q -d

Which will run dnsmasq as a normal app (not a background daemon) in your 
terminal and make it log there (in addition to the usual syslog). Then 
you can immediately see the effects of DNS queries done in another terminal.

Of course, once the tests are done, you have to break execution and then 
start the service again (or, if you opted to modify your config, you 
have to remove the log-queries option and restart the service).

In my case, this test gives the following result, where "thedomain" is 
the queried FQDN, and X.Y.Z.T is its address, both changed to protect 
the innocent:

# dnsmasq -q -d
[...]
(from 192.168.128.3, dig thedomain)
dnsmasq: query[A] thedomain from 192.168.128.3
dnsmasq: forwarded thedomain to 127.0.0.1
dnsmasq: reply thedomain is X.Y.Z.T
(from 192.168.128.3, dig thedomain)
dnsmasq: query[A] thedomain from 192.168.128.3
dnsmasq: cached thedomain is X.Y.Z.T
[...]
(killall -HUP dnsmasq)
[...]
dnsmasq: read /etc/dnsmasq.conf.hosts - 30 addresses
dnsmasq-dhcp: read /etc/dnsmasq.conf.leases
[...]
(from 192.168.128.3, dig thedomain)
dnsmasq: query[A] thedomain from 192.168.128.3
dnsmasq: forwarded thedomain to 127.0.0.1
dnsmasq: reply thedomain is X.Y.Z.T
(from 192.168.128.3, dig thedomain)
dnsmasq: query[A] thedomain from 192.168.128.3
dnsmasq: cached thedomain is X.Y.Z.T

Amicalement,
Albert.

> ------------------------------------------------------------------------
> JasonHu/胡文峰
> Mail: JasonHu at boyaa.com <mailto:JasonHu at boyaa.com>
> 深圳市东方博雅科技有限公司
> Boyaa Interactive
> --------------------------------
> *From:* Dnsmasq-discuss
> <mailto:dnsmasq-discuss-bounces at lists.thekelleys.org.uk>
> *Date:* 2014-03-21 15:17
> *To:* dnsmasq-discuss at lists.thekelleys.org.uk
> <mailto:dnsmasq-discuss at lists.thekelleys.org.uk>
> *Subject:* Re: [Dnsmasq-discuss] Is there any method to flush dnsmasq's
> cache without interrupt service
>
> Le 21/03/2014 07:59, 胡文峰 a écrit :
>  > HI friends:
>  > I want to flush the dnsmasq cache under some conditions! But when I run
>  > /etc/init.d/dnsmasq restart, the dns service got interrupted for 1-2
>  > seconds!
>  > So I wonder is there any methods to ask dnsmasq to drop all the cache
>  > without interrupt the dns service?
>
> Send a SIGHUP message to the running dnsmasq instance. Maybe
> /etc/init.d/dnsmasq reload will do that on your system, or you can just
> kill -HUP the PID of your dnsmaq instance or killall -HUP dnsmasq.
>
> Other methods exist; see 'man dnsmaq' and search for 'cache'.
>
>  > Best Regards!
>
> Amicalement,
> --
> Albert.



More information about the Dnsmasq-discuss mailing list