How To Flush the DNS Cache on Your Mac
You may have used a computer with an Internet connection for years without ever running into DNS issues or without even knowing what exactly DNS is. However, once in a while, various factors can lead to your DNS cache on Mac getting corrupted or no longer working properly. In those cases, you should perform the simple process of flushing your Mac's DNS cache to resolve any issues with accessing the Internet.
Before we start, DNS stands for "domain name system" and it is the infrastructure that takes care of linking the proper website names with their domain's physical IP addresses represented by a string of four numbers separated by dots. The DNS cache on your system is a database kept on your Mac's local storage that keeps track of all websites you visited recently and their IP addresses. The reason why the system stores this as a local database is that it is easier, faster, and ultimately better for the user to do this locally instead of contacting a DNS server every time.
However, if your DNS cache gets corrupted, you might start running into issues opening certain websites that worked fine yesterday, run into 404 errors, or other difficulties when browsing. To avoid all of this, flush your DNS cache following those steps:
Press Command+Space to open the search box, then type "terminal" inside it.
Once you can see the text terminal window, enter the following commands with your keyboard, pressing Enter after each one:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
You will need to enter your Mac password to execute the commands.
You are all done! If you followed those steps precisely and entered the commands properly, your DNS cache should be flushed clean and you should be able to access all websites like you normally do.