Can I override DNS hostnames or use a custom hosts file?

Sure! Let’s say you want to script against one environment, and then run load tests against a different environment. One easy way to do this is by overriding the DNS entries for your target environment with a custom hosts file.

Why would I want to override hostnames?

Many teams run separate environments of their site or web application, such as development, test, staging, and of course production. If you run multiple environments, you might want to run the same load test against each of them, without having to go through and edit all your scripts.

Sometimes you might also want to stand up an identical copy of the production environment for the sole purpose of load testing. That way you can record against the real production environment, and then simply override the hostnames when it comes time to stand up the alternate environment and run your tests.

How do I override hostnames in a load test?

To get to it, open your test scenario and click the wrench for the v-user group(s) in question.

Getting to the advanced v-user group settings

Click to expand the custom hosts file…

Overriding IP addresses for hostnames

Your custom hosts file should use the usual /etc/hosts format, but limited to a single hostname per line. Also, comments in your hosts file may be ignored or stripped out.

Read more about this and other advanced configuration options in Running Load Tests.

What should I do if a hostname maps to multiple IP addresses or a CNAME?

If your site uses DNS load balancing (mapping the same domain to multiple IP addresses) or you’ve got a dynamic CNAME entry, then overriding a single hostname with a single IP address may not work for you.

Another way to accomplish this is to replace the hostname(s) in your script with a script variable and then bind it to one or more entries in a dataset.