[英]Java InetAddress.getAllByName() not returning IPv6 address on Windows even with -Djava.net.preferIPv6Addresses=true
My DNS contains two records for ServerA:我的 DNS 包含 ServerA 的两条记录:
I am not able to get my SimpleClient.java program (source at the end of this post) on a Windows server to list the IPv6 address of ServerA using .netAddress.getAllByName()
, even when configuring the JVM with -Djava.net.preferIPv6Addresses=true
.我无法在 Windows 服务器上获取我的SimpleClient.java程序(本文末尾的源代码)以使用.netAddress.getAllByName()
列出ServerA的 IPv6 地址,即使在使用 -Djava.net 配置 JVM 时-Djava.net.preferIPv6Addresses=true
。
The same test running on an IPv6 enabled Linux server is successful.在启用 IPv6 的 Linux 服务器上运行的相同测试成功。
Configuration details:配置详情:
The output of ipconfig
on the Windows server shows that IPv6 seems enabled: Windows 服务器上ipconfig
的 output 显示 IPv6 似乎已启用:
> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 10.25.0.214
Subnet Mask . . . . . . . . . . . : X.X.X.X
Default Gateway . . . . . . . . . : X.X.X.X
Ethernet adapter Ethernet 2:
Connection-specific DNS Suffix . : fr.company.com
IPv6 Address. . . . . . . . . . . : fda8:6c3:ce53:a890::3
Link-local IPv6 Address . . . . . : X.X.X.X::X
Default Gateway . . . . . . . . . : X.X.X.X::X
The nslookup
output from the Windows server is the expected one:来自 Windows 服务器的nslookup
output 是预期的:
> nslookup ServerA
Server: dns.fr.company.com
Address: X.X.X.X
Non-authoritative answer:
Name: ServerA.fr.company.com
Addresses: fda8:6c3:ce53:a890::55
10.25.46.130
I am able to successfully run ping -6 ServerA
from the Windows server:我能够从 Windows 服务器成功运行ping -6 ServerA
:
> ping -6 ServerA
Pinging ServerA.fr.company.com [fda8:6c3:ce53:a890::55] with 32 bytes of data:
Reply from fda8:6c3:ce53:a890::55: time<1ms
Reply from fda8:6c3:ce53:a890::55: time<1ms
Below is the expected output running from an IPv6 enabled Linux server:以下是从启用 IPv6 的 Linux 服务器运行的预期 output :
# IPv4 (default)
$ java SimpleClient.java ServerA 12345
preferIPv6Addresses: null
InetAddress.getByName()
ServerA/10.25.46.130
InetAddress.getAllByName()
ServerA/10.25.46.130
ServerA/fda8:6c3:ce53:a890:0:0:0:55
# IPv6
$ java -Djava.net.preferIPv6Addresses=true SimpleClient.java ServerA 12345
preferIPv6Addresses: true
InetAddress.getByName()
ServerA/fda8:6c3:ce53:a890:0:0:0:55
InetAddress.getAllByName()
ServerA/fda8:6c3:ce53:a890:0:0:0:55
ServerA/10.25.46.130
The same test failing on the Windows server:相同的测试在 Windows 服务器上失败:
# IPv4 (default)
> java SimpleClient.java ServerA 12345
preferIPv6Addresses: null
InetAddress.getByName()
ServerA/10.25.46.130
InetAddress.getAllByName()
ServerA/10.25.46.130
# IPv6
> java -Djava.net.preferIPv6Addresses=true SimpleClient.java ServerA 12345
preferIPv6Addresses: true
InetAddress.getByName()
ServerA/10.25.46.130
InetAddress.getAllByName()
ServerA/10.25.46.130
On the Windows server, the call to .netAddress.getAllByName()
is only returning a single IPv4 address and not both an IPv4 and IPv6 address like as expected on the Linux IPv6 enabled server.在 Windows 服务器上,对.netAddress.getAllByName()
的调用仅返回一个 IPv4 地址,而不是像 Linux 启用 IPv6 的服务器上预期的那样同时返回 IPv4 和 IPv6 地址。
I can reproduce the same behavior on a Linux server with IPv6 disabled (grub and kernel settings):我可以在禁用 IPv6 的 Linux 服务器上重现相同的行为(grub 和 kernel 设置):
# IPv4 (default)
$ java SimpleClient.java ServerA 12345
preferIPv6Addresses: null
InetAddress.getByName()
ServerA/10.25.46.130
InetAddress.getAllByName()
ServerA/10.25.46.130
# IPv6
$ java -Djava.net.preferIPv6Addresses=true SimpleClient.java ServerA 12345
preferIPv6Addresses: true
InetAddress.getByName()
ServerA/10.25.46.130
InetAddress.getAllByName()
ServerA/10.25.46.130
From these tests, I conclude that something is wrong somewhere on the IPv6 configuration of the Windows server but I don't know what.从这些测试中,我得出结论,Windows 服务器的 IPv6 配置某处有问题,但我不知道是什么。
Some notes and stuff I tried:我试过的一些笔记和东西:
DisabledComponents
key in the registy for the path Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
我没有在路径Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters
的注册表中找到DisabledComponents
项Below is the code for SampleClient.java :下面是SampleClient.java的代码:
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.IOException;
public class SimpleClient {
public static void main(String[] args) {
if (args.length < 2) return;
String hostname = args[0];
System.out.println("preferIPv6Addresses: " + System.getProperty("java.net.preferIPv6Addresses"));
try {
System.out.println("InetAddress.getByName()");
System.out.println(InetAddress.getByName(hostname));
InetAddress[] addresses = InetAddress.getAllByName(hostname);
System.out.println("InetAddress.getAllByName()");
for (InetAddress address : addresses) {
System.out.println(address);
}
} catch (UnknownHostException ex) {
System.out.println("Server not found: " + ex.getMessage());
}
int port = Integer.parseInt(args[1]);
try (Socket socket = new Socket(hostname, port)) {
InputStream input = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
System.out.println(reader.readLine());
} catch (UnknownHostException ex) {
System.out.println("Server not found: " + ex.getMessage());
} catch (IOException ex) {
System.out.println("I/O error: " + ex.getMessage());
}
}
}
Can somebody hint at something that might be wrong on the Windows server configuration?有人可以暗示 Windows 服务器配置可能有问题吗?
Thank you.谢谢你。
The issue was in the.network configuration of the Windows server.问题出在 Windows 服务器的网络配置中。
The server was provisioned with two.network interfaces to segregate between IPv4 and IPv6, each interface being configured to support a single.network stack.服务器配备了两个网络接口以在 IPv4 和 IPv6 之间进行隔离,每个接口都配置为支持单个网络堆栈。
Keeping a single.network interface and configuring both IPv4 and IPv6 on this interface fixed the issue.保留一个单一的网络接口并在此接口上同时配置IPv4和 IPv6 解决了这个问题。
More details on the SuperUser question: https://superuser.com/questions/1719174/jvm-on-windows-not-returning-any-ipv6-address-in-dns-lookup有关 SuperUser 问题的更多详细信息: https://superuser.com/questions/1719174/jvm-on-windows-not-returning-any-ipv6-address-in-dns-lookup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.