With nearly two decades of experience working in the IT industry in various roles as Enterprise technology consultant, Java Architect, project leader, Engineer, Designer and Developer, Mr. Knutson has gained a wide variety of experience in disciplines including JavaEE, Web Services, Mobile Computing and Enterprise Integration Solutions. Over the course of his career, Mr. Knutson has enjoyed long lasting partnerships with many of the most recognizable names in the Health Care, Financial, Banking, Insurance, Manufacturing, Telecommunications, Utilities, Product Distribution, Industrial and Electronics industries employing industry standard full software life cycle methodologies including the Rational Unified Process (RUP), Agile, SCRUM, and Extreme Programming (XP). Mr. Knutson has also undertaken speaking engagements, training seminars, white paper and book publishing engagements world-wide. As an active Blogger and tweeter, Mr. Knutson has also been inducted in the prestigious DZone.com Most Valuable Blogger (MVB) group and can be followed at http://www.dzone.com/page/mvbs and twitter at http://twitter.com/mickknutson. Able to quickly and effectively adapt to any phase of an existing project from Business Modeling to Production Support, Mr. Knutson’s wide array of technical expertise in OOA / OOD / OOP, Java, J2EE, Internet, Oracle, Enterprise Integration and Message Oriented Middleware allow him to seamlessly integrate into your Information Systems project at any phase and provide immediate productivity. Mr. Knutson is exceptional at team building and motivating either at a peer-to-peer level, or in a leadership role with excellent communications skills and the ability to adapt to all environments and cultures with ease. Mick is a DZone MVB and is not an employee of DZone and has posted 18 posts at DZone. You can read more from them at their website. View Full User Profile

Tomcat 5.5 and Tomcat 6 connector option enableLookups not defaulting to true

02.10.2012
| 4011 views |
  • submit to reddit

I have been working on an issue where HttpServletRequest.getHostName() always return the IP address, instead of the host name.

The Tomcat 5.5 and Tomcat 6 documentation states enableLookups is set to true by default.

enableLookups

Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are enabled.

http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

http://tomcat.apache.org/tomcat-6.0-doc/config/http.html

Interestingly enough, when we were on Tomcat 5.5 the reverse look-ups for HttpServletRequest.getHostName() worked fine. This seems to be an issue with the documentation for Tomcat 6. Luckily there is an easy solution.

Searching a little more, this seems to also be the same issue as reported in Tomcat 4:

https://issues.apache.org/bugzilla/show_bug.cgi?id=21621

But in the documentation for tomcat 4, the default is false so the assumption is correct.

Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are disabled.

So the documentation for Tomcat 5+ changed and the functionality did not change.

Solution

To solve this issue, in server.xml I added enableLookups=”true” to the connector like this

<Connector enableLookups="true"
           port="8080"
           protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

Next steps will be to validate this on Tomcat 7.

 

From http://www.baselogic.com/blog/development/java-javaee-j2ee/tomcat-6-connector-option-enablelookups-defaulting-true/

Published at DZone with permission of Mick Knutson, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Jess Holle replied on Fri, 2012/02/10 - 8:21am

The default should be false.  The error was in ever setting the default to true.

The issue with setting this to true is that DNS lookups can become a horrible bottleneck in many environments.  If that's not the case in your environment that's great, but if you're trying to deploy Tomcat and an application thereon to numerous customer environments that you have no control of then the only safe setting is false.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.