如何在JRE上禁用IPv4 IP堆栈的IPv6堆栈?

时间:2023-01-19 17:18:35

As you can see on below screenshots, eclipse and Android SDK Manager (and other Java programs) are trying to connect to a IPv4 Internet IP via IPv6 TCP/IP stack while Proxifier (a proxy manager program, nevermind) can not support that.

正如您在下面的屏幕截图中看到的那样,eclipse和Android SDK Manager(以及其他Java程序)正在尝试通过IPv6 TCP / IP堆栈连接到IPv4 Internet IP,而Proxifier(代理管理器程序,无所谓)不能支持它。

如何在JRE上禁用IPv4 IP堆栈的IPv6堆栈?如何在JRE上禁用IPv4 IP堆栈的IPv6堆栈?

How I can disable IPv6 in Java?

如何在Java中禁用IPv6?

3 个解决方案

#1


78  

I wanted to use this for some program I hadn't control for running that Java app so ended with this _JAVA_OPTIONS=-Djava.net.preferIPv4Stack=true environment variable. (read about _JAVA_OPTIONS here)

我想将这个用于我无法控制运行该Java应用程序的程序,因此以_JAVA_OPTIONS = -Djava.net.preferIPv4Stack = true环境变量结束。 (在这里阅读_JAVA_OPTIONS)

If you are using Windows, just run this command on Windows cmd:
setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

如果您使用的是Windows,只需在Windows cmd上运行此命令:setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack = true

Thanks to Jason Nichols for reminding this JVM argument :)

感谢Jason Nichols提醒这个JVM参数:)

#2


34  

Did you try (from the command line)

你试过(从命令行)

-Djava.net.preferIPv4Stack=true

or (from your code)

或(来自您的代码)

System.setProperty("java.net.preferIPv4Stack" , "true");

#3


2  

Maybe a bit late but for me neither solution worked. So I included this option as it is stated here:

也许有点晚了,但对我来说,这两种解决方所以我在这里说明了这个选项:

-Djava.net.preferIPv4Addresses=true

But also the followingI added line to the end of the file /etc/sysctl.conf

但是下面我还在文件/etc/sysctl.conf的末尾添加了一行

net.ipv6.conf.all.disable_ipv6 = 1

And

sudo sysctl -p

as it is explained here. In order to check that ipv6 is disabled just execute:

正如这里解释的那样。为了检查ipv6是否被禁用,只需执行:

ip a | grep inet

#1


78  

I wanted to use this for some program I hadn't control for running that Java app so ended with this _JAVA_OPTIONS=-Djava.net.preferIPv4Stack=true environment variable. (read about _JAVA_OPTIONS here)

我想将这个用于我无法控制运行该Java应用程序的程序,因此以_JAVA_OPTIONS = -Djava.net.preferIPv4Stack = true环境变量结束。 (在这里阅读_JAVA_OPTIONS)

If you are using Windows, just run this command on Windows cmd:
setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

如果您使用的是Windows,只需在Windows cmd上运行此命令:setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack = true

Thanks to Jason Nichols for reminding this JVM argument :)

感谢Jason Nichols提醒这个JVM参数:)

#2


34  

Did you try (from the command line)

你试过(从命令行)

-Djava.net.preferIPv4Stack=true

or (from your code)

或(来自您的代码)

System.setProperty("java.net.preferIPv4Stack" , "true");

#3


2  

Maybe a bit late but for me neither solution worked. So I included this option as it is stated here:

也许有点晚了,但对我来说,这两种解决方所以我在这里说明了这个选项:

-Djava.net.preferIPv4Addresses=true

But also the followingI added line to the end of the file /etc/sysctl.conf

但是下面我还在文件/etc/sysctl.conf的末尾添加了一行

net.ipv6.conf.all.disable_ipv6 = 1

And

sudo sysctl -p

as it is explained here. In order to check that ipv6 is disabled just execute:

正如这里解释的那样。为了检查ipv6是否被禁用,只需执行:

ip a | grep inet