How to force Java to use IPv4 instead IPv6?

39

5

My Java browser plug-in is no longer working. When I open a page that has a Java element, Java cannot connect to the server.

After investigation, I found that Java was trying to use IPv6, while my network does not support IPv6, so Java always fails to connect.

I tried looking on Google and found that I should run Java with -Djava.net.preferIPv4Stack=true, but how can I pass this to the browser?

I use Google Chrome and Java 7 update 5.

nyongrand

Posted 2012-07-25T08:37:50.720

Reputation: 568

@harrymc always copy content: that link is dead. – javadba – 2017-01-16T03:12:38.357

@javadba: Links are never dead : see the Wayback Machine, but it's outdated. Better google "Disable IPv6 On Windows" for half a million results.

– harrymc – 2017-01-16T07:31:53.880

Why don't you disable the IPv6 protocol so Java won't have this option. – harrymc – 2013-08-30T18:55:04.073

it is a old story, I do not know if I've disable IPv6 protocol, seems to have, I've forgotten, what I remember is I remove Java 7 and replace it with Java 6 – nyongrand – 2013-08-31T09:21:07.907

1

Disabling is easy : see this.

– harrymc – 2013-08-31T09:25:18.063

Answers

69

Put the options in _JAVA_OPTIONS environment variable. How to do this is already described in various other posts – although they usually talk about setting PATH, but it's all the same.

For example, on Linux, put the following in your ~/.profile or ~/.bash_profile:

export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"

user1686

Posted 2012-07-25T08:37:50.720

Reputation: 283 655

1Why does Java 'prefer' IPV6? It seems to break code that was working. – Ribo – 2016-04-02T15:18:17.650

How to set it in Windows ? – Adnan Ali – 2017-06-18T09:51:53.587

1@Ribo: By default, Java uses dual-stack IPv6 when possible, that is, it uses IPv6 sockets that also support IPv4 addresses. These sockets are still compatible with IPv4 applications by using IPv4-mapped addresses. Therefore, this is a backward-compatible behavior. – Dr. Koutheir Attouchi – 2017-08-24T08:38:05.533

IPv4-mapped addresses break proxies. – MarcH – 2018-12-05T00:44:54.293

1ok, thanks for your reply, although i use windows but your solution inspire me, thanks – nyongrand – 2012-07-25T19:28:04.780

1

See for example this post for setting environment variables: http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

– user2428118 – 2013-08-30T18:12:58.950