0

I would like to alter my dnsmasq's cache so when I look for certain domains it'll give me the IP address I want it to serve (not necessarily the actual IP of that domain). It's basically like poisoning my own DNS server but not remotely.

Where is dnsmasq's cache saved? How can I alter it?

1
  • I think you'd just add them to /etc/hosts however I'm not putting this as an answer as I'm not 100% sure. Dec 1 '16 at 8:08
1

The cache is in the memory, not saved to the filesystem. From man dnsmasq:

   The  cache  statistics  are  also  available  in  the DNS as answers to
   queries of class CHAOS and type TXT in domain bind.  The  domain  names
   are   cachesize.bind,   insertions.bind,  evictions.bind,  misses.bind,
   hits.bind, auth.bind and servers.bind.  An  example  command  to  query
   this, using the dig utility would be

   dig +short chaos txt cachesize.bind
1
  • Are you implying one cannot alter the cache in any way?
    – Zach P
    Dec 1 '16 at 9:14
1

You can put those domain names in /etc/hosts. Don't forget to restart dnsmasq, since otherwise it won't reload it.

Dnsmasq reads and uses the data from /etc/hosts, which is one of the reasons I use it. I'm not sure whether it always does that, or it is configurable.

1
  • man dnsmasq, at least on my system, says " When it receives a SIGHUP, dnsmasq clears its cache and then re-loads /etc/hosts". And I've never seen dnsmasq pick up changes in /etc/hosts by itself. I simply restart it, SIGHUP would work too. Jan 16 '21 at 12:30
0

You don't change the dnsmasq's cache content, but prefil it --

Create a .conf file under /etc/dnsmasq.d/, e.g., /etc/dnsmasq.d/dbab.adblock.conf, with the format of

address=/101com.com/192.168.2.101
address=/101order.com/192.168.2.101
...

For details refer to
https://sfxpt.wordpress.com/2015/11/22/dbab-from-start-to-finish/

In the section "Faq: How to blacklist those bad sites".

2
  • What is the difference of prefilling to changing hosts? Jan 16 '21 at 6:45
  • prefil is the best answer to the question of "I would like to alter my dnsmasq's cache so when I look for certain domains it'll give me the IP address I want it to serve"
    – xpt
    Jan 16 '21 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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