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...

Method 1 of 1:

Editing Using TextEdit

  1. Picture 1 of How to Edit the Hosts File on a Mac
    Open the Terminal app. You can use the Spotlight search functionality to do this.
  2. Picture 2 of How to Edit the Hosts File on a Mac
    Copy the /etc/hosts file to a local file to be able to edit it.
    1. Type the command: cp /etc/hosts hosts .
  3. Picture 3 of How to Edit the Hosts File on a Mac
    Edit the copy of the hosts file using TextEdit.
    1. Type the command: open /Applications/TextEdit.app hosts
  4. Picture 4 of How to Edit the Hosts File on a Mac
    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. Picture 5 of How to Edit the Hosts File on a Mac
    Copy the file hosts over top of the system /etc/hosts file. Do this by typing: sudo cp hosts /etc/hosts.
    1. 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. Picture 6 of How to Edit the Hosts File on a Mac
    Test your new local domain name by typing the domain name into your web browser.
    1. Note: your new domain name will not work until you have a web server responding at the IP address you specify!
Update 04 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile