To flush the DNS cache in Linux, you typically need to interact with the specific DNS caching service running on your system via the terminal.
Here is a general process based on common Linux configurations, incorporating information from the provided reference:
Steps to Flush DNS Cache
Flushing the DNS cache involves accessing your system's command line interface and running a command specific to the DNS caching service in use.
- Open the Terminal: Begin by opening the terminal application. A common shortcut for this is pressing Ctrl + Alt + T simultaneously.
- Determine the DNS Service: The exact command depends on the DNS caching service your Linux distribution uses. Many modern distributions, including Ubuntu, use
systemd-resolved
. Other systems might use services likednsmasq
ornscd
. - Execute the Flush Command: Enter the appropriate command for your system.
- For distributions using
systemd-resolved
(like Ubuntu): According to the reference, the command is:sudo systemd-resolve --flush-caches
- For other services: Commands will vary. For example:
- If using
nscd
:sudo nscd -i hosts
- If using
dnsmasq
:sudo systemctl restart dnsmasq
(restarting the service often flushes its cache) - If using the
resolvectl
utility (alternative forsystemd-resolved
):sudo resolvectl flush-caches
- If using
- Note: Use the command relevant to your specific setup. The reference specifically highlights the
systemd-resolve
command for Ubuntu.
- For distributions using
- Enter Password (if prompted): If you used
sudo
, you will likely be prompted to enter your user password to confirm the command execution. Type your password and press Enter. Note that the password won't be displayed as you type for security reasons.
Successfully executing the command clears the local DNS cache maintained by the specified service.
Verifying the Flush
While not always necessary, some services provide a way to check the cache statistics before and after flushing.
- For
systemd-resolved
: You can view cache statistics usingsystemd-resolve --statistics
before and after flushing to see the cache size change.
By following these steps, you can effectively clear the local DNS cache on your Linux system, which can help resolve issues related to outdated IP addresses or connectivity problems after DNS record changes.