why cannot I edit my `hosts` file?

I'm trying to edit my hosts file, because doing ssh <some host in hosts> fails to translate to ip.

according to the Finder UI it is found under:

enter image description here however when trying to run cat hosts from the terminal I get an error:

➜  /etc  cat hosts
cat: hosts: No such file or directory

I tried to create a new hosts file but then I see another one is created next to the first one

enter image description here

but when I try to edit the second hosts I need to duplicate to anther destination. I copy it to /etc and again the first problem occurs.

I have tried to change the permissions to everyone can read and write. But yet it didn't help.


Solution 1:

There shouldn't be a way to have two identically named files in the /etc folder. Can you do a Get Info on the original and verify the Name & Extension (and that the extension is not hidden, and that there are no spaces at the end of the name)?

Solution 2:

Usually only the root user is allowed to modify the file hosts.

To do that and fix your hosts file or your /etc folder (depending where you applied your read/write permissions) follow these steps:

  1. Throw away your newly created hosts file (but not the old one!)
  2. Repair your permissions with Disk Utility. enter image description here
  3. Open Terminal and enter sudo nano /etc/hosts and hit
  4. Enter your password (it will not be shown!) and hit
    The standard hosts file in Yosemite looks like this: nano
  5. Edit your hosts file.
    The format for each line is IP-address, then a tab or a single space and the hostname(s). Terminate the file with an empty trailing line.
  6. write the changes to disk with ctrlO followed by and exit nano with ctrlx
  7. Enter exit, hit and quit Terminal.app

As an alternative for the steps 3-7 you may download and install hosts.prefpane and enter your additional hosts there.