You’re developing a site on a sub-domain or development server that is setup something like this, dev.YourDomain.com and you want to see if all the files and paths are correct. You’ve moved the site to a new server and IP and you want to check YourDomain.com there without disrupting the live site. Simply edit your /private/etc/hosts file on your Mac OS X box to reflect the new IP you want to test.
Real Live Site: YourDomain.com IP 188.8.131.52
Dev Site: dev.YourDomain.com IP 184.108.40.206
DNS Masked Site: YourDomain.com IP 220.127.116.11
Simply edit /private/etc/hosts and add the line
18.104.22.168 yourdomain.com www.yourdomain.com
Now when you ping yourdomain.com your system will return 22.214.171.124. Open up your browser and test your new site before making the DNS switch on the real DNS servers.
The hosts file is used to map hostnames to IP addresses. With the hosts file you can change the IP to which you resolve a certain domain name.
This is particularly useful when you wish to see how a website will look when hosted on a different server without having to wait for a DNS change to propagate, or avoiding any DNS changes at all.