DNS caching is an important mechanism for increasing speed of website loading in a browser. For a webmaster, I do not need to speak much about the importance of fast loading websites because it is all very well know. But for a visitor also, it is good if something could be done to load the requested websites at a greater speed. DNS and caching of DNS play a significant role in determining how fast your net connection practically works.
Sometimes we need to flush or clear the DNS cache on local computer or on a proxy server. Let’s understand what DNS cache is and how to flush it.
On Internet, all the websites sit on computers that are called servers. Each of these servers are identified with a unique address called IP address. These IP addresses have to be unique in order to avoid any clashes while identifying machines.
When you type a URL, let’s say, techwelkin.com in your browser’s address bar, you actually tell your browser to go to the server of techwelkin.com and fetch the website.
But there is no server on the Internet whose name is techwelkin.com! Servers are identified by IP addresses and not by domain names. So how does your browser brings you the website?
Instead of looking for the server, your browser tells DNS that the user wants to visit techwelkin.com … DNS is a server that keeps a table of domain names and their associated IP addresses. So, DNS looks into its table and finds the IP address for techwelkin.com. DNS gives this IP address to your browser. Then your browsers gets connected with the server whose IP addresses was returned by the DNS.
This is how your browser reaches a particular website.
To increase the speed of DNS lookup, a cache memory (very fast memory) is setup. Frequently looked up domain names and associated IP addresses are stored in this cache. Fast memory and relatively smaller set of domain names make the search in DNS cache much faster than look up in the entire DNS table.
A DNS cache may be created at many places. Operating system of your local computer may also setup its own DNS cache. If you’re accessing Internet through a proxy server, then the proxy computer may have its own DNS cache. Then eventually your Internet service provider may also have its separate DNS cache.
DNS cache is good because it speeds up the process of finding (and therefore loading) websites. But what if a website is moved from one server to another? In such a case, the associated IP address with that website will change. However, if DNS cache is not refreshed, it will still match the website with the old server.
This is one of the scenarios where we need to flush and refresh DNS cache.
On Windows operating system, you can easily flush DNS cache of the local computer. For this take the following steps:
- Go to Start > Run and type cmd to open the Command Prompt. In case of Windows 8 you can press Windows key + R to bring up the Run box.
- In the black colored Command Prompt window, type ipconfig /flushdns
- Press Enter to issue command and the local DNS will get flushed.
- Open up a command terminal (either as root or run step 2 with sudo)
- Run the command /etc/init.d/nscd restart
Apple Mac machines have different commands depending upon the operating system running on them. Let’s see these commands according to the OS:
Mountain Lion or Lion
Mac OS X 10.7 or 10.8:
- Open the command terminal from Utilities
- Run the command sudo killall -HUP mDNSResponder
Mac OS X Snow Leopard (10.6):
- Open up a command terminal from Utilities
- Run the command dscacheutil -flushcache
Mac OS X Leopard (10.5.1) or below:
- Open a command terminal from Utilities
- Run the command lookupd -flushcache
If you’re not seeing the expected website even after clearing the local DNS cache with the help of the above given command, you can be almost certain that the cache of proxy server needs to be flushed.
You can not clear DNS of proxy from your local machine (unless proxy server is also running right on your own machine!)… For clearing the proxy cache, you’ll need to contact your server administrator.
Various proxies have different interfaces. In some cases you’ll find a flush button, whereas in other cases disabling and enabling DNS cache will reset the cache.
Wasn’t it easy to flush DNS in order to clear all the entries from domain-ip table? Although DNS caches are frequently refreshed by servers but sometimes you may need to manually flush them.
I hope it was useful. Please feel free to ask should you have any questions. I will be happy to try and help you. Thank you for using TechWelkin!