Flush DNS Cache
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
Mac OS 10.5.2 up to 10.6
Mac OS up to 10.5.1
Linux with Systemd
Older Linux versions
Depending on your distribution:
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 22.214.171.124 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: 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.