Why would you need to edit your hosts file?
You’ll often want to preview or develop a site on your Nublue hosting that still points elsewhere, ie: a site that’s not yet live with us. This can be handy for viewing a site you’re working on, or even checking how a site that you have migrated to a new server looks before setting it live.
The best method is to use your computer’s hosts file to bypass the usual DNS lookup. This forces your machine to view the domain on the IP address that you specify. It will only work for your computer, so all other users will see the live version of the site. Similarly, if you make this change on your phone, other machines and devices on your network remain unaffected so you’ll still be able to view your live site on your smartphone.
In Windows 10 the hosts file is located at c:\Windows\System32\Drivers\etc\hosts.
Right click on Notepad in your start menu and select “Run as Administrator”. This is crucial to ensure you can make the required changes to the file.
Now click File > Open and browse to : c:\Windows\System32\Drivers\etc\hosts. If you can’t view any of the listed directories you will need to configure Windows to show your hidden program or System Files as per the guide here.
Add a line to the bottom of the file the following lines, replacing IP_ADDRESS with the IP Address you took from the Hosting Control Panel and DOMAIN_NAME with your domain:
IP_ADDRESS DOMAIN_NAME www.DOMAIN_NAME
22.214.171.124 nublue.co.uk www.nublue.co.uk
You’ll now need to save the file and you’re done. You should be able to visit your site and view it as it appears on the new IP address. You may need to refresh your browser cache to ensure you’re seeing the new version of the site.
You can always test that you’re seeing the site on the IP you wanted by pinging your domain or by browsing to https://your-domain-name.com:8443. This will open up the Plesk control panel for your site and will show Nublue branding if you’re seeing a version of the site hosted with us. You can also see the hostname of the server in the name of the tab you’ve opened. This can be very useful in confirming that you’re looking at the correct version of the site, especially if both the old and new version of the site are hosted with Nublue.
If you’re on a Mac, the changes you’ll need to make to your hosts file are identical but the process for editing the file is different.
You can use the Terminal application to edit your hosts file. To do this, open up Finder then Applications > Utilities > Terminal.
From here you can use the following command to edit your hosts file:
sudo nano /etc/hosts
You will have to supply your admin password for the Mac but you should be able to make any necessary amendments to the hosts file. When you’re done, use Ctrl + O (followed by Enter) to save the file and then Ctrl + X to exit.
Reversing the change
To reverse the change and view the live version of your site again, you can simply remove the line you’ve added to your hosts file and save it afterwards. If you’re going to be switching back and forth between viewing two versions of the site, you can comment out the line with a leading “#” as in this example:
#126.96.36.199 nublue.co.uk www.nublue.co.uk
This allows you to add and remove the line easily in future, but bear in mind you may be seeing a cached version of the site in your browser when you make the switch. If in doubt you can make sure you’re not viewing a cached copy of the site by using a different browser, or switching to incognito/private mode. If this fails, you can refresh your browser cache or even flush your machine’s DNS cache.