Flush Your DNS Cache and You Clear One Program's Copy
How-To
Your machine is holding DNS answers in more than one place. A one-line command empties one of those places and leaves every other copy sitting where it is. Knowing which place you emptied is the whole difference between a fix and a ritual.
Which program is holding the answer
On Windows the owner has a name. Microsoft’s reference page for the ipconfig command describes two of its parameters next to each other. The first of the pair, /displaydns, shows “the contents of the DNS client resolver cache, which includes both entries preloaded from the local Hosts file and any recently obtained resource records for name queries resolved by the computer”. Immediately below it comes the sentence that identifies the owner: “The DNS Client service uses this information to resolve frequently queried names quickly, before querying its configured DNS servers.”
Two separate facts fall out of that. A named service holds the store, rather than the operating system at large or the browser you were using when the trouble started. And the store is mixed, because some of what sits in it arrived over the network and some of it was read off a file on the disk. A flush makes no distinction between the two origins, and the stricter case of something settled before any lookup happens is a name reserved rather than resolved.
Where systemd is running the owner has a name too. The manual page for systemd-resolved, the name-resolution service that ships with systemd, says in its opening description that “It implements a caching and validating DNS/DNSSEC stub resolver”. It answers for two local-network protocols alongside ordinary DNS, and the control tool shipped with it reports what is held “per scope”.
That last phrase decides the rest of this. Inside a single program the store is already divided, so the useful unit is not the cache. It is the program.
The command beside the one you were sent for
The flush parameter, /flushdns, has a neighbour in the same table. Microsoft gives it two sentences. “Flushes and resets the contents of the DNS client resolver cache”, and then “During DNS troubleshooting, you can use this procedure to discard negative cache entries from the cache, as well as any other entries that have been added dynamically.” The first names the scope. The second names the purpose, and that purpose is troubleshooting rather than housekeeping.
That second sentence also names a kind of entry the first leaves undistinguished, one recording that a lookup failed. Why a failure gets stored like any other answer belongs to the lookup itself, not to the clearing of it.
The same vendor documents a second route to it. A PowerShell command, Clear-DnsClientCache, described as one that “deletes all the contents of the DNS client cache”, is listed as equivalent to the command-line form, and the page for it carries exactly one related link. It points at Get-DnsClientCache, which gets the cache instead of clearing it.
The resolver service on Linux lists its pair the same way. In the manual page for resolvectl, its control tool, the flush-caches entry reads “Flushes all DNS resource record caches the service maintains locally”, and show-cache, in the same list of commands, gets six words: “Show current cache content, per scope”. The service’s own manual page adds a third route, in which a signal makes it “dump the contents of all DNS resource record caches it maintains, as well as all feature level information it learnt about configured DNS servers into the system logs”.
Four documents, two implementations, and in each of them the command that empties is listed beside a command that shows. Only one of the two destroys anything, and only that one needs you to have been right about the problem before you ran it.
Clearing everything is not the only option
A single lookup can be told to ignore the store instead. The same control tool accepts a per-query option governing cache use, named and explained on its own manual page, and the behaviour arrives in two sentences: “If true (the default), lookups use the local DNS resource record cache. If false, lookups are routed to the network instead, regardless of whether already available in the local cache.” That is a narrower instrument. It tells you what the answer would be with nothing in the way, without discarding what is there to find out.
The service also says the blunt version is normally unnecessary. Describing the signal that empties everything, its manual page notes that “it should normally not be necessary to request this explicitly”, and supplies the reason: “as systemd-resolved flushes the caches automatically anyway any time the host’s network configuration changes”. Joining a different network is a configuration change, and so is a tunnel coming up or going down. On that reading the ordinary case has already cleared itself before anybody typed anything.
One documented route does more than you asked for. A different signal makes the service “flush all caches it maintains, drop all open TCP connections (if any), and reload its configuration files”, which is three operations where you wanted one. The same page prefers the control tool to signals in any case, on the stated ground that “the latter is recommended since it operates in a synchronous way”. A command that has finished when it returns is worth more than a signal that has merely been delivered.
Not everything a service remembers is an answer. The same manual page documents a third signal, which makes systemd-resolved “forget everything it learnt about the configured DNS servers”. What that discards is not names: “any information about server feature support is flushed out, and the server feature probing logic is restarted on the next request, starting with the most fully featured level”. So a single program is holding at least two categories of remembered state, the answers it has been given and what it has learnt about the servers it asks, and the command that clears one of them leaves the other untouched. A flush is not even a complete clearing of the one program you aimed it at.
What a flush does not reach
The store you cleared sits in front of other stores. Microsoft’s own wording puts it there, since the service answers from what it holds “before querying its configured DNS servers”. Those configured servers are another party’s software, running on hardware you do not own, and nothing typed at your own prompt reaches what they are holding. A name whose record has just changed can keep coming back stale from them, and which party is on the receiving end is a setting, not a command.
Two consequences follow. Clearing locally changes what your machine holds. It changes nothing about what the party after it holds, and you have no command that reaches it.
Put the other way round, emptying the store does not make your machine right about anything. It makes your machine ask. Whatever comes back is the answer the next party in line is currently prepared to give, so the question after a flush is less whether it worked than who answered.
Take the reading before you clear anything. One of our own pages is built in that order, telling you to note the values it shows, make the change you are making, then come back and run it a second time. For a destructive command that sequence is not a nicety, because the earlier reading is the only thing a later one can be compared against, and once the store is empty you cannot go back and take it. If you are about to throw state away in order to fix something, start with a page whose own procedure puts the reading first.
Doing it in a useful order
The sequence that wastes least of your time runs in the same order the documentation does. Look at what is held, because both implementations above document a way to see it. Decide whether the entry you are worried about is in there at all. Then clear it, or route one lookup past it and leave the rest alone.
It will not make anything faster. Every name you had stored now has to be fetched again, which is slower until the store refills. Whether that costs you anything you would notice is not something our own figures can answer, because they cover two transfer rates and a round-trip time, and name resolution is not among what a browser-to-edge measurement does report.
A one-line command is the right tool when a machine is holding something you know to be wrong. It is a poor tool for working out whether that is the case, and that job belongs to the command listed next to it.