How to clear DNS cache in 18.04

Solution 1:

This should clear it

# sudo systemd-resolve --flush-cache

You can check with

# sudo systemd-resolve --statistics
  • it should show 0 in Current cache size

    DNSSEC supported by current servers: no
    Transactions
    Current Transactions: 0
    Total Transactions: 93750
    
    Cache
      Current Cache Size: 0
      Cache Hits: 18686
    Cache Misses: 28576
    
    DNSSEC Verdicts
          Secure: 0
        Insecure: 0
           Bogus: 0
    Indeterminate: 0
    

Solution 2:

Maybe this version also has two (2) DNS caches, like Ubuntu 20.10.

Please check the full tutorial to flush DNS caches:

https://askubuntu.com/a/1315569/136919