TLTR; systemd-resolve –flush-caches

systemd-resolve is a CLI tool for resolving domain names, IPv4 and IPv6 addresses, DNS records and services.

It also provides dns resolution statistics, settings and ability to flush cache. Before flushing cache, check the cache size and hit/miss statistics. Additional information such as transactions count is also reported.

$ sudo systemd-resolve --statistics
DNSSEC supported by current servers: no

Transactions                
Current Transactions: 0     
  Total Transactions: 105240
                            
Cache                       
  Current Cache Size: 15     
          Cache Hits: 50425 
        Cache Misses: 66235 
                            
DNSSEC Verdicts             
              Secure: 0     
            Insecure: 0     
               Bogus: 0     
       Indeterminate: 0     

As you can see above, the cache size is 15. In order to clear or flush the dns cache, run below command –

systemd-resolve --flush-caches

Running systemd-resolve --statistics should show a current cache size of 0.