Enabling IPv6 on Java and Maven

November 29, 2021

With IPv6 adoption being increased due to IPv4 scarcity and more providers like AWS and Hetzner moving on to IPv6 only networks, it is important to know that your app supports and uses the IPv6.

Java as it turns out comes out of the box with IPv6 disabled. Here are some steps that you can follow to enable IPv6 on you java app.


Maven which is heavily used to build java projects needs a few steps to enable IPv6. The default maven repo does not support IPv6 yet. However you can use IPv6 enabled repo ipv6.repo1.maven.org instead.

Open ~.m2/settings.xml and add the following to change the default central repo.

      <name>IPv6 Mirror Repository</name>

and when running mvn command append the following to use IPv6.



For Java Applications you can enable IPv6 by adding -Djava.net.preferIPv6Addresses=true when running for a command line as with maven.

Or add the preferIPv6Addresses on the system property in the app itself.

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

This will make the application use IPv6 when available.