So, your site is already set up on a server, and you’re looking to test it before it goes live. How do we accomplish this? (If you’d like to skip the basics, feel free to jump to the “Changing the hosts file” section below)
What is the Purpose of the Hosts File?
When you enter a web address in your browser, it figures out what IP address to talk to using the Domain Name System (DNS). However, before the DNS was created in the early days of the internet, there was a much more basic method to figure out the “hosts” file.
The hosts file is designed to store one line for every website (or host) it talks about, with an IP address and the hostname or website. The only problem is popularity — since billions of websites are out there nowadays, it would be impossible for every computer to keep a list of every website and its IP address. This is why the hosts file is not used much nowadays — instead, you can set up DNS records publicly for anyone to access when needed.
That said, the ability to direct your computer to a specific IP address is incredibly useful for developing and testing websites, which is why it’s still in place on modern computers. When you change your hosts file, your computer will connect to the IP address you’ve set even if the actual website is pointed somewhere else, so you don’t have to change your DNS records before your site is 100% ready.
Modifying the Hosts file in Windows
Step 1. Press the Start button, and then type “Notepad” to search.
Step 2. Right-click on the icon and select “Run as administrator.” You may be prompted to provide administrator rights to Notepad before you can proceed. This makes sure only authorized users can make system changes.
Step 3. Once you have Notepad up, go to File → Open.
Step 4. On the Open dialog box, navigate to C:\Windows\System32\drivers\etc. Make sure that “All Files” is selected on the drop-down menu in the bottom-right corner.
Step 5. Next, open the file named “hosts.” This file already contains useful instructions on using it. We need to enter the IP address of our server and the domain name of the site we are looking to test. In this case, we’re reviewing the example.com domain with IP 192.168.92.68. This entry can replace this with any domain name or server IP.
Step 6. After saving the file, you can go to example.com in your browser, and it will point the request to the server at 192.168.92.68, even if it is not yet live in the DNS. If you’ve visited the site before setting up your hosts file, you may need to flush your DNS cache to get the change to replace the previous cached IP.
Step 7. When you are finished testing, you can follow the same process to remove this entry from your hosts file and start loading the site from its actual public IP address.
What Other Options do I have?
If you do not have administrator rights on your computer, you cannot modify the hosts file. Besides using a different computer, there are several other options you can try.
- Using a staging subdomain (such as staging.example.com instead of example.com) is a great way to test a website before it’s ready to go live. One thing to keep in mind is that this subdomain might be accessible to other visitors if they know about it — if it’s critical to hide it from view, work with your developer or web host to set up access control.
- A third-party service like hosts.cx can be used as a proxy between your browser and the server you’re looking to test without changing your local hosts file.
- If you’re using Linux or macOS instead of Windows, there are also instructions on changing your hosts file.
Finally, if you still need help testing a website you’ve hosted with us, feel free to reach out, and we’ll be happy to help.