[How-To] Flush DNS Cache

If you are a developer who often has to test same application deployed on different servers, the various options you have are

1.) Modify your HOSTS file to point to a new IP. You can learn more about modifying HOSTS file by reading previous posts on HOSTS file ( Microsoft Windows: More fun with the HOSTS file and Block Websites of your choice without any Software)

2.) Modify the DNS Entry of your Website. This is useful if you have testers who are not technically savvy doing the testing. In such a scenario all you need to do is modify the DNS entry and the new IP is reflected as soon as the change happens.

However, if you are having issues with the DNS IP Resolution and if even after a change on your DNS Server, the new IP is not getting reflected, its time to Flush the DNS Cache. 

DNS Resolution of My Website is Cached? How can i Clear this Cache?

Follow the Steps below

1.) In your windows machine, open the command window by going through Start –>Run and type Cmd.

Initiate the command window

Image: Initiate the command window

2.) At the Command Prompt, type ipconfig /flushdns as shown below in the figure.

Flush out DNS Cache

Image: Flush out DNS Cache

3.) Your DNS Cache is now flushed. What this means is, that your computer will now make a new request to your DNS Server for getting the IP Address. 

The above listed trick lets you flush the DNS Cache from the local resolver of your computer. However, the DNS Entry might still be cached at the DNS Server. 

How Can i Stop the Local DNS Resolver from Caching at All?

Yes. If you make frequent changes to your IP Address and would like to keep the DNS Cache Resolver away from Caching the entries, you can stop the service by typing net stop dnscache at the command prompt.

In order to start the service again, type net start dnscache.

Starting and Stopping the DNS Local Resolver Caching.

Image: Starting and Stopping the DNS Local Resolver Caching.

You can even tweak Windows Registry to modify the DNS Caching behaviour

You can modify the behavior of the Microsoft Windows DNS caching algorithm by setting two registry entries in the

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters registry key.

The MaxCacheTtl represents the maximum time that the results of a DNS lookup will be cached. The default value is 86,400 seconds. If you set this value to 1, DNS entries will only be cashed for a single second. MaxCacheTtl needs to be a new DWORD.

MaxNegativeCacheTtl represents the maximim time that the results of a failed DNS lookup will be cached. The default value is 900 seconds. If you set this value to 0, failed DNS lookups will not be cached. MaxNegativeCacheTtl needs to be a new DWORD.

How Do I Flush DNS Cache in Linux?

In Linux, DNS Cache is managed by a service called nscd. To restart the nscd daemon, use the command `/etc/init.d/nscd restart`.


You can follow me on Twitter at http://twitter.com/vaibhav1981

Do stay tuned to Technofriends for more, one of the best ways of doing so is by subscribing to our feeds. You can subscribe to Technofriends feed by clicking here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: