How to use the 'hosts' file?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.
The path to the hosts file, depending on the operating system you are using, is:
- Windows - %SystemRoot%\system32\drivers\etc\hosts (by default the system root is c:\windows, so if you are using Windows, your hosts file is most probably c:\windows\system32\drivers\etc\hosts)
- Linux - /etc/hosts
- Mac OS X - /private/etc/hosts
Now let's say that you wish to resolve your domain domain.com to IP 1.2.3.4. In this case the entry you should add to your hosts file would be:
1.2.3.4 domain.com www.domain.com
You may need to clear your cache before you can properly resolve the domain to the new IP.