I believe the other answers given here are incorrect.
Java by default prefers the IPv6 stack (if available), but prefers IPv4 addresses. Pay attention to the subtle difference. This is controlled by the properties of the java.net.preferIPv4Stack and java.net.preferIPv6Addresses , both of which are false by default.
Therefore, InetAddress.getLoopbackAddress() almost always return an IPv4 address. You will need to set the java.net.preferIPv6Addresses system properties to true to force it to return an IPv6 address.
I do not see the OS depending on the result of this method in the JDK sources. I canβt think of an OS where Java will not (with default settings) return an IPv4 address for this method.
peterh
source share