Jack Wallen shows you how to flush the DNS cache on your Ubuntu servers to avoid network issues with DNS release.
Sometimes a network connection doesn’t seem to work as we expect. And no matter how much you fix the problem, the problem won’t go away. You configured a static IP address, you know the configuration is solid and you can ping your gateway, but something is causing that Linux server to reach the outside world in the way you expect.
One problem could be the DNS cache. DNS is a critical aspect of networking for all machines, as it translates names into IP addresses. If something goes wrong with DNS, your machine may struggle to reach the outside world. I have experienced a few times when a DNS cache was the problem. If that happens, what do you do? You flush the DNS cache.
This is a good job to do every now and then, as not only can your DNS cache get too large, but it can also contain corrupt entries (which can cause connection issues). So, how do you flush the DNS cache on Ubuntu Server?
SEE: Hiring Kit: Network Engineer (Tech Republic Premium)
What you need
All you need to clear the DNS cache on your Ubuntu server is a user with sudo privileges. With that user at the ready, we go to the flushing.
How to clear your DNS cache
Once upon a time, a DNS cache was flushed with a command like:
sudo systemd-resolve --flush-caches
The above command still works on Ubuntu 20.04. But if you upgraded to Jammy Jellyfish (22.04), the process has changed. This new command is backwards compatible with 20.04.
First, let’s take a look at our DNS cache statistics with the command:
resolvectl statistics
You should see an output that looks something like 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
Give the command to clear the cache:
resolvectl flush-caches
You should see the item Reset Cache Size 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 been down a rabbit hole for network troubleshooting and nothing seems to work, you can try clearing the DNS cache and see if that doesn’t fix your problem.
Subscribe to TechRepublic’s How to make technology work on YouTube for all the latest technical advice for business professionals from Jack Wallen.