Q:

How can I get the actual IP in a linux machine from Java

I am trying to get the local IP address from a Linux machine BUT NOT get the loopback.
To do that I am using the following code (I am not sure if what I am doing is correct):  
NetworkInterface ni = NetworkInterface.getByName("eth0");    
Enumeration<InetAddress> inetAddresses =  ni.getInetAddresses();
while(inetAddresses.hasMoreElements()) {  
         InetAddress ia = inetAddresses.nextElement();  
         if(!ia.isLinkLocalAddress()) {  
              //this is not loopback  
         }    
}  

When I run this I get 2 IPs (I was interested only in one of these) which when I do an ifconfig I see one (the one I want to get) is 
in the entry for eth0 while the other is in the entry for eth0:54.
I don't even know what is eth0:54.  
How can I get the IP I want?

A:

Linux machines can have more than one IP address including loopback.  There is no concept of uniqueness for IP addresses.
What you might be looking for is the hostname (and its IP address)  You can get this by reading /etc/hostname and looking up its IP address. Note: its possible it doesn't have an IP address if the machine is not setup in a normal manner.

A:

Any modern computer have multiple IP-numbers, 127.0.0.1 being one of them.  The actual configuration does not always get correctly reported up to the Java layer (in my experience).
You may simply want to execute /sbin/ifconfig -a on a scheduled basis (or at startup time) and log the complete output.

