Testing a servers ability to serve a particular domain

DNS is a magical thing. With enough control over a client PC, you can make right.com into wrong.com and viceversa.io. Jump onto a test client PC and muck with its DNS resolution by either changing the host file on that client, or you can do something a bit more complex and give that host a simple DNS server to query, like dnsmasq. Either which way you go about the process, the ultimate goal is to make the DNS response for queries concerning www.example.com respond with the IP address for Server B. HTTP host headers will then bear the DNS name for www.example.com, but be aimed at Server B.

Magic!


It's important to note that what matters to do a test like this for HTTP is not really related to DNS at all but what the HTTP client sends as the Host header value.

The client needs to connect to the right IP address and port, obviously, but beyond that it all comes down to the Host header which is inline in the HTTP request itself.


For a quick test the following command can be used without changing any operating system level configuration on the client:

$ curl -H "Host: www.example.com" http://192.0.2.17/foo/bar

or, for that matter,

$ curl -H "Host: www.example.com" http://beta.example.com/foo/bar


To do the same with a regular web browser you would either need a browser extension that can modify the request headers (or possibly an HTTP proxy that changes headers), or you would need to change the configuration of the client machine operating system.

As has been mentioned, the easiest means of doing such a configuration change would be to add an entry to the hosts file. This way the client OS resolver library would get a hit already when consulting the hosts file and will not even need to do a DNS lookup.

Other options include changing the configured DNS resolver servers on the client to a nameserver which is set up to answer as desired.


You can test this with telnet. You need to make a raw HTTP request by typing the commands. You can't make any mistakes, and some servers have a timeout so you also have to type the whole request within that time frame.

The command will be something like this:

telnet serverb 80

The request will look something like this:

GET / HTTP/1.1
Host: www.example.com

Note that it must end with a blank line, so you'd press enter twice after the host header.


What I usually do is force www.example.com to server B IP address in my /etc/hosts. I've been doing that since I used Mosaic and since I do it infrequently I haven't felt the need to find better.

Looking around a bit for you, I found https://superuser.com/questions/403042/custom-host-file-for-firefox which is answered by https://addons.mozilla.org/es/firefox/addon/foxyproxy-standard/ but there is a very recent note saying that it is abandoned.