How to edit the OS X hosts file

by Ross McKillop on August 23, 2010

Mac

This tutorial will guide you through the steps required to edit the hosts file in OS X.

Please Note: if you’re using OS X Lion (10.7), the method outlined below will not work. If you’re using Lion, see this tutorial to edit your hosts file. If you’re using OS X Snow Leopard (10.6) or earlier – the method outlined below will work just fine for you.

Note: editing the hosts file can have fairly adverse effects to your Mac if you’re not sure what you’re doing. This tutorial will show you how to edit it, but be careful doing so.

  1. Start out by opening a Terminal. To do so, open your Applications folder, select the Utilities folder, and then double-click Terminal.

  2. click to enlarge

  3. At the Terminal prompt, enter the following line:

    sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

    and then hit enter.


  4. click to enlarge

  5. At this point you’ll be prompted to enter your password. Do so, then hit enter.

  6. click to enlarge

  7. Your hosts file will now open in TextEdit. From here you can make any changes you deem fit/need.
  8. When you’re done, save the file.
  9. That’s it – you’re done. You can now close the Terminal. Should you ever need to re-edit your hosts file, follow the instructions from the beginning.

  10. click to enlarge