Reputation: 211
In the Linux, I disable IPv6 support by setting java.net.preferIPv4Stack=true by default, only support IPv4 in application.
However, I want now to reach the external IPv6 IP using InetAddress.isReachable(timeout), but it's failed totally and only works when I set java.net.preferIPv4Stack=false.
Are there any ways to reach IPv6 IP, but still keep java.net.preferIPv4Stack=true?
Thank you
Upvotes: 1
Views: 600
Reputation: 72369
No, that's not possible, since the option you set explicitly disables communication with IPv6 only hosts:
java.net.preferIPv4Stack (default: false)
If IPv6 is available on the operating system the underlying native socket will be, by default, an IPv6 socket which lets applications connect to, and accept connections from, both IPv4 and IPv6 hosts. However, in the case an application would rather use IPv4 only sockets, then this property can be set to true. The implication is that it will not be possible for the application to communicate with IPv6 only hosts.
If you want to make sure that IPv4 addresses are preferred over IPv6 ones, but still have IPv6 available, then you're in luck - that's the default behaviour! (If you want to change that to prefer IPv6 addresses for any reason, you can set java.net.preferIPv6Addresses=true
.)
Upvotes: 2