HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

what is the impact of localhost not at first line of /etc/hosts?

 
SOLVED
Go to solution
stephen peng
Valued Contributor

what is the impact of localhost not at first line of /etc/hosts?

dear all,
could you please explain what is the impact of localhost not at first line of /etc/hosts? I've got several servers thus configured, and I've met a situation, see
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1427566
would that be relevant?

thanks a lot.
5 REPLIES
stephen peng
Valued Contributor

Re: what is the impact of localhost not at first line of /etc/hosts?

or it is not wrong placing localhost wherever at /etc/hosts?
James R. Ferguson
Acclaimed Contributor
Solution

Re: what is the impact of localhost not at first line of /etc/hosts?

Hi Stephen:

You can place the 'localhost' ('loopback') entry anywhere in '/etc/hosts' you desire. The '/etc/hosts' file is searched sequentially from the beginning by 'gethostent()' routines.

Since a virgin (initial) '/etc/hosts' file is deposited with only a 'localhost' entry (see: '/usr/newconfig/etc/hosts') it is logical that this entry occurs first.

Regards!

...JRF...
stephen peng
Valued Contributor

Re: what is the impact of localhost not at first line of /etc/hosts?

thanks james, you corrected my mind. but this finding really blocked from dealing the situation I met before.
TwoProc
Honored Contributor

Re: what is the impact of localhost not at first line of /etc/hosts?

I looked at the other thread you mentioned, and I see no connection of that problem to the location of localhost in the /etc/hosts file.

I've always preferred it first, just because it's the first one listed in a new /etc/hosts file.

Unless - you had 127.0.0.1 defined as something else(lo0 for example) higher up in the file, and for some reason you needed not just localhost to be 127.0.0.1 but the reverse, you needed 127.0.0.1 to be localhost, in which case, the first assignment of 127.0.0.1 would return the name of the FIRST entry in /etc/hosts assigned to 127.0.0.1, which could be something like
127.0.0.1 lo0
...
...
stuff deleted
...
...
127.0.0.1 loopback
...
stuff deleted
...
...
127.0.0.1 localhost


if ran something on the above /etc/hosts file which need to reverse lookup 127.0.0.1, it would return lo0, not localhost.

So, I'd say make sure it is the first definition for 127.0.0.1 in the file.
We are the people our parents warned us about --Jimmy Buffett
stephen peng
Valued Contributor

Re: what is the impact of localhost not at first line of /etc/hosts?

thank you for your reply john.
look forward to someone who could make deeper conclusion about what I met before, or explain more about the role default gateway and nameserver play at that situation.

regards