Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a java api that will identify the ipv6 address fd00:: as local/private?

Tags:

java

ipv6

ipv4

I'm looking for a java api that will correctly identify if a given ip address is private or local. This code seems to work for most ipv4/ipv6 addresses:

    boolean isLocalIp = InetAddress.getByName(ipAddr).isSiteLocalAddress() ||
                        InetAddress.getByName(ipAddr).isLinkLocalAddress() ||
                        InetAddress.getByName(ipAddr).isLoopbackAddress() ;

Particularly, it identifies "fec0::" as a local/private type address but it does not identify, for example, "fc00::" or "fd00::" as local/private type addresses.

Looking at this wikipedia link https://en.wikipedia.org/wiki/Private_network#IPv6:

The address block fc00::/7 is reserved by IANA for Unique Local Addresses (ULA).[2] They are unicast addresses, but contain a 40-bit random number in the routing prefix to prevent collisions when two private networks are interconnected. Despite being inherently local in usage, the IPv6 address scope of unique local addresses is global.

The first block defined is fd00::/8, designed for /48 routing blocks, in which users can create multiple subnets, as needed.

Can anyone help with explaining if there is some false assumption here (e.g. that "fc00::" or "fd00::" should be identified as a local/private ipv6 address) or if there is some other java api that will correctly identify all local/private ip addresses?

Thanks for any feedback/answers!

like image 252
CraigF Avatar asked Dec 13 '18 14:12

CraigF


People also ask

Are there private IPv6 addresses?

Unique Local Unicast Addresses (ULAs) are the currently preferred version of private addressing for IPv6. IPv6 has had two versions of private addressing – deprecated site-local addressing and the current Unique Local Unicast Addresses (ULAs).

What does a :: represent in an IPv6 address?

Double colon. Specify IPv6 addresses by using double colons ( :: ) in place of a series of zeros. For example, IPv6 address ff06:0:0:0:0:0:0:c3 can be written as ff06::c3 . Double colons can be used only once in an IP address.

What type of IPv6 address is the equivalent of a private IPv4 address?

Unique Local Addresses. Figure 4-6 shows another type of IPv6 unicast address, the unique local address (ULA), which is the counterpart of IPv4 private addresses. Unique local addresses are also known as private IPv6 addresses or local IPv6 addresses (not to be confused with link-local addresses).

How do I find my local IPv6 link address?

IPv6 Link Local addresses are identified among IPv6 addresses by reserving the left most 64 bits as 1111111010000000 0000000000000000 0000000000000000 0000000000000000 (translates to FE80 in hexadecimals). IPv6 Link Local addresses are used by devices for communicating with other nodes on the same link.


1 Answers

Can anyone help with explaining if there is some false assumption here (e.g. that "fc00::" or "fd00::" should be identified as a local/private ipv6 address)

Addresses in those blocks are not meant to be routed outside a single administrative domain, but the term "site-local address" means something much more specific. That now-deprecated term refers specifically to the block fec0::/10.

Addresses in the block fc00::/7 are "unique local addresses" that are not guaranteed to be globally unique, but they are not link-local because they are permitted to be routed between different broadcast domains.

or if there is some other java api that will correctly identify all local/private ip addresses?

I looked briefly at InetAddress.isAnyLocalAddress(), but its docs do not seem to match what you're trying to do. It doesn't look like the standard library has such a method available.

like image 193
John Bollinger Avatar answered Oct 08 '22 15:10

John Bollinger