1. Home
  2. Hosting & Servers
  3. Managed Wordpress Hosting
  4. How do I access my website using the hosts file?
  1. Home
  2. Presales
  3. How do I access my website using the hosts file?
  1. Home
  2. Hosting & Servers
  3. Managed Wordpress Hosting
  4. How do I access my website using the hosts file?
  1. Home
  2. Presales
  3. How do I access my website using the hosts file?

How do I access my website using the hosts file?

If you need to check, test or access a new website that is only accessible on a temporary URL, you may need to edit the hosts file to properly test the website. This method of access can also be used to make changes to a staging website prior to the website going live, or to simply verify the outcome of a migration.

The location of the hosts file and how to edit this depends on the operating system you are using.

Further down this page, there are guides for WindowsMac and Linux.

How the Hosts file works

This basically works by tricking your computer into thinking that the DNS records have been updated on your Computer only. This allows you to access the website normally, but have it load from a different server.

The hosts file itself needs to be updated with specific syntax, this will be in the format of ‘ip domain(s)’, for example.

127.0.0.1 yourdomain.com.au www.yourdomain.com.au

Make sure the IP at the start of the line is the one of your actual server. You would see this in the email you received with your cPanel or WHM login information.

Once the changes have been made, you can test the website on the new server using its normal domain name/URL ie. how you normally access the website.

Crucial recommends removing the changes made in the host file once the testing has been completed.

Windows

1.Locate ‘notepad‘ in the start menu

 2. Right click on notepad and select ‘Run as Administrator


3. Click ‘File‘ and then ‘Open
   4. Navigate to the following location:      ‘C:\Windows\System32\drivers\etc

  • First navigate to your C: drive
  • Then navigate to the Windows folder
  • Then find the System32 folder
  • Then select drivers
  • Then locate the etc folder

   5. Change ‘Text Documents (*.txt)‘ to ‘All Files’
   6. Select ‘hosts‘ and click ‘Open
   7. Type in the details as required

Ensure that you use the details provided in the migration email for this section

8. When done save the file by clicking on ‘File‘ and then ‘Save

Mac

1.Open Finder

 

2.Select ‘Applications‘, and then ‘Utilities

  1. You can also hold down the ‘Control‘ and ‘Shift‘ keys and press ‘U‘ 

3. Open ‘terminal

 

4. Type in ‘sudo nano /private/etc/hosts
(If this file is blank use ‘sudo nano /etc/hosts‘)

 

  • 5.Type in your computer’s password and press ‘Enter
    The screen will remain blank while doing this

Use the ‘down arrow‘ key to navigate to the end of the file

 

  • 6.Type in the details as required
  • 7.Hold down the ‘Control‘ key and press ‘O‘ to save, then press ‘Enter
  • 8.Hold down the ‘Control‘ key and press ‘X‘ to exit nano
  • 9.You can now exit terminal

 

Linux

  1. Open a teminal window
  2. Type in ‘sudo vi /etc/hosts
  3. Type in your computer’s password and press ‘Enter
    The screen will remain blank while doing this
  4. Use either the down arrow or ‘j‘ to navigate to the bottom of the file
  5. Press ‘i‘ to enter insert mode
  6. Type in the details as required
  7. When done press ‘Esc‘ to exit insert mode
  8. To close the file press either ‘Z‘ twice or type the following ‘:wq
  9. You can now exit terminal

 

 

Updated on April 15, 2020

Was this article helpful?