How to edit the system hosts file on Mac using TextEdit

Text file hosts — little known, but very important thing. It contains valuable information for going online — database of domain names and used when they are translated into the network addresses of nodes.

Sometimes you need to make some changes. How to do it?

Advanced users make edits to hosts through OS X Terminal. But for those, who prefers to use a more familiar graphical interface, there is another way — editing through text editor TextEdit.

Required note: without need and without proper knowledge in hosts it is better not to change anything. Incorrectly formatted file can cause problems with DNS servers and make it impossible to visit certain sites.

If you work with OS X 10.11 El Capitan or a newer version of the system, first we will have to disable the new protection from Apple called System Integrity Protection (SIP).

  1. Restart your Mac and hold the Command key (⌘) + R. It will load into safe mode.
  2. On the menu bar, select Utilities, then Terminal.
  3. Enter the following command in the Terminal: csrutil disable; reboot
  4. Press Return (Enter).
  5. You will see a message about, that System Integrity Protection is disabled, and to accept Mac changes, a reboot is required, which will happen right away.

To check the status of SIP (on or off), open a terminal and enter the following command: csrutil statusIf done correctly, The word Terminal will appear in the Terminal’s response (is disabled). Enabled (included) means, that something went wrong.

Now you can begin to edit the hosts file. For this:

  1. Close the TextEdit application, if it is open.
  2. Open Terminal. The easiest way to do it — enter the word «Terminal» in spotlight search (icon with a magnifying glass in the upper right corner).
  3. Copy the following command to the Terminal command line: sudo open -a TextEdit /etc/hosts
  4. Press Return (Enter). If necessary, enter the administrator password.
  5. The hosts file will open in TextEdit. Make the necessary changes and save them via the menu bar (File —> Save) or the keyboard command Command (⌘) + S. Next, close TextEdit first, then Terminal.