java.net.preferIPv6Addresses
Java System Property accepts a boolean value (true
or false
)java.net.preferIPv6Addresses
ExplainedIf the operating system that your java application is running on supports IPv6 it will attempt to use IPv6 when connecting to a host that supports IPv6.
Typically this would mean if the host's DNS records include IPv6 addresses, such as in the AAAA
records.
The java.net.preferIPv4Stack
system property is related to the java.net.preferIPv6Addresses
property, it can be used to prefer IPv4 over IPv6 instead of IPv6 over IPv4.
Here are some other networking Java system properties:
http.agent
http.keepAlive
http.maxConnections
https.protocols
java.net.preferIPv4Stack
java.net.useSystemProxies
javax.net.debug
javax.net.ssl.trustStore
jdk.net.hosts.file
jdk.tls.client.protocols
jdk.tls.disabledAlgorithms
networkaddress.cache.negative.ttl
networkaddress.cache.ttl
sun.net.client.defaultConnectTimeout
sun.net.client.defaultReadTimeout
sun.net.inetaddr.ttl
Java has supported the java.net.preferIPv6Addresses
system property since at least version 8, 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
setProperty
may 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"); }