📜  flush dns - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:47.811000             🧑  作者: Mango

Flush DNS - Shell-Bash

DNS resolution is an integral part of network communication, and it involves translating domain names into IP addresses. DNS resolution can be cached locally at the client end, and it can lead to outdated results in some cases. In such cases, a DNS flush is required to clear out the cache and refresh the results. In this article, we will discuss how to flush DNS using Shell-Bash.

Method 1: Using the networksetup Command

The networksetup command is a built-in command in macOS, and it allows you to configure network settings. Here's how to flush DNS using the networksetup command:

  1. Open Terminal and type the following command:
sudo networksetup -setdnsservers Wi-Fi empty
  1. You will be prompted to enter your password. Enter it and press enter.

  2. This command will flush the DNS cache for the currently active network interface (in this case, Wi-Fi).

  3. To verify that the DNS cache has been flushed, you can use the following command:

dscacheutil -flushcache
Method 2: Using the dscacheutil Command

The dscacheutil command is a built-in command in macOS that allows you to manage the DNS cache. Here's how to flush DNS using the dscacheutil command:

  1. Open Terminal and type the following command:
sudo dscacheutil -flushcache
  1. You will be prompted to enter your password. Enter it and press enter.

  2. This command will flush the DNS cache.

  3. To verify that the DNS cache has been flushed, you can use the following command:

sudo killall -HUP mDNSResponder
Conclusion

Flushing DNS is an important step to ensure your network communication is smooth and up to date. This article covered two methods of flushing DNS using Shell-Bash. You can choose the method that best suits your needs and the time available.