1753797 Members
7215 Online
108805 Solutions
New Discussion юеВ

/etc/hosts file entries

 
Ravi Yeddanapudi
Occasional Contributor

/etc/hosts file entries

In our environment here there is an application requirement to have multiple IP
Addresses ( of terminals ) point to a single alias name.

The typical entries would look like :

IPADDR-1 ALIAS-1 # COMMENT-1
IPADDR-2 ALIAS-2 # COMMENT-2

The alias name is picked up by a script using " who am i -R " option in the
application. It has been observed that the alias names are sometimes ( very
random ) not picked up correctly.

Any ideas as to what is the method in which who am i -R works and if I can have
such entries in /etc/hosts.

Thanks for your help.

Regards,
Ravi
3 REPLIES 3
Chris Anoruo_1
Frequent Advisor

Re: /etc/hosts file entries

Hi Ravi,

The output of who am i -R is as soon below:
username ttyp3 Mar 22 12:55 (ip address)
You can use/read the online manual for 'who' (man who) , I think that will
assist you.
Ravi Yeddanapudi
Occasional Contributor

Re: /etc/hosts file entries

I have checked on the man. It says that it would do gethostbyname or
gethostbyaddr as the case may be.

Since we have multiple IP Address entries with the same alias name defined, the
command sometimes is returning a different alias name which appears to be
picked up at random.

I hope I made my problem clear. Please help.


Regards,
Ravi
user not active
Frequent Advisor

Re: /etc/hosts file entries

I found the following info which may be useful ?

According to the manual "Administering ARPA Services" page 2-10,
"Adding Remote Connectivity (Edit /etc/hosts)", If your host has more
than one IP address (for multiple network interfaces),you must addd entries for
every IP address. These entries must have the same official host name but
different aliases.

When the other machine refers to the hosts file for the hostname to IP address
resolution, only the first entry IP address is taken even though the machine is
on the second network.

For example,

Machine test2 has two network cards with IP address 15.19.65.1 and 16.19.65.1

The /etc/hosts file has the following content

15.19.65.1 test2 test2_if1
16.19.65.1 test2 test2_if2

When the client with IP address 16.19.65.2 run command telnet test2 it uses
the 15.19.65.1

Even though the book says that you must have multiple entries in /etc/hosts
with the official name first, and aliases second, this can be misleading:

Say I have a system named test with 2 interfaces:

1.2.3.4 test1 first
1.2.3.5 test1 second

If I do a gethostbyname() call, perhaps by doing a nslookup:

% nslookup test1
Name: test1
Address: 1.2.3.4
Aliases: first

So, the lookup of the official hostname will ALWAYS return the first entry from
the /etc/hosts table.

% nslookup first
Name: test1
Address: 1.2.3.4
Aliases: first

% nslookup second
Name: test1
Address: 1.2.3.5
Aliases: second

So, if a program wants to lookup an alias, it will be able to find the
canonical/official host name. This is the desirable behavior. Are you sure the
syntax in /etc/hosts is correct and is DNS involved at all in the equation ?

If you have unique /etc/hosts on each host. List the appropriate official
address first. So, on Client A's /etc/host, have the first official address of
Server A be 15.19.65.2 as in :

Client A /etc/host:
15.19.65.2 ServerA firstnic
16.19.65.2 ServerA secondnic

Client B /etc/host:
16.19.65.2 ServerA secondnic
15.19.65.2 ServerA firstnic

Then you could use the nsswitch.conf file (switch(4)) to reference /etc/hosts
first and DNS second ? may be of some help, hopefully someone with more
networking knowledge than I maybe able to confirm this or fill in any gaps ?