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 the example IP, but you will need a web server at the IP address you use to respond to your testing.

Steps

Editing Using TextEdit

1

Open the Terminal app. You can use the Spotlight search functionality to do this.

2

Copy the /etc/hosts file to a local file to be able to edit it.

Type the command: cp /etc/hosts hosts .

3

Edit the copy of the hosts file using TextEdit.

Type the command: open /Applications/TextEdit.app hosts

4

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", where 1.2.3.4 is the IP address and www.mynewdomain.com is the domain you want to point at the IP address.

5

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/hosts file. Note that on the command line, when you type a character into the password field, nothing at all will appear.

6

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!

Community Q&A

If this question (or a similar one) is answered twice in this section, please click here to let us know.

Tips

After you are done testing with the /etc/hosts entry you created, make sure to remove it from the hosts file. The domain you've set up is available only on your computer and will cause some confusion if you connect to a different site than other computers visiting the same domain.

To remove the new /etc/hosts file entry you created, perform the same process, but just delete the line you added when editing the hosts file in TextEdit.

Warnings

This method is used for testing, but it can also be used to pull pranks on other people. Make sure there is not suspicious entries in your host file for domains (such as www.yahoo.com) that you would not want changed on your computer only.

This method can be dangerous if you are not careful about what domains you put into /etc/hosts