Windows – How to automate the DNS flush

azuredhcpdomain-name-systemwindows

I am having couple of Virtual machines . Few applications are using the HOSTNAME in their configuration files to contact these machines.

Everything was running fine and all happy! until application stopped connecting to VMs or services in VMs using hostname! After some R&D I found that we can still connect the VMs using IP!! That mean's it's DNS issue! So I run below three commands and all started working fine

  1. ipconfig /flushdns
  2. ipconfig /registerdns
  3. netsh winsock reset

But now issue is, we can not predict when it will happen again. So what is best practise? Do I have to put these commands in a script and run in daily basis?

Best Answer

If you control the environment, you should consider to set higher values for the DHCP leases (e. g. 7 Days) and lower the TTL values on your DNS server (e. g. 15m or 1 hour).

In a well configured environment this behavior should not be observed.