Hosts file questions

I'm not getting the hosts file to work in Yosemite, but instead of a plain what's wrong, I'd like to know a bit more about how it works in general. Here is the default hosts file plus one, except that I added line numbers for later and took out the comments:

  1. 127.0.0.1 localhost
  2. 255.255.255.255 broadcasthost
  3. ::1 localhost
  4. fe80::1%lo0 localhost [I've seen this elsewhere, but it was NOT on my default Yosemite file]


Q1: Line 1 uses a tab between the IP and localhost and lines 2 and 3 use spaces. Does it matter?

Q2: Some examples, even on this forum, show a forth line "fe80::1%lo0 localhost", or something similar. What is that for, and do I need it?

Q3: Some hosts files add the new host lines at the end (line 5). Some add the new lines between lines 2 and 3. Does it matter?

Q4: What does the line 3 do?

Q5: The added lines look different as I see them around the web:

127.0.0.1 domain_name

domain_name 127.0.0.1

domain_name CNAME 127.0.0.1 (I have no idea what CNAME is)

Q6: And, similar to Q1 above, is there any difference between using IP[tab]domain versus IP[space]domain?


Thanks.

MacBook Pro, OS X Yosemite (10.10), 4 GB

Posted on Feb 22, 2015 5:33 PM

Reply
2 replies

Feb 22, 2015 6:08 PM in response to Tim Murray2

First, Caution messing with the /etc/hosts file, as if you mess it up, you can break your internet connections. If you insist on modifying your /etc/hosts file, suggest you make a backup copy you can always put back into place with the same owner and permissions as the original.


Depending on the origin of the operating system the format of the hosts file is different. Mac OS X /etc/hosts file came from FreeBSD, so that is the format used in Mac OS X

<https://www.freebsd.org/doc/handbook/configtuning-configfiles.html>

<https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/ man5/hosts.5.html>


The key bit of information about the format is:

[Internet address] [official hostname] [alias1] [alias2] ...

Q1 - white space is tabs and/or spaces it does not matter.

Q2 - fe80::1%lo0 - it is an IPv6 local-link localhost address

<http://superuser.com/questions/241642/what-is-the-relevance-of-fe801lo0-localhos t-in-etc-hosts>

Q3 - Does not matter, except a search starts at the beginning of the file. So "Official hostname" and/or "Alias" that matches the search is the IP address returned.

Q4 - Another IPv6 localhost addressing shorthand.

Q5 - See above answer based on where the operating originated (see FreeBSD for Mac OS X) - NOTE: Mac OS X only borrowed parts of FreeBSD, it is NOT FreeBSD. Rather it is a blend of Carnage Mellon University MACH Kernel and FreeBSD Unix API's and many FreeBSD Unix commands and utlities. On top of that is a huge amount of Mac OS X content for device drivers, application GUI frameworks, Apps, and years and years of extensive kernel changes.

Q6 - White space is all that matters (tabs and spaces are both white space).


See the "man hosts" page (link provided above) and the FreeBSD configuration link above.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Hosts file questions

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