• Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
  • Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
Home»Distros»Ubuntu»How To Flush DNS Cache On Ubuntu

How To Flush DNS Cache On Ubuntu

Anup ThapaBy Anup ThapaMarch 13, 2023 Ubuntu 2 Mins Read

The DNS cache is a local database of domain names and addresses that helps speed up name resolution. The records in this cache can sometimes be incorrect/outdated, which leads to various DNS-related network errors. The easiest way to fix such issues is to clear the DNS cache.

Flush DNS on Ubuntu 22.04

Ubuntu handles name resolution and caching with the systemd-resolved service. Rather than directly managing the service, you can use the resolvectl binary to query the DNS records or perform actions like flushing the cache.

First, check the DNS cache stats with

sudo resolvectl statistics

Clear the cache using the flush-caches parameter.

sudo resolvectl flush-caches

Verify the cache’s state again with

sudo resolvectl statistics

Flush DNS on Older Ubuntu Versions

On Ubuntu versions 20.04 and older, systemd-resolve could be directly called to clear the cache. Resolvectl is backward compatible with older Ubuntu versions, so the previous method works too. But you can also flush the cache with this alternative method.

Check the current cache statistics with  

sudo systemd-resolve --statistics

Use the flush-caches option to clear the cache.

sudo systemd-resolve --flush-caches

Verify that the cache was cleared.

sudo systemd-resolve --statistics

Flush Custom DNS Service Cache

If you’re running a custom DNS service like dnsmasq, nscd, unbound, bind, etc., you’ll need to clear their cache separately as well.

For instance, you can flush the dnsmasq cache by sending a hangup signal (SIGHUP) to the dnsmasq process.

sudo killall -HUP dnsmasq

If you’re running dnsmasq as a service, you can instead use

sudo systemctl restart dnsmasq

This was just one example. As there are numerous third-party DNS services to choose from, we recommend referring to the program-specific documentation for instructions on how to clear the cache.

Anup Thapa
  • LinkedIn

Anup Thapa has been using Linux for over 5 years. He has an extensive background in computer hardware and networking. At LinuxStart, Anup is an integral part of our editorial team. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys experimenting with different Linux distros and reading up on things like networking and virtualization.

Leave A Reply Cancel Reply

Table of Contents
  • Flush DNS on Ubuntu 22.04
  • Flush DNS on Older Ubuntu Versions
  • Flush Custom DNS Service Cache
Linux Start
Guides

What is the Linux Kernel?

The Linux Kernel is the core of the Linux operating system and is central to…

How To Install Linux Mint

How To Install Linux on VirtualBox

Getting Started with Linux

How to Install Linux

10 Best Linux Distros of 2023

Which Linux Distro Should You Choose? A Complete Guide to Help You Decide

© 2023 LinuxStart.com

Type above and press Enter to search. Press Esc to cancel.