In this case, the getRemoteHost method returns an IP address instead of a host name?

On the server of our private network, we have an HttpServlet with which a PC of the same network is connected.

We need to know the host name of the client that communicates with the server. For this, we call the getRemoteHost of the HttpServletRequest method.

Several times this method returns the client computer name (desired behavior), and another - the method returns the IP address. (same client, same server, same private network)

API says:

java.lang.String getRemoteHost ()

Returns the full name of the client or last proxy that sent the request. If the engine cannot or does not want to resolve the host name (to improve performance), this method returns the form of an IP address with a dotted line. For HTTP servlets the same as the value of the CGI variable REMOTE_HOST

Returns : String containing the full name of the client

I see that for the HTTP servlet, this value matches the CGI variable REMOTE_HOST. What does it mean? Does the server decide to resolve the address or not? Is there any way to force this behavior?

+6
source share
1 answer

In Tomcat, for example, the connector has an “enableLookups” parameter, which is disabled by default for performance reasons. See http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

Other containers may have different ways to do the same.

+3
source

All Articles