Difference between revisions of "Flush DNS Cache"

From Exterior Memory
Jump to: navigation, search
(Negative Caching)
(Linux)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Flush DNS Cache ==
 
== Flush DNS Cache ==
  
=== Mac OS 10.10 and up ===
+
=== Mac OS 10.7 and up (actually 10.7 up to 10.9 and 10.10.4 and up) ===
 
+
discoveryutil udnsflushcaches
+
 
+
=== Mac OS 10.7 up to 10.9 ===
+
  
 
  dscacheutil -flushcache
 
  dscacheutil -flushcache
 
  killall -HUP mDNSResponder
 
  killall -HUP mDNSResponder
 +
 +
=== Mac OS 10.10 up to 10.10.3 ===
 +
 +
discoveryutil udnsflushcaches
  
 
=== Mac OS 10.5.2 up to 10.6 ===
 
=== Mac OS 10.5.2 up to 10.6 ===
Line 22: Line 22:
 
  ipconfig /flushdns
 
  ipconfig /flushdns
  
=== Linux ===
+
=== Linux with Systemd ===
 +
 
 +
systemd-resolve --flush-caches
 +
 
 +
=== Older Linux versions ===
  
 
Depending on your distribution:
 
Depending on your distribution:
Line 51: Line 55:
 
=== Flushing does not help ===
 
=== Flushing does not help ===
  
I've seen a few cases where flushing does not help. In that case, I usually reboot my computer.
+
I've seen a few cases where flushing does not help.
  
 
In one of these cases, the <tt>discoveryutil udnsflushcaches</tt> command would give the following error in <tt>system.log</tt>:
 
In one of these cases, the <tt>discoveryutil udnsflushcaches</tt> command would give the following error in <tt>system.log</tt>:
Line 58: Line 62:
  
 
It seems that in this case, the command from <tt>discoveryutil</tt> never reached <tt>discoveryd</tt>.
 
It seems that in this case, the command from <tt>discoveryutil</tt> never reached <tt>discoveryd</tt>.
 +
 +
In that case, I usually reboot my computer, or <tt>killall discoveryd</tt> in the knowledge that Mac OS X launch daemon will restart <tt>discoveryd</tt>.
 +
 +
[[Category:DNS]]
 +
[[Category:Mac OS X]]
 +
[[Category:Linux]]
 +
[[Category:Windows]]

Latest revision as of 18:17, 28 October 2020

Flush DNS Cache

Mac OS 10.7 and up (actually 10.7 up to 10.9 and 10.10.4 and up)

dscacheutil -flushcache
killall -HUP mDNSResponder

Mac OS 10.10 up to 10.10.3

discoveryutil udnsflushcaches

Mac OS 10.5.2 up to 10.6

dscacheutil -flushcache

Mac OS up to 10.5.1

lookupd -flushcache

Windows

ipconfig /flushdns

Linux with Systemd

systemd-resolve --flush-caches

Older Linux versions

Depending on your distribution:

/etc/init.d/named restart

or

/etc/init.d/nscd restart

Troubleshooting

Negative Caching

ping, or most other programs use the build-in name discovery, with build-in cache. In this case, there is a negative cache:

$ ping www.example.org
ping: cannot resolve www.example.org: Unknown host

host, dig or nslookup do not use the build-in name discovery, but always query an external name server, bypassing any cache at the local host (the name server is likely to still cache the result though).

$ host www.example.org
www.example.org has address 93.184.216.119
www.example.org has IPv6 address 2606:2800:220:6d:26bf:1447:1097:aa7

In this example, the name servers finds the DNS record, but the local host says it does not exist. This is negative caching; a previously 'not found' result is cached. In this case, it is best to flush the local DNS cache and try again.

Flushing does not help

I've seen a few cases where flushing does not help.

In one of these cases, the discoveryutil udnsflushcaches command would give the following error in system.log:

discoveryd[36369]: Basic RemoteControl com.apple.discoveryd XPC connection 0x7fa7a8590860: Connection invalid

It seems that in this case, the command from discoveryutil never reached discoveryd.

In that case, I usually reboot my computer, or killall discoveryd in the knowledge that Mac OS X launch daemon will restart discoveryd.