Thursday, 17 February 2011

Hosts file and Browsers

Windows Hosts file can be used to re-map host name to an IP. For example, requests for information to particular addresses (hostnames) like “www.example.com” are directed to specific IP Addr.

You can use this technique to test how your web application response to requests with fully qualified domain name, when you don't actually buy any domain name. Say I have a real server with real IP:8.8.8.8. I want to know if my web application render correctly when user browse to [appname].myDomain.com. Add the following entry to the host file (windows\system32\drivers\etc)
8.8.8.8  appname.myDomain.com
It works well for awhile. Someday, some one come & buy myDomain.com, point it to another server say DomainMarket.com. The technique still work if your Internet does not goes through a proxy server (e.g at school or many businesses). when your browser behind a proxy, the proxy perform DNS lookups for you, then the HOSTS file is ignored. Ping in command line to appname.myDomain.com still resolves to 8.8.8.8, while your browser still resolves to DomainMarket.com

Hope this can save someone sometime.
Tai -