How to Edit your Hosts File on a Mac

The hosts file is used by your computer to lookup/resolve domain names to an IP address. This file can be used to force your computer to resolve your website to a specific IP address rather than resolving your website using the DNS found in the name servers the domain is pointed to. Manually configuring your domain with the IP address of your Hosting server, will allow you to test your website without affecting the server where your domain is pointed to via the name servers/DNS.

Edit Hosts File

    1. Open the Terminal application.

You may either type Terminal in the Spotlight search or by navigating to Applications -> Utilities -> Terminal.

    1. Open the hosts file for editing.

In the terminal window you just opened copy/paste the command string below, and press return.

sudo nano /private/etc/hosts

You’ll be prompted to enter your Mac user’s password.

    1. Edit the hosts file by adding these two lines to the bottom of the file.


For example, it should look like:

    1. Save your changes by pressing control-o on your keyboard then return to accept the filename. Exit the editor by pressing control-x. This takes you back to the terminal screen.
    2. You may need to flush your Mac’s DNS cache, so copy/paste the below command string into terminal, and press return.

dscacheutil -flushcache

You may have to add sudo to this command, for example:
sudo dscacheutil -flushcache

This completes the hosts file modification, so you should now be able to see your site here with us using your domain in your browser’s address bar.

When testing is complete you may undo these changes by repeating the steps above but removing the information entered in step 3.