Messed Up Hosts? How to Restore the Original Default /etc/hosts File in Mac OS X

Apr 12, 2014 - 13 Comments

The Original, unmodified hosts file in Mac OS X is easy to restore if need be

The hosts file is included on every computer and used by Mac OS to map IP addresses to host names. Because users may choose to adjust, change, or otherwise edit the hosts file for a variety of reasons, it can be easily subjected to user error, leading to a variety of undesirable network problems ranging from inaccessible network locations, network failures, web sites blocked or otherwise unable to load, even to failed iOS updates and various iTunes errors like the frequently encountered 17 and 3194 errors because the Apple servers have been blocked.

Fortunately, restoring the original default /etc/hosts file back to normal is pretty easy, and the best way to get back the original untouched default file is to simply overwrite the existing damaged hosts file with a new clean version that is a copy of what comes default in Mac OS X. An example of that has been included below for convenience, but you can retrieve it from another Mac if need be as well. No additional entries or modifications are included in the version below, which is a direct replica from that found in OS X Mavericks, making it safe to return to if you accidentally messed up the important hosts document during a change or adjustment.

You’ll want to copy the text below and paste it into a plain text file, stored at the /etc/hosts path. If you’re not sure how to do that, you can follow these instructions to learn how to edit the file the proper way from the command line and simply overwrite it with the hosts block below, or use TextEdit and save over the messed up version, which is what we’ll walk through below.

The Default & Original /etc/hosts File in Mac OS X Looks Like This

Contained within the code block is the original hosts file and the four default entries. Just copy and paste this over an existing hosts file then save it as plain text to restore it.

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## localhost broadcasthost
::1 localhost
fe80::1%lo0 localhost

Those familiar with the command line shouldn’t have a problem with this, but if you’re not quite sure what to do you can also complete the process from the TextEdit app as we’ll describe below:

Restore an Unmodified Original Hosts File to Mac OS X

TextEdit is the simple text editor bundled with every Mac, you’ll also need administrator access to complete this task since the hosts document is a system file in a restricted directory.

  1. Open TextEdit and paste the above code block into a new empty blank file
  2. Select All text and choose “Format > Make Plain Text” and click “OK
  3. Choose “File > Save As” and uncheck the box for “If no extension is provided use txt” – this is important, DO NOT INCLUDE A FILE EXTENSION
  4. Restore the default hosts file in Mac OS X

  5. Hit Command+Shift+G to bring up the “Go To Folder” window, now type in /etc/ and go
  6. Name the file ‘hosts’ and save, you’ll need to enter an administrator password to be able to write to this directory
  7. Restoring the original default hosts file to a Mac

Now to confirm the hosts file saved properly, go to the Terminal app and type the following:

cat /etc/hosts

That command should report the file to look like this:

The Original, unmodified hosts file in Mac OS X is easy to restore if need be

If it doesn’t look like the sample hosts file above, you did something wrong. The most common problems are usually not saving the file as plain text, accidentally adding the file extension, or naming it incorrectly, so double-check that. If you’re still having problems, you may not have overwritten the file properly.

You’ll probably want to flush DNS cache or just reboot the Mac for changes to take effect system-wide and have the hosts file restored.

This is really the easiest way to restore the hosts file if you have messed it up, if it has become overly cluttered with tons of entries, or somehow other rendered the hosts database completely unusable. You certainly don’t need to restore an entire Mac from a Time Machine backup or reinstall the OS to accomplish this.


Related articles:

Posted by: Paul Horowitz in Mac OS, Tips & Tricks, Troubleshooting


» Comments RSS Feed

  1. Lokesh Kumar Jain says:

    This worked on the Mac OS Sierra.
    That was stopping me to work with angularjs project. :)

  2. Ali Tahseen says:

    N.B : this won’t work on OSX El Capitan since the /etc/ folder is considered a restricted zone and thus every file in it is unmodifiable.
    instead you’ll have to edit the hosts file using terminal and thats what i did.


  3. Omar says:

    In fact if you do:
    ls -la /etc

    You can find the following file:

    If you cat it:
    # Host Database
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ## localhost broadcasthost
    ::1 localhost

    So, basically you just need to remove the current hosts file and copy the hosts~orig into /etc/hosts.

    This is what you can do at least on Yosemite.

  4. pin says:

    see /private/etc/hosts

  5. Yosemite Hosts says:

    Here is the default OS X Yosemite /etc/hosts file without modifications as found from cat /etc/hosts:

    ####### START AFTER THIS LINE ######
    # Host Database
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ## localhost broadcasthost

    ::1 localhost

    • DL says:

      When I type cat /etc/hosts into the terminal, it says that the file cannot be found… I’m also having trouble pinging localhost. Solutions?

  6. Lexxie says:

    This method changes the permissions on the hosts file!
    You have to use Nano (in Terminal) or Textwrangler to avoid that. I am not aware exactly what the vulnerabilities are of changed permissions on the hosts file, but you should NOT change them.

  7. Jerry says:

    will this work with mountain lion, or just maverick?

    • jtn says:

      Yes, it will work in OS X Mavericks.

      The /etc/hosts and /private/etc/hosts file are both the same on all versions of OS X, and most linux machines for that matter. The last address is loopback IPv6.

      And as @eric mentions, if you make a fresh file, be sure to properly chown permissions

  8. Eric says:

    Since it’s a manually made file, the owner is not the same.

    sudo chown root:wheel /etc/hosts
    sudo chmod 644 /etc/hosts

    • BrentM says:

      I’ve been having weird network issues on my Mac and before I go to the extent of rebuilding the OS I had a thought about the Hosts file.

      Adobe deleted it via Team Viewer because CC would not come out of trial mode and I was wondering what kind of problems that would or could cause.


Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site