Jack Wallen shows you how to flush the DNS cache on your Ubuntu Servers to avoid DNS-released networking issues.

Image: gonin/Adobe Stock

Sometimes a network connection doesn’t seem to function how we expect them to. And it doesn’t matter how much you troubleshoot the issue, the problem doesn’t go away. You’ve configured a static IP address, you know that configuration is solid and you can ping your gateway, but something is causing that Linux server from reaching the outside world in the manner you expect.

One problem could be the DNS cache. DNS is a crucial aspect of networking for all machines, as it translates names to IP addresses. When something goes wrong with DNS, your machine might have trouble reaching the outside world. I have experienced, on a few occasions, a DNS cache to be the problem. When that happens, what do you do? You flush the DNS cache.

This is a good task to undertake now and then, as your DNS cache can not only grow too large, but it could also contain corrupt entries (which can cause problems with connections). So, how do you flush the DNS cache on Ubuntu Server?

SEE: Hiring Kit: Network Engineer (TechRepublic Premium)

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:


Current Transactions: 0

Total Transactions: 3520


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.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Source link