This article is also available in:

How do I find and edit host files on my Mac?

The Hosts file is an essential tool to change the way your computer sees a particular website.

Although most users will never need to edit their hosts file, a web developer or user may need to edit the file to view a new site under development.

In order for your computer to display your test site rather than the live site, you must add the IP address of the test site, as well as the domain name, to the Hosts file.

As long as this information is contained in your Hosts file, your browser will redirect the request to display the site to the specified IP address.

This allows us to test the functionality without changing the DNS of our production site.

We have included step-by-step instructions to locate the Hosts file:

But where is the Hosts file on our Mac, and how to edit it? The Hosts file on a Mac is located in the folder /etc, in the file /hosts.

To edit the file, follow the steps below.

Launch the MacOS Terminal application.
Go to the Finder, then click Go.
Click Utilities.
Double-click Terminal to launch the Terminal window.
Now enter the nano command for the hosts file in the folder /etc

Next, enter the password to allow your user to change access to the file.
Next, use the arrow keys to move the cursor to the bottom of the file. On a newline, enter the IP address of the test server and the domain name you want to use for that IP address. (for example: ' VOTREDOMAINE.FR`. Of course: will have to be replaced by the IP address of the server and will have to be replaced by your own domain name). In addition, if your site was using the www. , you will also need to put the following line: ` WWW.VOTREDOMAINE. This saves the changes made to the file.
Now press Ctrl+X to exit the nano editor.
Finally, to update our browser’s DNS records and make these changes, enter the command killall for -HUP mDNSResponder:

Note that Firefox browsers may have a setting called DNS on HTTPS enabled. This makes this method inefficient to find the location of Mac host file

Updated on: 24/10/2023

Was this article helpful?

Share your feedback


Thank you!