How to Edit the Hosts File on a Mac
Editing your /etc/hosts file is useful for testing a new website. It allows you to point a domain name (such as www.mynewdomain.com) at a custom IP address on your local computer only. In this article, we will use the IP address 1.2.3.4 as...
Table of Contents
Method 1 of 1:
Editing Using TextEdit
-
Open the Terminal app. You can use the Spotlight search functionality to do this. -
Copy the/etc/hostsfile to a local file to be able to edit it.- Type the command:
cp /etc/hosts hosts.
- Type the command:
-
Edit the copy of thehostsfile using TextEdit.- Type the command:
open /Applications/TextEdit.app hosts
- Type the command:
-
Add your new hosts file entry as a single line at the bottom of the file. The format of the line is "1.2.3.4 www.mynewdomain.com", where1.2.3.4is the IP address andwww.mynewdomain.comis the domain you want to point at the IP address. -
Copy the file hosts over top of the system /etc/hosts file. Do this by typing:sudo cp hosts /etc/hosts.- You will be prompted for your password at this point because you are overwriting the system
/etc/hostsfile. Note that on the command line, when you type a character into the password field, nothing at all will appear.
- You will be prompted for your password at this point because you are overwriting the system
-
Test your new local domain name by typing the domain name into your web browser.- Note: your new domain name will not work until you have a web server responding at the IP address you specify!
You've just finished reading the article "How to Edit the Hosts File on a Mac" edited by the TipsMake team. You can save how-to-edit-the-hosts-file-on-a-mac.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.
Read more





