Java and IPv6

(Ogg-Vorbis format, 5Mbytes) (WAV format, 26Mbytes)


The class has two subclasses

These cannot be instantiated directly, but are obtained from the "factory" methods such as

If your network stack is configured to use IPv6, you get an Inet6Address , otherwise you get an Inet4Address .

You can check if you have an IPv6 address by

if (address instanceof Inet6Address) ...
You can check if a socket uses IPv6 by

if (socket.getLocalAddress() instanceof Inet6Address) ...


The IPv4 localhost is The IPv6 localhost is 0:0:0:0:0:0:0:1


There are methods to tell if an IPv6 address is compatable with an IPv4 address, and some properties that can be set to tell the JVM to prefer IPv4 or IPv6. Apart from that, there appears to be little that Java gives you.

Jan Newmarch <>
Last modified: Mon Aug 15 12:14:45 EST 2005
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.