[Dnsmasq-discuss] dnsmasq cache dump

Sung Pae self at sungpae.com
Mon Feb 11 09:45:46 GMT 2013


On Mon, Feb 11, 2013 at 09:11:47AM +0000, Simon Kelley wrote:

> On 11/02/13 09:02, trang dang wrote:
>
> > Hello,
> >
> > I use dnsmasq 2.63 on debian, only dns is on, and want to read cache
> > dump with a small script. Till now the cache dump has been written
> > in extra log file (log-facility is on) or in syslog. Is there any
> > way to get an extra cache file? It will be easier to parse the
> > content of the cache. Furthermore, the host name in the log is cut
> > after about 39 characters. Is there any way to get the complete
> > content?
>
> There's not way to do either of those, sorry. You best bet is probably
> to start hacking on the existing cache dumping code in src/cache.c to
> make it do what you want.

I did exactly this about a month ago:¹

https://github.com/guns/dnsmasq/commit/13ac5ace736a5d24c629d8cadc65eda92ea443cb.patch

This adds a `--hosts-cache=<path>` option that dumps the current cache
to <path> in hosts file format on SIGUSR1.

If anyone is curious why I would want such a feature, I am using the
information to construct firewalls for children (e.g. visit pbs.org,
browse around, dump hosts to file, then add them to child's outbound
firewall rules). There are other ways to go about this, but I found this
to be straightforward.

It also happens to be useful for navigating to sites whose DNS entries
have been recently hijacked, which has become a frightening reality in
recent years.

    guns

¹ Patched against v2.65; it needs a manual merging for current git HEAD



More information about the Dnsmasq-discuss mailing list