which is better/more correct for /etc/hosts

Vu Pham vu at sivell.com
Wed Dec 12 13:40:36 PST 2007



C M Reinehr wrote:
> Doug,
> 
> On Wednesday 12 December 2007 11:55, Douglas J Hunley wrote:
>> is this better:
>> 192.168.10.1	servera,serverb,serverc
>> or this:
>> 192.168.10.1	servera
>> 192.168.10.1	serverb
>> 192.168.10.1	serverc
>>
>> and why is it better?
> 
> This probably is wasting bandwidth as I'm sure you've already read the manual 
> and are looking for something deeper, but it states clearly:
> 
>> This manual page describes the format of the /etc/hosts file. This file is
>> a simple text file that associates IP addresses with hostnames, one line
>> per IP address. For each host a single line should be present with the
>> following information:
>>
>>
>>  IP_address canonical_hostname [aliases...]
> 
> I interpret this to mean that each line should reference a unique ip address 
> rather than duplicate the ip addresses of previous lines. My fear is that 
> placing each alias on a separate line would result either in the second & 
> third alias being ignored, or in the first and second being 
> ignored/overwritten by the last entry.
> 

I think /etc/hosts is for finding an IP address for a given name 
therefore different names to one ip address should work.

Below are three names in my /etc/hosts and the ping results.

[root at o ~]#  cat /etc/hosts
[...]
192.168.249.1   router
192.168.249.1   routertoo
192.168.249.1   whocares

[root at o ~]# ping router
PING router (192.168.249.1) 56(84) bytes of data.
64 bytes from router (192.168.249.1): icmp_seq=1 ttl=255 time=0.330 ms
64 bytes from router (192.168.249.1): icmp_seq=2 ttl=255 time=0.317 ms

--- router ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.317/0.323/0.330/0.019 ms
[root at o ~]# ping routertoo
PING routertoo (192.168.249.1) 56(84) bytes of data.
64 bytes from router (192.168.249.1): icmp_seq=1 ttl=255 time=0.314 ms
64 bytes from router (192.168.249.1): icmp_seq=2 ttl=255 time=0.312 ms

--- routertoo ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.312/0.313/0.314/0.001 ms
[root at o ~]# ping whocares
PING whocares (192.168.249.1) 56(84) bytes of data.
64 bytes from router (192.168.249.1): icmp_seq=1 ttl=255 time=0.319 ms
64 bytes from router (192.168.249.1): icmp_seq=2 ttl=255 time=0.311 ms

--- whocares ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.311/0.315/0.319/0.004 ms
[root at o ~]#

Vu




More information about the Linux-users mailing list