One of the most common questions we receive from our clients is knowing how they can preview a website that has been loaded on our servers before the DNS records have been changed over to point to us.
The preferred method we suggest, is editing the Hosts file on the Operating System. Every operating system, whether it is Windows, Linux, or Mac, have a txt file called the hosts file. This file contain an IP-domain mapping, with each entry on its own line. Your computer will check this file before retrieving the information from the DNS server. So to put simply, what is mapped is the Hosts file overrides the records in the DNS server.
So by changing the hosts file to the associated IP, you can now see the website on your computer.
Let’s quickly review how to change the hosts file on each Operating System:
For this tutorial, we will using the following domain and the IP. The IP will be an IP that will be associated with the domain on our (FullHost’s) network.
Domain: example.com,
IP: 192.168.1.1
Before making any changes, ALWAYS make a backup copy of the hosts file.
Windows OS (10 and 8)
- Find the notepad application on your windows machine, open it by right clicking and Run as administrator.
- Open the file: c:\Windows\System32\Drivers\etc\hosts
- Scroll down to the very bottom of the file and add these lines:
- 198.168.1.1 example.com
- 198.168.1.1 www.example.com
- Save the file
- Clear your browser cache and restart the browser
- Now open the website as you would normally
Linux
- Open the Terminal.
- Open the hosts file using any text editor like nano or vim or gedit.
- nano /etc/hosts
- Scroll down to the very bottom of the file and add these lines:
- 198.168.1.1 example.com
- 198.168.1.1 www.example.com
- Save the file
- Clear your browser cache and restart the browser
- Now open the website as you would normally
Mac OS X 10.6
- Open Applications > Utilities > Terminal
- Open the hosts file
- sudo nano /private/etc/hosts
- Add these lines:
- 198.168.1.1 example.com
- 198.168.1.1 www.example.com
- Save the hosts file
- Apply the changes by flushing the DNS cache by using the command below.
- dscacheutil -flushcache
Now that you’ve made the changes to the hosts file, you can check whether you have edited the hosts file correctly.
- Open the command line console, cmd in windows, Terminal in Linux and Mac.
- Ping your website, ping example.com
- If it returns the IP configured in the hosts file, then you’re done!