Skip to main content
GrN.dk

Main navigation

  • Articles
  • Cases
  • Contact
  • Your Digital Project Manager
  • About Greg Nowak
  • Services
  • Portfolio
  • Container
    • Excel Freelancer
    • Kubuntu - tips and tricks
    • Linux Apache MySQL and PHP
    • News
    • Image Gallery
User account menu
  • Log in

Join my community / free newsletter — sign up here

Breadcrumb

  1. Home

How to Flush the DNS Cache on Ubuntu Linux

By Greg Nowak. Last updated 2026-07-10.

When a website, mail service, or API still resolves to its old address after a cutover, “flush DNS” is the familiar advice. It may be the right move, but only if the stale answer is coming from the Ubuntu machine’s local cache.

On standard Ubuntu 24.04 LTS and 26.04 LTS installations using systemd-resolved, clearing that cache takes one command. Agency laptops, inherited servers, containers, VPNs, and customised environments may have another resolver in the path. The practical job is therefore to identify the component answering the query, clear the appropriate cache, and verify the result from the runtime that matters.

The quick command for current Ubuntu systems

If the machine uses systemd-resolved, run:

sudo resolvectl flush-caches

Then request a fresh network lookup that does not use the local DNS resource-record cache:

resolvectl --cache=no query example.com

Replace example.com with the affected hostname. This bypasses the cache maintained by systemd-resolved; it does not bypass a cache at your router, VPN, company DNS server, ISP, or other upstream resolver.

Confirm which resolver is actually in use

Before changing services on a production host, inspect the resolution path:

readlink -f /etc/resolv.conf
resolvectl status
systemctl is-active systemd-resolved nscd dnsmasq
grep '^hosts:' /etc/nsswitch.conf

If /etc/resolv.conf resolves to /run/systemd/resolve/stub-resolv.conf, or contains 127.0.0.53, local DNS requests are normally passing through systemd-resolved. Its status output also shows the DNS servers and routing domains assigned globally and to each network interface. That is particularly useful when a VPN supplies DNS for only part of your namespace.

The hosts: entry in /etc/nsswitch.conf shows how normal application lookups are ordered. Remember that /etc/hosts can override an upstream DNS answer; clearing a DNS cache will not remove that mapping.

What you find Likely answering layer Next action
127.0.0.53 or the systemd stub file systemd-resolved Flush with resolvectl
nscd is active nscd hosts cache Invalidate the hosts table
dnsmasq is active and clients use it dnsmasq Send its documented HUP signal
A fresh host lookup is correct but the application is stale Application, browser, container, or proxy Test and clear that layer
Fresh lookups are stale across several networks Authoritative or upstream DNS Check the zone, TTL, and resolver path
A compact decision matrix for choosing the cache to investigate.

Flush the resolver you found

systemd-resolved:

sudo resolvectl flush-caches
resolvectl statistics

Current Ubuntu documentation notes that systemd-resolved already clears its caches when network configuration changes. Manual flushing is mainly useful during troubleshooting or immediately after a controlled DNS change. On supported 24.04 and 26.04 installations, you can also inspect locally cached records with:

resolvectl show-cache

nscd: if the Name Service Cache Daemon is installed, invalidate its hosts database:

sudo nscd -i hosts

dnsmasq: its documented SIGHUP handling clears the cache and reloads host-related files. For a systemd-managed instance, the signal can be sent with:

sudo systemctl kill --signal=HUP dnsmasq

Use your approved service procedure on a managed server. A HUP does not reload the main dnsmasq configuration file, and dnsmasq may also be providing DHCP, so do not substitute an unplanned restart during an incident.

Verify the cutover, not just the command

A successful command produces little business value unless the affected service now reaches the intended destination. Use a short verification sequence:

  1. Check the authoritative answer. If dig is installed, identify the domain’s nameservers and query one directly:
    dig +short NS example.com
    dig @AUTHORITATIVE_NAMESERVER example.com A +noall +answer
  2. Bypass the local resolved cache.
    resolvectl --cache=no query example.com
  3. Test the normal application lookup path.
    getent ahosts example.com
  4. Test the real dependency. Open the website, run the API client, exercise the webhook, or test mail delivery from the machine and network where the failure occurred.

If the authoritative answer is correct but an upstream resolver returns the old value, the previous record may remain cached until its TTL expires. Flushing the Ubuntu host cannot force that external cache to refresh early.

When flushing does not solve the problem

