[CentOS] /etc/hosts - hostname alias for 127.0.0.1

Tue Mar 8 01:54:37 UTC 2011
Robert Spangler <mlists at zoominternet.net>

On Monday 07 March 2011 15:22, the following was written:

>  Keith Keller wrote:
>  > On Mon, Mar 07, 2011 at 10:34:24AM -0600, Sean Carolan wrote:
>  >> Can anyone point out reasons why it might be a bad idea to put this
>  >> sort of line in your /etc/hosts file, eg, pointing the FQDN at the
>  >> loopback address?
>  >>
>  >> 127.0.0.1    hostname.domain.com hostname   localhost
>  >> localhost.localdomain

You can do this if you want.  The host file is only used by the machine it is 
on.  As to bad Idea it would depend on what you are trying to do and if the 
process you are trying to reach locally is listening on that ip address.

I have only the short name configured on 127.0.0.1

>  > Would the application work with a hosts entry like this?

If the process what configured to listen on that interface, yes.

>  > 127.0.0.1    hostname.dummy   localhost localhost.localdomain
>  >
>  > (Make sure you pick .dummy so as not to interfere with any other DNS.)

Why do you need the '.dummy'? short name should work fine.

>  > In theory you could leave off .dummy, but then you risk hostname being
>  > completed with the search domain in resolv.conf, which creates the
>  > problems already mentioned with putting hostname.domain.com in
>  > /etc/hosts.  (I have not tested this at all!)

Resolv.conf is not used for the hosts file, it is used for DNS.  I have my 
short name configured to the lo interface and the FQDN to the real ip 
address.  If I ping the short name I get this:

etc $ ping -c 3 bms
PING bms (127.0.0.1) 56(84) bytes of data.
64 bytes from bms (127.0.0.1): icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from bms (127.0.0.1): icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from bms (127.0.0.1): icmp_seq=3 ttl=64 time=0.037 ms

If I ping the FQDN I get this:

etc $ ping -c 3 bms.domain.com
PING bms.domain.com (x.x.x.x) 56(84) bytes of data.
64 bytes from bms.domain.com (x.x.x.x): icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from bms.domain.com (x.x.x.x): icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from bms.domain.com (x.x.x.x): icmp_seq=3 ttl=64 time=0.093 ms


>  And giving it 127.0.0.1 would tell it others to ignore it, I think. Where
>  did your user come up with this idea - clearly, they have *no* clue what
>  they're doing, and need at least a brown bag lunch about TCP/IP, and they
>  should not be allowed to dictate this. Their "idea" is a bug, and needs to
>  be fixed.

How do you figure this?  The hosts file is ONLY used locally.  If someone is 
looking you up they are using DNS if they don't have you configured 
in "their" hosts file.

Their "idea" might be flaws but it is not bugs.


-- 

Regards
Robert

Linux
The adventure of a lifetime.

Linux User #296285
Get Counted
http://counter.li.org/