Format of /etc/hosts file entry

General support questions
Post Reply
kiransharma755
Posts: 46
Joined: 2015/02/27 14:30:54

Format of /etc/hosts file entry

Post by kiransharma755 » 2015/07/21 23:23:18

I always get confused what should the second column of the host file. Should it be a fqdn or alias? or it does not matter?

eg.
IPAddress Hostname Alias
127.0.0.1 localhost deep.openna.com
208.164.186.1 deep.openna.com deep
208.164.186.2 mail.openna.com mail
208.164.186.3 web.openna.com web


the above example has fqdn in the 2nd column but in first row, the second column is the alias name. When I check my host ( I am not a linux admin but trying to be ), has mixed. for the local server, the 2nd column has alias, but for the other server, the 2nd column has fqdn. more confused.

If any one could help me to understand, that would be great.

Thanks
K

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Format of /etc/hosts file entry

Post by gerald_clark » 2015/07/21 23:32:16

man 5 hosts
should solve the mystery.

kiransharma755
Posts: 46
Joined: 2015/02/27 14:30:54

Re: Format of /etc/hosts file entry

Post by kiransharma755 » 2015/07/23 18:50:47

gerald_clark wrote:man 5 hosts
should solve the mystery.
No, it does not.

I have done my homework before I asked you. I am seriously working on it and want to understand. As I said, when I checked man(5) hosts, it says

Internet address
official host name
aliases

what is official hostname? I think this should be myhost(.mydomain.com). This is because official hostname is the short name . the long name is the fqdn not the hostname.

So it does not work that way too as I have seen fqdn in the 2nd column.

Can I conclude that it does not matter?

Also, in another note, I have seen hostname as fqdn. Is not hostname different from dnqn or we can use them interchangeable ? or does not matter?

thanks
Kiran

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Format of /etc/hosts file entry

Post by gerald_clark » 2015/07/23 18:59:10

On my CentOS 6 system, man hosts says each line should be present with the following information:

IP_address canonical_hostname [aliases...]


There are examples at the bottom of the page.

scottro
Forum Moderator
Posts: 2556
Joined: 2007/09/03 21:18:09
Location: NYC
Contact:

Re: Format of /etc/hosts file entry

Post by scottro » 2015/07/23 22:31:02

Odd, my CentOS-6 doesn't have a man hosts.

Anyway, I do

192.168.1.5 scott1.scottro.net scott1


I've also found--never really kept track of this but on some machines, not having this will make things like startx hang which it does hosts -f, that for the 127.0.0.1 address, I have things like

127.0.0.1 scott1.scottro.net scott1 localhost.localdomain localhost.

That's the order I will have it in and it's never broken anything. Wonder why I don't have man hosts. <shrug>
New users should check the FAQ and Read Me First pages

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Format of /etc/hosts file entry

Post by gerald_clark » 2015/07/23 23:08:57

It's supplied by man-pages-3.22-20.el6.noarch.rpm

Post Reply