Select Page
You are here >
< Back

A step-by-step guide


What’s the goal of changing the hosts file?

To preview a website on a server using a URL, before the URL is publicly set to point to that server.

In this guide we will set the url:

to point to the server that lives on the IP address:

This guide is applicable to any set of URLs and IP addresses.

The changes will apply only to yourself on the computer that you change the hosts file on!

NB! Remember to revert the changes to the hosts file when you no longer want your computer to point the given URL to the specified IP address.

Let’s get started

1. Open your Terminal

You can find the terminal by opening Finder

and search for Terminal in the search field

Please click on the Terminal icon to 
open the terminal.

2. Grant full permissions in terminal

Please enter the following into your terminal:

sudo su

You will get prompted for your password, please enter the password you use to log in to your Mac, and hit the enter key ↵

3. Open the hosts file with the nano editor

To open the hosts file you need to edit, please enter the following command:

nano /etc/hosts

Then hit the enter key ↵

4. Edit the hosts file

Your hosts file will initially look something like this:

Please go the bottom of the file, and add the following on a new line:

Your hosts file should now look similar to this:

5. Save the hosts file and close the nano editor

a) Press control + O

b) Press Enter

c) Press control + X

This will save your changes, close the Nano editor, and bring you back to the terminal.

6. Reset the networking service on your Mac

The final command you will have to enter in the terminal is this:

killall -HUP mDNSResponder

Please enter the above command and hit the enter key ↵

You may now close your terminal.

7. Verify it is working by opening the URL in your browser

The final step is to verify that you’re now accessing the new website by opening the url we set in the hosts file.

In our example we set to point to the new website,
note that we did not set to point to the new website.

By visiting this URL, you should see the new website:

By visiting this URL, you should see the old website:

That’s all!

Please direct any questions you may have to
[email protected]