How to edit hosts file on Mac

A hosts file is a file that maps domain names to IP addresses. This article explains how to edit the hosts file on a Mac.

Editing hosts file on Mac

Follow the steps below to edit the hosts file on Mac:

  1. Navigate to Applications, then the Utilities folder and then click on the Terminal app to open the Terminal application. Alternatively, type Terminal in the Spotlight to open the Terminal application
  2. To open the hosts file for editing, copy either one of the command below and paste in the terminal window and press Enter:

    • sudo nano /private/etc/hosts  
    • sudo nano /etc/hosts  -- (on newer MacOS)
  3. Enter the password to edit the host file. (Note: The cursor will not move when the password is typed)

  4. Move the cursor to the bottom of the file and enter the server IP and domain name

    • SERVER_IP_ADDRESS domain.com/ SERVER_IP_ADDRESS www.domain.com : example (111.111.111.111 mydomain.com/ 111.111.111.111 www.mydomain.com:

      There must be a space between IP and domain name
  5. Save the changes by pressing control-o on your keyboard then return to accept the filename. Exit the editor by pressing control-x.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.