What is a host file?
A hosts file is an address book, situated on your local computer that maps a host name to an IP address (network name resolution). Generally, a domain name (host name) is translated to an IP address via the DNS resolution process. However, the host entries that are present in the host file will bypass this DNS resolution.
When will this be useful for you?
- If you’ve just modified the Name Servers of your domain name, and are viewing the cached results due to DNS propagation.
- If you’re in the process of migrating to a new hosting server, and want view your website on the new server while it’s still under development. This way you can preview the site, whereas your visitors will continue to view the live website on the old server. Thus, the traffic to your site remains unaffected.
How do I do it?
Here’s how 🙂
Go to C:\Windows\System32\drivers\etc and locate the hosts file
- Open it in any text editor like Notepad, Notepad++, etc
Add your host entries as shown in the snapshot below and save the file
That’s it. Flush your DNS cache and browser cache and you should be able to see your website from the server IP you specified in the host file.
- Locate the hosts file at /etc/hosts
- Run the below command to edit file: vim /etc/hosts
- Add your host entries as shown in the snapshot below and save the file.
That’s it. Flush your DNS cache + browser cache and you should be able to see your website from the server IP you specified in the host file.