Testing Connectivity and DNS Changes with a Hosts File

Many Exchange Server migration scenarios involve making DNS changes that can impact a very large number of customers at once if they go badly.

Similarly, we often need to isolate network elements such as load balancers or DNS round robin configurations when troubleshooting client connectivity issues. Making changes to a load balancer or DNS record for this troubleshooting carries a similar risk to those changes made during migrations.

Instead of making a risky, high impact change to your environment you can instead use a hosts file on one (or a few) test computers to achieve the same outcome. The hosts file on the computer will override any DNS results that would be returned for a server lookup, allowing you to have just those specific client computers pointing to a different location for Exchange services such as Autodiscover, Outlook Anywhere, and so on.

host-files-01

Modifying hosts files is a quick and easy task. It requires elevated privileges, so first I like to start an elevated CMD prompt.

start-menu

The CMD prompt will usually start in the C:\Windows\System32 folder. Navigate to thedrivers\etc subfolder.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd drivers\etc

Then launch Notepad to edit the hosts file.

C:\Windows\System32\drivers\etc>notepad hosts

Any lines in the hosts file starting with a hash character are comments, and will have no effect on the system. Add your desired entry to the hosts file by typing the IP address, pressing tab, then typing the fully qualified domain name. For example, here I am configuring mail.exchangeserverpro.net to resolve to 10.1.4.30 to go directly to a Client Access server instead of resolving to the VIP of the load balancer via DNS.

host-files-02

Save the file and close Notepad. Next you need to restart the DNS Client service. You can do this from the CMD prompt as follows:

C:\Windows\System32\drivers\etc>net stop "DNS Client"
The DNS Client service is stopping.
The DNS Client service was stopped successfully.

C:\Windows\System32\drivers\etc>net start "DNS Client"
The DNS Client service is starting.
The DNS Client service was started successfully.

Restarting the DNS Client service is often enough but a full restart of the PC would be advisable at some stage to thoroughly test the change.

If you’re using hosts file for this type of testing or troubleshooting just remember to keep track of which computers you’ve changed them on so that you can go back and remove the entries later. I have encountered many cases in the field where a hosts file change was forgotten about and that particular computer experienced frequent issues as a result.