Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InetAddress.getLocalHost retrieving 127.0.0.1, not the actual IP Address

843790Oct 17 2006 — edited Oct 18 2006
I am using the following code :
try{
InetAddress iaddr = InetAddress.getLocalHost();
String ipaddr = iaddr.getHostAddress();
System.out.println("IP= "+ipaddr);
}catch(UnknownHostException ex){
ex.getMessage();
}

to get the IP address of the server on which this code is running.

We are actually trying to set up different machines (other than the Production machine) for Failover of the Application. So, we need to get the IP address of the machine on which the application is running in the code.

For one machine, the above code works perfectly OK.

But, for the three Production machines, the IP address that we are retrieving using the getLocalHost function is fetching the localhost and not the IP address of the machine. That is instead of fetching the IP � a.b.c.d (I am not writing the actual IP in this mail :) ) ... it is fetching the localhost 127.0.0.1 .

So we need to find out a way to fetch the actual IP address so that failover can work.

FYI, all of the machines are Solaris machines.

Regards,

Anjan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2006
Added on Oct 17 2006
3 comments
707 views