Eran Medan Eran Medan - 1 month ago 8
Java Question

How to get the Node's server IP behind a load balancer in Java

I have a webpage behind a load balancer, and I want to display the user (for troubleshooting purposes) the IP of the actual node that the user is connected to (will be the same for a while due to sticky session)

I'm sure it's a very trivial question, but I want to be sure, what Java API should be used for that? will all APIs return me the request host? or will it be server dependent?

Answer

InetAddress.getLocalHost().getHostName() will give you the name of the server you are on. InetAddress.getLocalHost().getHostAddress() will give the IP Address of the server you are on.

Comments