The HOSTS file takes the structure of the IP address you wish to point to followed by the hostname you are mapping to it. E.g.
10.20.30.40 nethosted.co.uk www.nethosted.co.uk
This format remains the same across operating systems, however the location of the hosts file does vary. Here is where you can find it on different operating systems:
- Windows 95/98/Me: C:\windows\hosts
- Windows NT/2000/XP Pro: C:\winnt\system32\drivers\etc\hosts
- Windows XP Home: C:\windows\system32\drivers\etc\hosts
- Windows Vista/7/8/10: C:\windows\system32\drivers\etc\hosts
- Mac OS X: /private/etc/hosts
- Linux: /etc/hosts
On Windows 10 (and Vista/7/8) you need to edit the file with administrator rights:
- Start Menu -> Search for Notepad
- Right click Notepad and choose "Run as administrator"
- Click "Continue" on the security prompt
- Select File -> Open
- Browse to “C:\Windows\System32\Drivers\etc”
- Change the file filter selection from "Text Documents (*.txt)" to "All Files (*.*)"
- Select the "hosts" file and Open
- Make the changes that you require and save the file.
For Mac OS X
- Start typing
Terminalin the Spotlight search(cmd+space), or from Applications > Utilities > Terminal.
- Open the hosts file by running this command in Terminal, typing your OSX user password when prompted: sudo nano /private/etc/hosts
- Add the new hosts entry underneath the existing ones at the bottom of the file.
- Press CONTROL+O to save and press ENTER when prompted.
- CONTROL-X to exit nano.
- Running the following in the Terminal window will flush the DNS cache so this takes effect immediately: dscacheutil -flushcache
For Linux you should edit /etc/hosts with your favourite text editor from the root account or using sudo.
After you have set this you can just visit the website in your browser (it may need to be restarted first) and the site will then load from our servers. Using the browsers built in private browsing mode can also help to avoid caching here.
Using this method can save you a lot of headaches in the site development process, and offers you the flexibility to develop your site from anywhere without having to change the DNS servers on your web hosting. It also removes the need to consider DNS caching and propagation.