What you’ll need
The only thing you’ll need to flush the DNS cache on your Ubuntu Server is a user with sudo privileges. With that user at the ready, let’s get to the flushing.
How to flush your DNS cache
Once upon a time, the DNS cache was flushed with a command like:
sudo systemd-resolve --flush-caches
The above command will still work on Ubuntu 20.04. But if you’ve upgraded to Jammy Jellyfish (22.04), the process has changed. This new command is backward compatible with 20.04
First, let’s view the statistics of our DNS cache with the command:
resolvectl statistics
You should see output similar to this:
Transactions
Current Transactions: 0
Total Transactions: 3520
Cache
Current Cache Size: 1
Cache Hits: 9
Cache Misses: 1388
DNSSEC Verdicts
Secure: 0
Insecure: 0
Bogus: 0
Indeterminate: 0
To flush the cache, issue the command:
resolvectl flush-caches
You should see the Cache Size entry reset to 0.
Believe it or not, that’s all there is to flush a DNS cache in Ubuntu. This works for both Ubuntu Server and Ubuntu Desktop. If you’ve gone down a network troubleshooting rabbit hole and nothing seems to work, you might try flushing the DNS cache and see if that doesn’t resolve your problem.