sudo dscacheutil -flushcache followed by sudo killall -HUP mDNSResponder. This sequence forces the system to discard stale records and restart the name resolution service, ensuring your device fetches fresh IP addresses from your configured DNS servers.
Why Clearing the Cache Matters
The Domain Name System (DNS) translates human-readable domain names like example.com into numerical IP addresses that computers use to communicate. macOS stores these translations in a local cache to speed up future requests. However, this caching mechanism can sometimes become outdated or corrupted. When a website changes its server IP address, or when you move between different Wi-Fi networks with distinct DNS configurations, your Mac might continue using the old, incorrect information stored in memory.
This discrepancy often manifests as connectivity issues where specific websites fail to load, while others work perfectly. You might also experience slow loading times for sites that should be accessible instantly. In some cases, browser errors such as DNS_PROBE_FINISHED_NXDOMAIN appear, indicating that the resolver could not find the record it was looking for. Clearing the cache is a fundamental troubleshooting step that resolves these inconsistencies without requiring complex network reconfiguration.
Step-by-Step Guide for macOS Monterey
macOS Monterey uses a slightly different command structure compared to older versions of the operating system. While previous iterations relied solely on restarting the mDNSResponder service, Monterey requires an additional step to ensure the cache database is properly flushed. Follow these steps carefully to execute the commands correctly.
- Open Terminal: Navigate to
Applications > Utilitiesin your Finder window. Double-click theTerminal.appicon to launch the command-line interface. Alternatively, you can use Spotlight search by pressingCommand + Spaceand typing "Terminal." - Flush the Cache Database: Type the following command exactly as shown and press Return:
The system will prompt you for your administrator password. Note that characters will not appear on screen as you type the password for security reasons. Enter your password and press Return.sudo dscacheutil -flushcache - Restart the Responder Service: Immediately after the first command completes, enter the second command:
Press Return again. If you receive a message stating thatsudo killall -HUP mDNSRespondermDNSResponderis not running, do not worry. This simply means the service needs to be triggered to reload its configuration, which happens automatically upon the next DNS query.
Once these commands have executed successfully, your DNS cache is cleared. You can verify this by attempting to access a website that recently changed its IP address or by pinging a domain to see if the response time reflects a fresh lookup rather than a cached hit.
Alternative Methods and Diagnostics
If the standard commands do not resolve your networking issues, there are alternative approaches to consider. Some users find success by resetting the entire network stack, although this is more invasive and may require re-entering Wi-Fi passwords. Another option involves checking your DNS settings directly through System Preferences to ensure you are using reliable resolvers.
You can also diagnose persistent issues by checking the status of the mDNSResponder process. Run ps aux | grep mDNSResponder in Terminal to see if the process is active. If the process appears stuck or unresponsive, a full system reboot can force all network services to restart cleanly. For more advanced configurations, such as setting custom DNS resolvers, you may need to edit system files or use third-party tools. Consider reading Configuring macOS with Custom DNS Resolvers in /etc/resolver if you require specific control over how your Mac resolves names.
It is also worth noting that some applications maintain their own internal DNS caches independent of the system-wide cache. Browsers like Chrome and Firefox often have their own mechanisms for managing DNS lookups. If you still encounter issues after clearing the system cache, try clearing your browser's DNS cache or switching to a different browser to isolate the problem.
Preventing Future Issues
To minimize the likelihood of encountering stale DNS entries, ensure that your macOS software is up to date. Apple frequently releases updates that improve network stability and fix bugs related to mDNSResponder. Additionally, if you frequently switch between networks, such as moving from home Wi-Fi to a corporate network, consider reviewing your network settings. You might want to disable automatic DNS assignment if you suspect the router is providing incorrect records. For guidance on optimizing your DNS setup for WiFi connections, refer to Configuring DNS Server Network Interfaces for WiFi Networks on MacOS.
In rare cases, you may wish to prevent the system from writing to the DNS cache entirely to force every request to go to the server. This approach can be useful for debugging but will significantly increase latency. If you decide to take this route, you can explore methods to Disable writing to macOS DNS cache, though this is generally not recommended for everyday use due to the performance impact.
Frequently Asked Questions
Does clearing the DNS cache delete my browsing history?
No, clearing the DNS cache does not affect your browser history, cookies, or saved passwords. It only removes the temporary mapping of domain names to IP addresses stored by the operating system. Your personal data remains intact within your browser and other applications.
What should I do if the command says 'mDNSResponder is not running'?
This message is normal and indicates that the service is currently idle or has already restarted. The -HUP signal tells the system to reload the configuration whenever the service starts again. You do not need to manually start the service; it will activate automatically when you make your next network request.
Will this fix issues with specific apps failing to connect?
It may help if the issue is caused by a stale DNS entry affecting the app's connection. However, many applications manage their own network connections independently. If the problem persists, check the app's specific settings or firewall rules, as the system-wide DNS flush might not override application-level caching.
Can I clear the DNS cache using the graphical interface?
macOS does not provide a built-in button or menu option to clear the DNS cache via the graphical user interface. You must use the Terminal command line to perform this action. There are no official settings in System Preferences that allow for one-click cache flushing.
How often should I clear my DNS cache?
You typically only need to clear the DNS cache when you experience connectivity problems or after changing your network configuration. Under normal circumstances, the cache manages itself efficiently. Regular maintenance is unnecessary unless you are troubleshooting specific network issues.