2
votes

Here are three log exmaples:

127.0.0.1 - - [17/Sep/2010:14:03:07 +0800] "GET /docs/logging.html HTTP/1.1" 200 24040 "http://localhost:8000/docs/manager-howto.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
0:0:0:0:0:0:0:1 - - [26/Oct/2010:09:53:30 +0800] "GET /docs/images/tomcat.gif HTTP/1.1" 200 1934 "http://localhost:8000/docs/" "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
0:0:0:0:0:0:0:1 - - [26/Oct/2010:09:53:30 +0800] "GET /docs/images/asf-logo.gif HTTP/1.1" 200 7279 "http://localhost:8000/docs/" "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"

The first is correct. However, the IP of the second and the third is the IPv6 format, how to avoid this?

1
Why do you want to disable it? It accurately reflects how the connection to the Tomcat server was initiated. If you have some tool that interprets the log, that tool should be either updated to account for IPv6, or you should do some translation to the log before allowing the tool to read it (for example, find all occurrences of 0:0:0:0:0:0:0:1, and replace with its IPv4 equivalent, 127.0.0.1. If any other hosts connect (non-localhost), however, you will not be able to do this translation.mpontillo
I can do some translation? from ipv6 to ipv4?hguser
you essentially have 4 options, in my mind: (1) don't listen on the IPv6 port (tell Java at startup to only use IPv4), (2) instruct your browser (looks like Firefox) to disable IPv6, (3) adjust the way you interpret the logs to account for IPv6, or (4) translate all the IPv6 addresses in the log to their IPv4 equivalents before you interpret the log. The caveat is that (4) only works with simple IPv6 addresses like ::1.mpontillo
but if I disable the ipv6 address in tomcat,so clients who use ipv6 will not be recorded in thelog file,isn't it?hguser
you can't have it both ways. If you want people to be able to connect with IPv6, you'll have to be able to live with the IPv6-format log entries. You'll have to update your tool to understand IPv6 addresses if that is the case.mpontillo

1 Answers

3
votes

I've observed on my Tomcat 6.0.20 that the IPv6 address is shown when I access it as localhost:8080 whereas the IPv4 (i.e. the dot-decimal notation) is shown when I access it using the IP address or the server name.

Any remote user accessing the URL will also show ipv4 notation.

via IP address or domain name:

172.x.x.x - - [26/Oct/2010:11:19:50 +0530] "GET /examples/servlets/servlet/RequestParamExample HTTP/1.1" 200 665

via localhost:

0:0:0:0:0:0:0:1 - - [26/Oct/2010:11:20:54 +0530] "GET /examples/servlets/servlet/HelloWorldExample HTTP/1.1" 200 359

Does it work the same for you?