Clearing the local DNS cache on OS X Lion
As someone who works in the hosted services industry, I frequently need to access web sites or other systems that are in the midst of a DNS change.
When a change occurs it’s easy enough to flush the recursive DNS servers that I use, however the operating system itself also caches the DNS results. This means that even though the recursive DNS servers I’m using have the new records, my operating system insists on sending requests to the old IP address.
Ever since I switched to OS X a number of years ago I’ve been using the following command with success:
This all changed when I upgraded to OS X 10.7 “Lion”. The operating system would still return old results regardless of how often I’d execute this command.
After a great deal of frustration I discovered the this operating system sends all DNS requests through an intermediary DNS resolver called “mDNSResponder”. This daemon caches the results, and even if you flush the cache you’ll still receive old results.
To rectify this you need to reload mDNSResponder. To do this, simply run the following command from your terminal:
You will need administrative permissions on your machine to do this.
Once done the cache will be clear and your machine should request fresh records from the DNS resolvers that your machine is using. Note that the DNS resolvers may still be caching outdated records.