How to Edit your Hosts File on a Mac

Your computer uses the HOSTS file to look up/resolve domain names to an IP address. This file can force your computer to resolve your website to a specific IP address rather than using the DNS entries indicated by the domain’s name servers.

Manually configuring your domain with the IP address of your InMotion Hosting server will allow you to point a domain name to a different server location using an IP address. A HOSTS file change is intended to be temporary and should not be used with the published website.

Video – How to Edit Your HOSTS File on a Mac

Edit HOSTS File in a Terminal Client

You can use a terminal client application, or the one Apple provides in its operating system when editing your HOSTS file.

  1. Open the Terminal client of your choice.
  2. Edit the HOSTS file in the terminal window using one of the commands below.
    sudo nano /private/etc/hosts

    For newer versions of Mac OS, use this command:
    sudo nano /etc/hosts
  3. Enter your Apple login password for your device.
  4. Edit the HOSTS file by adding these two lines.
    SERVER_IP_ADDRESS domain.com
    SERVER_IP_ADDRESS www.domain.com

    This is an example of how it would appear in the HOSTS file:
    86.75.30.9 domain.com
    86.75.30.9 www.domain.com

    NOTE: Replace “domain.com” with your actual domain name. If you are unsure which IP address to use, please contact our Support Department for further assistance.

  5. Save your changes by pressing Control-O on your keyboard, then hit the enter key to accept the filename.
  6. Exit the editor by pressing Control-X.

How to Flush the DNS Cache

You may need to flush your Mac’s DNS cache for the HOSTS file change to work. Use the following command to flush the cache:

  1. Open your Terminal client.
  2. Type in the following command: dscacheutil -flushcache
  3. Hit enter to run the command.

This completes the HOSTS file modification. You can now see your website using a domain name pointing to the specific IP address you added to the HOSTS file. If you no longer need the changes in the HOSTS file you can repeat the steps above and remove the changes you added.

If you are using Windows, please refer to our guide on how to Modify Your Hosts File Using Windows.

Learn more about DNS management with our DNS and Nameserver Changes Education Channel.

Secure VPS HostingEnjoy high-performance, lightning-fast servers with increased security and maximum up-time with our Secure VPS Hosting!

check markLinux VPS check markcPanel or Control Web Panel check markScalable check markWebsite Migration Assistance

Linux VPS Hosting

Share this Article
InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting