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%system32driversetchosts (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 18.104.22.168. In this case the entry you should add to your hosts file would be:
22.214.171.124 domain.com www.domain.com
In Windows 7 you might have difficulties editing the hosts file due to the required access level. In order to edit the file navigate to Windows -> Start. Search for Notepad, right-click on the corresponding icon and select Run as Administrator. This should launch notepad with elevated privileges. Next, open the hosts file from the File menu, edit and save it.
For the permission issue, try the following steps:
Take ownership of the hosts file and change the permission for it.
- Right click on the hosts file and click Properties.
- Switch to the Security tab and click on the Advanced button.
- Navigate to the Owner tab and click Editâ€¦
- Highlight your user account or the Administrators group and click OK twice to quit the Advanced Security Settings dialog box.
- On the Security tab under the Properties dialog box click Editâ€¦
- Highlight the Administrators group, check the box for Full control under Allow and click OK.