Skip to content

Back

How to edit your host file on macOS

Applies to:
Domains
Professional Hosting
Universal Hosting
Reseller Hosting
VPS Hosting
WordPress Hosting

Difficulty:
Easy

Time Needed:
5 minutes

Introduction

This is a quick step-by-step guide to editing your host file on macOS. Editing your host file is a great way of viewing a specific web server prior to updating your DNS, or whilst it is propagating.

If you are a Windows user, please see our Knowledge Base article ‘How to edit your host file on Windows’.


How to edit your host file on macOS

STEP 1
Choose ‘Go’

When running macOS, click on the Finder icon, then choose ‘Go’ from the menu bar.


STEP 2
Open ‘Utilities’

From the drop down menu, select ‘Utilities’.


STEP 3
Select ‘Terminal’

This will then open the ‘Utilities’ settings. Locate the icon labelled ‘Terminal’, and double click on it.


STEP 4
Run the command

This will bring up your command prompt. Simply enter the following, and press the ‘Return’ key.

sudo nano /etc/hosts


STEP 5
Edit the host file

This will open your host file. To add a new server or domain, move the cursor to the bottom of the file using the arrows keys. Once you have moved the cursor to the end of the file, enter the IP address of your server, press the ‘Tab’ key, then enter your domain name.

The following is an example, you will need to update these to your relevant IP address and URL.

127.0.0.1 yourdomain.com

When you have entered the relevant IP address and url, hold down CTRL and press the o key, then press the Return key to save your changes. Then simply hold down CTRL key and press the X key to exit and return back to your command prompt.


STEP 6
Flush your DNS

For the final step, simply enter the following command to flush your Mac’s DNS cache.

sudo killall -HUP mDNSResponder

After running the above command, return back to your web browser and enter the domain you added to your host file. If the site changes from the one of the public can see, to the one on your new server, then you have edited the host file successfully.

Was this article helpful?
YesNo