You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

What is the difference between private/etc/hosts and etc/hosts?

I was attempting to modify my iMac 'hosts' file in terminal and tried the usual sudo nano /private/etc/hosts. It would bring up an empty page. I thought the hosts file was simply empty. I added the entries I wanted to block and when I tried to exit and save (^o or ^x and choosing yes), i would get the error '/private/etc/hosts: No file exists' (or something to that effect).

After some researching, I tried using 'sudo nano /etc/hosts' and it brought up what looks like the hosts file (It has the same entries as I have on my MBP running the same OS when I sudo nano /private/etc/hosts)

Is there a difference in the file in /private/etc/hosts and /etc/hosts ?
Does that mean I have a problem with my iMacs' host file?

iMac, Mac OS X (10.6.8)

Posted on Feb 20, 2013 5:38 AM

Reply
20 replies

Feb 20, 2013 11:18 AM in response to WZZZ

Hi WZZZ,

Yes, when I go/private in a finder window it shows 4 directories: etc, tftpboot, tmp and var. When I open etc, I see the hosts file (there is also 'hostsconfig', 'hostsconfig~orig', 'hosts' and 'hosts.equiv'). Clicking on 'hosts' opens text edit and does display the file with entries, including the ones I added. So it seems all is well.


It doesn't really explain why sudo nano /private/etc/hosts brings up a blank file when I use terminal though. Any thoughts?


Sorry if my reply is so verbose, just wanted to report in detail. Thank you very much for your help!

Feb 20, 2013 11:23 AM in response to ds store

Hi ds_store,


Thanks for our response! You may be right about the /private/etc/hosts path being restricted. Although, I am able to access the hosts file using that path on my MBP. Both are running OS10.6.8. Perhaps my iMac is configured differently (although I could not for the life of me recall any tinkering on my part that would have done that).

Feb 20, 2013 11:29 AM in response to chungster

So if I understand correctly the 'hosts' file from both paths, /private/etc/ and /etc/ is the exact same file?

Should I be concerned about the failure / inaccessibility of the hosts file via /private/etc/hosts in terminal?

As mentioned above to WZZZ, I am able to see the proper entries in the hosts file when I access it as he suggested (via the go command in finder).

Feb 20, 2013 1:28 PM in response to WZZZ

Hmmm, alias? Where do you see that?

Technically it is a file system "Symbolic Link" which is similar to a Mac OS X Finder Alias, but different.


Symbolic Links are dereferenced by the file system drivers. Aliases are dereferenced by code above the file system, so strict Unix command line commands cannot use an Alias to find a file.


There are also file system "Hard Links" which are yet another similar to an Alias, but totally different.


Each has its advantages, and their limitations.

Feb 20, 2013 1:36 PM in response to chungster

chungster wrote:

I just tried the 'sudo nano /private/etc/hosts' via terminal and it brought up a list of entries (not a blank page like before). I promise I wasn't on drugs last night, but somehow all seems ok!


You were tired and mistyped, nano created a new file at that location is likley what occured.




Hmmm, alias? Where do you see that?


At / (root directory)


There is a whole smathering of hidden files and folders there if you enable invisble things.

Feb 20, 2013 1:49 PM in response to WZZZ

But since it's a symlink (not to be confused with a Finder alias) to /private/etc, I still don't understand ds store's screenshot showing etc as an alias. Why is that showing as a Finder folder with the alias icon?

The Finder can see that it is a Symbolic Link, and since Aliases and Symlinks perform similar services, the Finder is being lazy and tagging both Aliases and Symbolic Links as "Alias".

But /etc would not function as a Finder Alias, and really needs to be a Symbolic Link, as the various Mac OS X commands, utilities, daemons, etc... would fail if /etc was an Alias.

Feb 20, 2013 2:18 PM in response to ds store

I AM showing all invisibles. That's where the Get Info for etc is coming from, which is showing etc without the alias symbol. No matter what I try it comes up without the alias. This is on 10.6. BobHarris is saying that it really shouldn't be showing as an alias, since it's a symlink.


Maybe it's showing like that with TextWrangler on yours? I'll have to try TW later.

Feb 20, 2013 2:35 PM in response to WZZZ

There is a etc folder "alias" or "symbolic link" at the root directory which if you double click on it it opens /private/etc


So if you sudo pico /etc/hosts it's the same as sudo pico /private/etc/hosts


If yours is deleted, then it's likely no big deal. Resinstall OS X over itself and it likely will return it.

What is the difference between private/etc/hosts and etc/hosts?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.