Under normal circumstances the DNS system will inform your browser at what IP address a site should be accessed. However, if you are transferring a site or working on a new site on a new server while your existing site continues to operate then it is useful to be able to override the normal DNS process. This is where the HOSTS file comes in.

The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more hostnames. Each field is separated by white space (blanks or tabulation characters). Comment lines may be included; they are indicated by a hash character (#) in the first position of such lines. Entirely blank lines in the file are ignored. For example, a typical hosts file may contain the following:
# This is an example of the hosts file

127.0.0.1  localhost loopback
::1        localhost

This example only contains entries for the loopback addresses of the system and their hostnames, a typical default content of the hosts file. The example illustrates that an IP address may have multiple hostnames, and that a hostname may be mapped to several IP addresses.

So you have a new site being built on a new server at xxx.xxx.xxx.xxx

In this case open your hosts file (see table below for operating system specific locations) using a text editor and enter the following on a new line at the bottom of the file. Note you may have to open your text editor with elevated permission. In windows, for example, right click on the short cut to notepad (other text editors are available) and Run as Administrator before attempting to edit your hosts file.

xxx.xxx.xxx.xxx mynewsite.com

 

Operating System Version(s) Location
UnixUnix-like,POSIX /etc/hosts[2]
Microsoft Windows 3.1 %Windir%\HOSTS.SAM
9598/98SEMe %WinDir%\
NT2000, and 32-bit versions of XP,[3] 2003,Vista7 %SystemRoot%\system32\drivers\etc\
64-bit versions[4] %SystemRoot%\system32\drivers\etc\ (Many sources, including several Microsoft support pages, will incorrectly state that the hosts file is at%SystemRoot%\SysWOW64\drivers\etc\)[5]
Windows Mobile Registry key under \HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts
Apple Macintosh 9 and earlier System Folder: Preferences or System folder
Mac OS X 10.0 – 10.1.5 [6] (Added through NetInfo or niload)
Mac OS X 10.2 and newer, iOS (only with jailbreak) /private/etc/hosts [6] or, since /etc is a symbolic link to /private/etc/etc/hosts (just like POSIX)
Novell NetWare SYS:etc\hosts
OS/2 &eComStation "bootdrive":\mptn\etc\
Symbian Symbian OS 6.1–9.0 C:\system\data\hosts
Symbian OS 9.1+ C:\private\10000882\hosts
MorphOS NetStack ENVARC:sys/net/hosts
Android /system/etc/hosts or like Mac OS X, since /etc is a symbolic link to /system/etc/etc/hosts (just like POSIX)
iOS (only with jailbreak) iOS 2.0 and newer /etc/hosts
TOPS-20 <SYSTEM>HOSTS.TXT

* source