I think this example will show you what you need:
http://www.rgagnon.com/javadetails/java-0390.html.
In Linux, the external IP address will usually be on the network interface "eth0". Localhost is
always 127.0.0.1 (technically, anything with an IP address starting with 127 is a loopback adapter, but so many programs have "127.0.0.1" hardcoded into them that operating system programmers make sure that the "lo" is always 127.0.0.1). The loopback adapter is often used for IPC (inter-process communication).
If you'll look at the
documentation, you'll see that you can "getByName".