How can I see systemd-resolve dns cache?

5,139

As mentioned by bac0n, you can use the following command to send signal USR1 to systemd-resolved:

sudo killall -USR1 systemd-resolved

This will NOT stop the service. It just tells systemd-resolved to write all the current cache entries (and some other information) to the system log.

You can then export the log messages written by systemd-resolved to a text file with the following command:

sudo journalctl -u systemd-resolved > ~/resolved.txt

Open the text file generated this way in the text editor of your choice and search for CACHE:. After this the list of cache entries will follow.

Please note that the text file might contain several CACHE:.

Share:
5,139
johhnry
Author by

johhnry

Updated on September 18, 2022

Comments

  • johhnry
    johhnry over 1 year

    Using sudo systemd-resolve --statistics let me see the current dns cache statistics, for example :

    Cache                     
      Current Cache Size: 68  
              Cache Hits: 412 
            Cache Misses: 461
    

    I would like to see all the entries of the dns cache (here 68), is it possible?

    • bac0n
      bac0n almost 4 years
      think you can do: killall -USR1 systemd-resolved (the output will be redirected to journald)
    • johhnry
      johhnry almost 4 years
      But this is going to kill the process rather than printing the cache?
    • bac0n
      bac0n almost 4 years
      no, it wil just sending SIGUSR1 to systemd-resolved, you can find a description in man systemd-resolved
  • johhnry
    johhnry over 3 years
    Thanks a lot, this is helpful!