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.
{ 18 comments… add one }
  • Wind January 26, 2012, 1:39 am

    Or you know,

    sudo nano /etc/hosts

    in Terminal.

  • Ross McKillop January 26, 2012, 1:45 am

    Wind – absolutely yes. The point was to avoid using Terminal entirely though.

  • Matt Miller January 26, 2012, 11:54 pm

    Why not use gasmask. It is way easer than this. I have edited my hosts file by hand for years and this is really a good program.

  • Ross McKillop January 27, 2012, 9:28 am

    @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?

  • Matt Miller January 27, 2012, 12:00 pm

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

  • Scott January 30, 2012, 11:57 am

    The point was to avoid using Terminal entirely though.
    Sometimes the terminal is the very easy way. :)

  • Barry February 21, 2012, 1:24 am

    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!

  • ekburgess19 August 5, 2012, 12:50 am

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

  • Oce January 31, 2013, 8:15 pm

    Dang man, just cured my headache!!!!! Thank you!!!

  • MacD April 3, 2013, 6:48 am

    GasMask doesn’t seem to work with OSX 10.2.3.
    TextWragler works great with OSX 10.8.3.

  • MacD April 3, 2013, 6:50 am

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

  • MacD April 12, 2013, 3:49 am

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

  • Ross McKillop April 12, 2013, 5:20 am

    I was using 4.0 – I just upgraded to the latest version, I’ll update the screenshots shortly. Thanks for letting me know the GUI had changed!

  • Ross McKillop April 12, 2013, 5:24 am

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

  • sandra May 3, 2013, 3:45 am

    Thanks – that is so helpful.

  • ajnoguerra July 12, 2013, 1:41 am

    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

  • Emily Hierstein Sparkle September 8, 2016, 9:46 am

    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)

Leave a Comment