Check for an /etc/hosts override, split DNS supplied by a VPN, a different resolver inside a container or virtual machine, browser or application caching, and proxies that resolve names independently. Run the diagnostic from inside the affected container or application environment when possible; testing only from the host can produce a reassuring but irrelevant result.

For client launches and infrastructure changes, record the authoritative value, expected TTL, active resolver, verification commands, and rollback owner in the runbook before the change begins. That turns “try flushing DNS” into a repeatable operational check.

Make the next cutover calmer

If DNS troubleshooting is exposing incomplete runbooks, unclear ownership, or fragile delivery processes, talk to Greg about practical technical operations support.

Related on GrN.dk

  • Sending Mail From a Linux Server with Postfix: A Practical Setup Guide
  • Ubuntu Server Dashboards and Monitoring Tools: When to Use Cockpit, Monit, ISPConfig, or Landscape
  • WordPress Cron: When to Replace WP-Cron with Server Cron

Need help with this kind of work?

Talk to Greg about practical technical operations support Get in touch with Greg.

Sources

  • Ubuntu 26.04 LTS resolvectl manpage
  • Ubuntu 26.04 LTS systemd-resolved manpage
  • Ubuntu 26.04 LTS dnsmasq manpage
  • Ubuntu 24.04 LTS nscd manpage
Last modified
2026-07-10

Tags

  • Ubuntu
  • Linux
  • DNS
  • Operations

Review Greg on Google

Greg Nowak Google Reviews

 

Illustrated infographic summarizing: AI crawler policy now has verbs: separate search, RAG, and training
AI crawler policy now has verbs: separate search, RAG, and training
2026-08-02

AI crawler rules now need separate decisions for search, RAG, and training, backed by practical testing across robots.txt, CDNs, WAFs, and CMS controls.

Illustrated infographic summarizing: WordPress Supports Old PHP; Your Production Server Shouldn’t
WordPress Supports Old PHP; Your Production Server Shouldn’t
2026-08-01

WordPress still runs on legacy PHP, but compatibility is not a security policy. Build and test your upgrade path before PHP 8.2 support ends.

Illustrated infographic summarizing: The AI-built tool your team relies on needs an owner
The AI-built tool your team relies on needs an owner
2026-07-31

AI-built internal tools can become business-critical before anyone owns them. Here is how to secure, review, monitor, and retire them without blocking useful work.

Illustrated infographic summarizing: Your AI model has an expiry date: build the migration lane now
Your AI model has an expiry date: build the migration lane now
2026-07-30

AI models retire on a schedule. Learn how to map dependencies, test replacements, release safely and preserve a working rollback route.

Illustrated infographic summarizing: Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
2026-07-29

GitHub’s repo-level Copilot metrics show where AI is active, but not whether it adds value. This scorecard connects usage with delivery, quality, and cost.

Illustrated infographic summarizing: Not Every AI Job Needs an Instant Answer: Batch the Backlog
Not Every AI Job Needs an Instant Answer: Batch the Backlog
2026-07-28

Move delay-tolerant AI work into dependable batch queues to cut processing costs without compromising quality, data controls, or urgent workflows.

Illustrated infographic summarizing: A stray Set-Cookie can waste your CDN: audit the cache at the edge
A stray Set-Cookie can waste your CDN: audit the cache at the edge
2026-07-27

Cloudflare Cache Response Rules can recover wasted CDN capacity, but first you need a route-level audit of public, personal and authenticated responses.

Illustrated infographic summarizing: Shorter TLS certificates expose every renewal you never automated
Shorter TLS certificates expose every renewal you never automated
2026-07-26

Shorter TLS lifetimes leave less room for manual handoffs and faulty deploy hooks. Build a renewal path that protects service availability.

Illustrated infographic summarizing: One Timeout, Two Orders: Make AI Actions Safe to Retry
One Timeout, Two Orders: Make AI Actions Safe to Retry
2026-07-25

A timed-out AI action may already have succeeded. Stable keys, durable ledgers, queues and stored results prevent a routine retry from duplicating real work.

Illustrated infographic summarizing: Your AI Visibility Dashboard Needs a Methodology, Not More Charts
Your AI Visibility Dashboard Needs a Methodology, Not More Charts
2026-07-24

A practical framework for measuring AI-search visibility with fixed prompts, repeated tests, separate metrics, retained evidence, and honest reporting.

More articles
RSS feed

GrN.dk web platforms, web optimization, data analysis, data handling and logistics.