How to Edit the Hosts File on a Mac

Open the Terminal app., Copy the /etc/hosts file to a local file to be able to edit it., Edit the copy of the hosts file using TextEdit., Add your new hosts file entry as a single line at the bottom of the file., Copy the file hosts over top of the...

6 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Open the Terminal app.

    You can use the Spotlight search functionality to do this.
  2. Step 2: Copy the /etc/hosts file to a local file to be able to edit it.

    Type the command: cp /etc/hosts hosts . , Type the command: open /Applications/TextEdit.app hosts , 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. , 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. , Note: your new domain name will not work until you have a web server responding at the IP address you specify!
  3. Step 3: Edit the copy of the hosts file using TextEdit.

  4. Step 4: Add your new hosts file entry as a single line at the bottom of the file.

  5. Step 5: Copy the file hosts over top of the system /etc/hosts file.

  6. Step 6: Test your new local domain name by typing the domain name into your web browser.

Detailed Guide

You can use the Spotlight search functionality to do this.

Type the command: cp /etc/hosts hosts . , Type the command: open /Applications/TextEdit.app hosts , 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. , 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. , Note: your new domain name will not work until you have a web server responding at the IP address you specify!

About the Author

N

Natalie Hall

Writer and educator with a focus on practical DIY projects knowledge.

28 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: