Your computer's local hosts file will allow your computer to override the results of a DNS query, forcing your computer to resolve your website from a specific server or IP address. This can be particularly useful when you are migrating to a new hosting provider as it allows you to test your website, ensuring everything is operating as it should before your live website traffic lands on the new server.
While there are multiple ways you can preview your website before switching the DNS, the most recommended way is to modify your local hosts file as this will give you the most accurate picture of how your website will be, once you make the live switch.
Before you can update your local hosts file, you need to know the IP address associated with your hosting server which you would like to preview your website on.
For AblePage customers, you can find this within the cPanel website control panel, or by contacting our 24/7 expert support team.
Once you have obtained the IP address, you are good to proceed.
The local hosts file is located in ~/etc/hosts
for all MacOS versions, and needs to be opened in a Terminal window.
To open a Terminal window, press Command (⌘) + Space to open a Spotlight search box. In this search box, type Terminal
and click on the corresponding app.
In the Terminal window that opens, open your local hosts file using your preferred editor. In the example below, we are using Nano:
sudo nano /etc/hosts
Once you press enter, you will be prompted to enter your MacOS accounts password (the password you use to log into your MacOS device).
Using the down arrow key, scroll down to the bottom of the file and enter your hosting accounts server IP address, followed by your domain name with and without the www. prefix. For example:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
65.46.19.111 mysite.com www.mysite.com
65.46.19.111 myothersite.com www.myothersite.com
Once you are ready to save your changes, press control
+ x
, and follow that by pressing y
to confirm the changes.
It is recommended to then flush your DNS cache by entering the command below into your Terminal application:
dscacheutil -flushcache
You should now be able to reload your website and see your website load from the new server.
Receive monthly top tips on how to grow and scale your web business.
No Spam. Unsubscribe Anytime.
If you found this article helpful then you will love our support!
Get blazing fast web hosting and experience the AblePage difference today!