How to edit the hosts file in OS X Lion (the very easy way)

One of the added security features to OS X Lion resulted in making edits to the OS X hosts file more difficult. This tutorial will show you how to edit the hosts file without having to use the Terminal or a complicated Application.

Please note: If you’re using OS X “Snow Leopard” (10.6) or lower, you’ll want to use this tutorial to edit your hosts file instead. The method outlined below is intended for Mac’s running OS X Lion (10.7) only.

  1. Start out by heading over to the TextWrangler download page and download TextWrangler.

    TextWrangler is a free text editor for OS X, and is actually a great program (in addition to being required for this tutorial). Install it as you would with most OS X Apps – open the .dmg file and drag TextWrangler to your Applications folder.

    Unlike most OS X Apps, you need to run this program once to complete the installation. So open your Applications folder and double-click TextWrangler to open it.

  2. You’ll be prompted to register TextWrangler, which is completely optional. Whatever you decide – make sure that Install the current command line tools is checked. Then click Skip Registration, Later or Register Now based on your decision.
  3. TextWrangler will now open – and now you can close it :)
  4. Open a Finder window and select Go from the Menu Bar, then Go to Folder… from the list.
  5. Enter in /etc then click Go.
  6. Inside the etc folder, locate the hosts file. Right-click (or control-click for single-button mouse folks) the hosts file, select Open With and then TextWrangler.

  7. click to enlarge

  8. TextWrangler will launch and open your hosts file.

  9. click to enlarge

  10. As soon as you make a change to the file, TextWrangler will display a message (see screenshot below) that says Are you sure you want to unlock “hosts”?. Since you do, click the Unlock button.
  11. Once you make your changes (and be careful – editing the hosts file incorrectly can cause a variety of problems) – save it. You’ll instantly be prompted to enter your password. Do so, and then click OK.
  12. That’s it – you’ve edited your hosts file.

Home » Mac » How to edit the hosts file in OS X Lion (the very easy way)

18 thoughts on “How to edit the hosts file in OS X Lion (the very easy way)”

  1. Emily Hierstein Sparkle

    I’ve used your solution before with no problems, thank you. However, when I tried today I get this error from TextWrangler when I try to save. “The authenticated save for this file failed (application error code: 20004)”. It skips asking for my password. Odd. (Mac OS X 10.11.6 and TW 5.5.1)

  2. Solved my problem after a lot of visited forums about this issue. Really helpful. A lot better than using the terminal and anything else. Thank you

  3. @5210c35b11287dd526849c7851c197f7:disqus – I just checked, the steps are exactly the same, everything is the same – the only difference is the GUI (those color icons etc). I’m still going to update the screenshots to avoid confusion tho. Cheers.

  4. Does anyone know what version of TextWrangler GUI is being shown in step 7 … because in the so called latest version 4.5 (3264)?

    TextWrangler 4.5 doesn’t look anything like the GUI header in Step 7 (with the color icons).

  5. Opps, I meant GasMask doesn’t seem to work with OSX10.8.3 (Mountain Lion). The 10.2.3 mention was my error.

  6. OMG thank you! after hours of trying to trouble shoot terminal, i did this in less than 5 mins. Thank you, thank you, thank you!!

  7. Perfect. Worked fine in Lion whereas the Terminal command to open the hosts file for editing (that worked in Snow Leopard) fails in Lion. Great workaround. Thanks!

  8. @Ross –
    Gasmask manages the edits you make independent of the actual file. It has its own editor, and I am assuming it is saving the different edits in its own file system space. My point was that gasmask is *easier* than editing the files manually.

  9. @Matt –

    I looked into Gasmask briefly, and read several times that once you use it to edit the hosts file, you have to continue using it otherwise changes will be disregarded if you edit w/ another app. I have NO idea if this is true – I did NOT download and test it out myself. I opted to go w/ this route as either way, you need to download a 3rd party program. I figured TextWrangler may be of some use (great text editor) in addition to being helpful for editing the hosts file. Whereas Gasmask serves only one purpose – to edit the hosts file…

    Perhaps you can help shed some light – when you use Gasmask in Lion, does it in fact save all changes and NOT revert them if you edit w/ another app?

  10. Pingback: How to edit the OS X hosts file – Simple Help

Leave a Comment

Your email address will not be published. Required fields are marked *