I am designing a servlet in which I would like to determine the fully qualified domain name (FQDN) of the client. I am attempting to use javax.servlet.HttpServletRequest.getRemoteHost() in order to get the hostname. When running the application on Apache Tomcat as a standalone server, request.getRemoteHost() works as I would hope, returning the FQDN of the client. However, when running the application with the Apache Httpd server as a frontend and mod_jk as the connector, request.getRemoteHost() always returns the ip address of the client instead of the FQDN.

I have tried the following two configuration options in an attempt to solve this problem.

  1. In Apache Tomcat's server.xml I have set enableLookups="true"
  2. In Apache Httpd's httpd.conf, I have set HostnameLookups On

Still request.getRemoteHost() returns the client's ip address instead of it's FQDN.

Is there a configuration option that will allow my servlet's request.getRemoteHost() method return the client's FQDN when running Apache Tomcat with Apache Httpd, as it does when it is running with just Apache Tomcat?

My environment is RHEL 7.5 with Apache Httpd server 2.4.6 and Apache Tomcat 8.5

  • one IP can have many many FQDNs associated with it. What are you trying to accomplish? You may be better off checking PTR records for the IP retrieved (reverse DNS records) – ivanivan Dec 3 '18 at 19:06
  • I'm trying to get ANY hostname. You are correct, I would be better off with reverse dns, but this is a third party application and I cannot modify the source code. I'm just trying to make the existing code work (if it is possible). – Bill T Dec 3 '18 at 20:53
  • Check this forum post out - particularly the part about the RFC that defines the HTTP connection stuff... coderanch.com/t/81745/application-servers/… – ivanivan Dec 3 '18 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.