How can I automate the DNS flush?
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
- ipconfig /flushdns
- ipconfig /registerdns
- 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?
Solution 1:
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.
Solution 2:
Do I have to put these commands in a script and run in daily basis?
Definitely bad idea, see below. This should be treated as last resort.
So what is best practise?
Troubleshot your DNS server and network conectivity, configure your hosts' DNS client cache.
Source: https://technet.microsoft.com/en-us/library/cc959309.aspx
The resolver cache and server cache are maintained separately. For information about the server cache, see Windows 2000 Server Help. The length of time for which a positive or negative response is cached on a DNS client depends on the values in the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNSCache\Parameters
What is important here is that your client may cache negative answers. Your applications should be configured with decent name resolving timeout. If your hosts have L2 connectivity, then you could configure NetBIOS as a backup. If not, then you can also use WINS. Make sure how master/backup browser election looks like and how to control it.