java.net.preferIPv6Addresses Java System Property accepts the values true, false, or systemjava.net.preferIPv6Addresses ExplainedWhen dealing with a host which has both IPv4 and IPv6 addresses, and if IPv6 is available on the operating system, the default behavior is to prefer using IPv4 addresses over IPv6 ones. This is to ensure backward compatibility, for example for applications that depend on the representation of an IPv4 address (e.g. 192.168.1.1).
This property can be set to true to change that preference and use IPv6 addresses over IPv4 ones where possible, or system to preserve the order of the addresses as returned by the operating system.
This property is checked only once, at startup.
The java.net.preferIPv4Stack system property is related to the java.net.preferIPv6Addresses property. When set to true, it forces the use of IPv4 only sockets, making it impossible to communicate with IPv6 only hosts.
Here are some other networking Java system properties:
http.agenthttp.keepAlivehttp.maxConnectionshttps.protocolsjava.net.preferIPv4Stackjava.net.useSystemProxiesjavax.net.debugjavax.net.ssl.trustStorejdk.http.maxHeaderSizejdk.net.hosts.filejdk.tls.client.protocolsjdk.tls.server.newSessionTicketCountjdk.crypto.disabledAlgorithmsjdk.tls.disabledAlgorithmsnetworkaddress.cache.negative.ttlnetworkaddress.cache.ttlsun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeoutsun.net.inetaddr.ttlJava has supported the java.net.preferIPv6Addresses system property since at least version 6, support may go back to even older versions of java.
java.net.preferIPv6Addresses on StartupYou can set the java.net.preferIPv6Addresses java system property during startup of the java runtime using the -D command line argument:
java -Djava.net.preferIPv6Addresses=true MyAppMain
You may also be able to specify java.net.preferIPv6Addresses via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Djava.net.preferIPv6Addresses=true
java.net.preferIPv6Addresses at RuntimeYou can set java.net.preferIPv6Addresses at runtime with the following Java code:
System.setProperty("java.net.preferIPv6Addresses", "true");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the java.net.preferIPv6Addresses system property may be cached within an internal private static variable of the implementing class.
To read the value of java.net.preferIPv6Addresses at runtime, you can use this Java code:
String propertyValue = System.getProperty("java.net.preferIPv6Addresses");
if (propertyValue != null) {
System.out.println("java.net.preferIPv6Addresses = " + propertyValue);
} else {
System.out.println("java.net.preferIPv6Addresses was null");
}