How To Flush DNS Cache On Ubuntu Server

Jack Wallen shows you how to flush the DNS cache on your Ubuntu servers to avoid DNS-related network issues.

Image: gonin/Adobe Stock

Sometimes a network connection does not seem to work as we expect. And no matter how hard you solve the problem, the problem does not go away. You’ve configured a static IP, you know the configuration is solid, and you can ping your gateway, but something is preventing that Linux server from reaching the outside world the way you expect.

A problem could be the DNS cache. DNS is a crucial aspect of networking all machines, as it translates names into IP addresses. If there’s a problem with the DNS, your machine may have trouble reaching the outside world. I encountered, a few times, a DNS cache like problem. When this happens, what do you do? You flush the DNS cache.

This is a good task to undertake from time to time, as your DNS cache may not only grow too large, but it may also contain corrupted entries (which may cause connection issues). So, how to flush DNS cache on Ubuntu Server?

SEE: Recruitment Kit: Network Engineer (TechRepublic Premium)

What you will need

The only thing you will need to flush the DNS cache on your Ubuntu server is a user with sudo privileges. With that user ready, let’s get to rinsing.

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 upgraded to Jammy Jellyfish (22.04), the process has changed. This new command is backward compatible with 20.04.

Let’s first see 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 clear the cache, run 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 flushing a DNS cache in Ubuntu. It works for both Ubuntu Server and Ubuntu Desktop. If you’ve run into a network troubleshooting rabbit hole and nothing seems to be working, you can try flushing the DNS cache and see if that doesn’t fix your problem.

Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.


Source link

Steven L. Nielsen