Sometimes when designing a new web site, you may need to test certain aspects of the site before launching the site live to the general public. By editing your local Hosts file, you can affect what happens when you type in a certain web site address on your own system by redirecting the web browsers on your computer to a different IP address to view that particular site than the rest of the world would see. So while the rest of the users of the Internet type “www.myfavoritefood.com” into their web browsers and get redirected to the web server at the IP address 201.983.756.1, visiting the same “www.myfavoritefood.com” web address on YOUR own computer only could bring you to the IP address of say 184.108.40.206 (your testing web server, for example). Once you are done testing your site, you could then edit your local Host file again to connect to the site as a regular Internet user would.
To test your web site using your own domain name BEFORE DNS propagation has completed, you can use your local computer’s HOSTS file. Your computer will use the entries in your HOSTS file FIRST before it tries to use your IPS to look up the DNS information for your domain.
REMEMBER: When you are finished testing, remember to remove the custom lines that you added to your Hosts file.
Edit Your Mac Hosts File with Text Edit
There are two primary ways to edit the hosts file in Mac OS X. The first is by using TextEdit, since the hosts file is merely a simple plain text document. However, you can’t open the file directly, since it resides in a protected area of the file system. Instead, we need to copy the file to an unprotected location, like the Desktop, edit it, and then copy it back.
To find the hosts file, open Finder and, in Finder’s menu bar, select Go > Go to Folder. In the box, type the following location and press Return.
/private/etc/hosts A new Finder window will open and your Mac’s hosts file will be selected. Click and drag it out of the Finder window and drop it on your desktop. This will let us freely edit the file. Double click the hosts file to edit... add your IP and the domain name: IE: 20.333.44.222 cnfdesigns.com Click "Save" on your textedit... Then drag the file back to the original location.
When you drop the hosts file back in its original location, OS X will ask you what to do about the unmodified hosts file that’s already there. Choose “Replace” and then enter your administrative user password to authenticate the transfer.
With the modified hosts file now in place, fire up your Web browser to test the changes. In most cases, the new mapping should work immediately, but if you’re not seeing the correct behavior, you may need to flush your DNS cache. For OS X Lion and OS X Mountain Lion, open Terminal and use the following command. Note that you’ll need to enter your admin password to execute it:
sudo killall -HUP mDNSResponder
For OS X Mavericks, use this command instead:
dscacheutil -flushcache; sudo killall -HUP mDNSResponder