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: Drupal 12 Slipped to December. Drupal 10 Still Runs Out of Road
Drupal 12 Slipped to December. Drupal 10 Still Runs Out of Road
2026-08-07

Drupal 12 arrives as Drupal 10 support ends in December 2026. Moving to Drupal 11.3+ first keeps two mandatory upgrades manageable.

Illustrated infographic summarizing: EU OpenAI Residency Is a Migration Project, Not a Dashboard Toggle
EU OpenAI Residency Is a Migration Project, Not a Dashboard Toggle
2026-08-05

An EU-resident OpenAI API setup needs a new project, regional routing, dependency and state migration, compatibility testing, and clear governance evidence.

Illustrated infographic summarizing: AI Images Need a Chain of Custody, Not Just a Disclosure Label
AI Images Need a Chain of Custody, Not Just a Disclosure Label
2026-08-04

AI image labels are only the endpoint. Learn how to test C2PA credentials through editing, CMS, CDN and agency handoffs while preserving evidence.

Illustrated infographic summarizing: MCP Just Went Stateless: Audit the Integrations Behind Your AI Tools
MCP Just Went Stateless: Audit the Integrations Behind Your AI Tools
2026-08-03

The 28 July 2026 MCP release removes protocol sessions and changes discovery, tasks, caching, OAuth and tracing. A practical guide to auditing the move.

Illustrated infographic summarizing: SEO Trends for 2026: What Actually Changed Since 2024
SEO Trends for 2026: What Actually Changed Since 2024
2026-08-03

A practical guide to what changed in SEO between 2024 and 2026, from AI and multimodal search to Core Web Vitals, privacy and local visibility.

Illustrated infographic summarizing: INP and Green SEO Share a Backlog: Cut the Work Every Visit Repeats
INP and Green SEO Share a Backlog: Cut the Work Every Visit Repeats
2026-08-03

INP and sustainable web work often expose the same waste. Use field data, profiling, caching and performance budgets to build one practical backlog.

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.

More articles
RSS feed

Footer

  • All articles
  • Contact

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