3

HttpServletRequest.getRemoteAddr() in Tomcat returns IPv6 formatted IP address, but I would like to configure it that returns IPv4.

I access the servlet via 'localhost'. If I access it via '127.0.0.1' then returns IPv4 formatted IP address (see this answer).

Environment:

  • Windows 7 x64
  • Tomcat 6.0.35-windows-x64

My LAN connection properties: IPv6 is checked off, but it doesn't work neither if I check it on.

My LAN connection properties

Community
  • 1
  • 1
davorp
  • 4,156
  • 3
  • 26
  • 34

2 Answers2

17

try adding this parameter -Djava.net.preferIPv4Stack=true to your tomcat startup commandline.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
0

when you use localhost/xxx, your browser first have to find the mapped address for the name "localhost".In system host file you will find:

# 127.0.0.1 localhost

# ::1 localhost

both definition disabled by default.

to change browser's default matching rules, you have to enable the definition.

e.g: remove "#" from the first host file line, your brower will know directily "localhost" equals 127.0.0.1

Cheers

Community
  • 1
  • 1
Spech
  • 55
  • 1
  • 6