Preview a domain by editing your host file
When developing a new website it can be very useful to look at the site on a live server before you point the domain to it, this way you can check out the site before it goes live, thankfully this is very easy to do using a host file that's located on your computer.
How it works is you add the server IP address followed by the domain name then when going to the domain name instead of the usually IP address being used, your computer will use the IP address you specified in the host file.
Once the site is ready point the domain to the server isn the usual way, change name server or add an A record etc at this point its safe to remove the record in the host file.
To set this up is a little different on Mac and Windows.
open terminal and type
sudo nano /private/etc/hosts
Press enter, you may need to enter your password.
The first few lines will be comments, comments start with a # on a new line enter the IP address of the server and the domain name:
Then save the file by pressing ctrl + x then press y to confirm and enter to overwrite the host file.
Find and open the host file sytemroot is normally c:/windows
In order to be able to make changes to the file do not open the file directly instead open notepad as an administrator by clicking start then right clicking over notepad and select run as administrator
Once notepad is open go to File - Open then navigate to the host file c:windows\system32\drivers\etc
Select the host file, once open you can write to the file once the changes are written save the file, when saving make sure the file type is set to all files.
Once the host file have been saved the changes are instant. This method makes testing a site very easy to do before the domain is pointed to the server.