How to flush DNS cache on Linux?

DNS (Domain Name System) is a network service used to resolve domain names into corresponding IP addresses. On the Linux operating system, in order to improve the performance and efficiency of DNS query, the system will cache the latest DNS query results. But sometimes you may need to manually refresh the DNS cache in order to obtain the latest DNS resolution results. This article will explain how to flush DNS cache on Linux and provide detailed steps.

step

Here are the detailed steps to flush DNS cache on Linux:

Step 1: Determine Your Linux Distribution

Different Linux distributions may use different DNS resolution tools and services. Before starting, first determine the Linux distribution you are using. This article will cover two common distributions: Ubuntu and CentOS.

Step 2: Flush the DNS cache on Ubuntu

Method 1: Use systemd-resolved service

Ubuntu uses the systemd-resolved service to handle DNS resolution and caching. To flush the DNS cache, you can execute the following command:

sudo systemd-resolve --flush-caches

This will clear the DNS cache of the systemd-resolved service and cause it to re-resolve DNS from scratch.

Method 2: Restart the systemd-resolved service

Another way is to restart the systemd-resolved service, which will also clear the cache and restart the service. Execute the following command:

sudo systemctl restart systemd-resolved

Step 3: Flush DNS Cache on CentOS

Method 1: Use the NetworkManager service

CentOS uses the NetworkManager service to manage network connections and DNS resolution. To flush the DNS cache, you can execute the following command:

sudo systemctl reload NetworkManager

This will reload the NetworkManager service and clear the DNS cache.

Method 2: Restart the NetworkManager service

Another method is to flush the DNS cache by restarting the NetworkManager service. Execute the following command:

sudo systemctl restart NetworkManager

Step 4: Other Linux Distributions

For other Linux distributions, you can try one of the following:

  • Restart network service: Restart network service by executing sudo systemctl restart networkor sudo service network restartcommand, which may refresh DNS cache.
  • Restart your computer: If none of the above works, you can try restarting your computer, which will clear the DNS cache and reload all network configurations.

in conclusion

By performing the above steps, you can refresh the DNS cache on Linux to get the latest DNS resolution results. Keep in mind that in some cases it may take some time to fully see the new DNS resolution results. If you have problems with your Internet connection or other configuration issues with your DNS server, flushing the DNS cache may not take effect immediately. Also, different Linux distributions may use different tools and services to handle DNS resolution and caching, so make sure to use the appropriate commands and methods for your distribution when performing the above steps.

If you still encounter DNS resolution problems, you can try to use other DNS resolution servers, or check whether your network configuration and DNS settings are correct. At the same time, you can also try to clear the DNS cache of the browser, because the browser also caches the DNS resolution results.

All in all, flushing the DNS cache is a common solution to some DNS-related issues, and it can be easily performed on Linux as well. Depending on your Linux distribution, choose the appropriate method to flush the DNS cache, and be sure to try flushing the DNS cache before trying other solutions.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/131313204