Say you have Server A
set up with your favourite webserver-daemon to serve www.example.com
. Now you want to move this to Server B
. After a bunch of copying and configuring, the new server seems to be ready.
A final test would be in order: Before changing the DNS-records, how does one ask for www.example.com
from Server B when the DNS records still point to server A?
While my main question has been answered, in the event of /etc/hosts not being under my realm of influence, is it possible to test it with telnet by instead talking raw HTTP1.1 to the webserver?
DNS is a magical thing. With enough control over a client PC, you can make
right.com
intowrong.com
andviceversa.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, likednsmasq
. Either which way you go about the process, the ultimate goal is to make the DNS response for queries concerningwww.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:
or, for that matter,
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 thehosts
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:
The request will look something like this:
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.
If you need to check if it works, I advice a simple broswer plugin like
Modify Headers
for Firefox, and change theHOST
towww.mydomain.com
.