web servers

How to Clear DNS Cache on Linux

Last modified: May 12, 2026

FAQ
Fiverr freelancers

Sometimes you need to clear the DNS cache on your Linux computer. This is very similar to clearing the DNS cache on a Mac or Windows computer. In this article we look at the ways you can clear the cache.

Show More

* This button will show the rest of the post and open up an offer from a vendor

What is DNS Caching

Before clearing the DNS cache, it helps to understand why it exists and what goes wrong with it.

DNS (Domain Name System) is the system that translates domain names into IP addresses. When you type a website address into your browser, DNS looks up the IP address of that site’s server and connects you to it. Without DNS, you’d have to memorize numerical IP addresses for every site you visit.

DNS caching stores recent lookup results on your computer so that repeat visits to the same site are faster. Instead of querying a remote DNS server every time, your computer checks its local cache first. This reduces load times and reduces the number of DNS queries going out over your network.

The problem comes when a cached record becomes outdated or corrupted. This is common in a few specific situations:

  • A website has moved to a new server and the IP address changed
  • You’ve just migrated a WordPress site to a new host
  • Your ISP has returned a cached “site not found” result that no longer applies
  • You changed your domain’s DNS records and the old record is still cached locally

In these cases, clearing the DNS cache forces your computer to fetch a fresh record, which resolves the issue.

How to Clear the DNS Cache on Linux (Ubuntu)

Modern Ubuntu systems (Ubuntu 18.04 and later) use systemd-resolved as the DNS resolver. The cache is held by this service, not by the operating system itself, so you run the flush command against systemd-resolve.

The steps below apply to Ubuntu 18.04, 20.04, 22.04, and 24.04. If you’re using an older Ubuntu version or a different distribution, see the “Other Distributions” section below.

Step 1 – Terminal

Open Terminal on your Ubuntu system. The fastest way is the keyboard shortcut Ctrl + Alt + T, which opens a new Terminal window directly.

You can also open it from the application menu: click Activities in the top-left corner of the desktop, type terminal into the search bar, and press Enter when the Terminal icon appears. This method works on both GNOME and most other Ubuntu desktop environments.

Step 2 – Code

Once Terminal is open, run the following command:

sudo systemd-resolve --flush-caches

You will be prompted to enter your sudo (administrator) password. Type it and press Enter. The command will execute silently — no output means it worked.

To verify the cache was cleared, run:

systemd-resolve --statistics

Look for the line that says Current Cache Size:. If it shows 0, the flush worked. You can also check the “Cache Hits” and “Cache Misses” counters to confirm activity has reset.

Other Distributions

The command varies depending on which Linux distribution you’re running. Here are the correct commands for the most common distros:

Ubuntu 16.04 and older (uses nscd or dnsmasq):

sudo /etc/init.d/dns-clean start

Or if using nscd:

sudo service nscd restart

CentOS, RHEL, and Fedora (uses nscd):

sudo systemctl restart nscd

If nscd is not installed, install it first: sudo yum install nscd (CentOS/RHEL) or sudo dnf install nscd (Fedora).

Debian:

sudo systemctl restart nscd

Some Debian setups use dnsmasq instead:

sudo systemctl restart dnsmasq

Arch Linux (uses systemd-resolved by default):

sudo systemd-resolve --flush-caches

If you’re not sure which DNS resolver your system is using, run systemctl list-units | grep dns to see which DNS-related services are active.

Final Word: How to Clear DNS Cache on Linux

Clearing the DNS cache on Linux takes only a few seconds once you know which command to use. The right command depends on your distribution and which DNS resolver it uses — but for most modern Ubuntu and Arch systems, sudo systemd-resolve --flush-caches handles it. For CentOS, RHEL, Fedora, and Debian, restarting the nscd or dnsmasq service does the same job.

If you’re looking to learn more about operating a WordPress website, check out the other articles within our WordPress FAQ pages. If you’re considering WordPress hosting, you can also check out our hosting pages here.

Recap:
Save 4 Later
Email liked links to yourself

    Stay Updated with WordPress Insights

    Get the latest WordPress tips, theme reviews, and industry deals delivered to your inbox.