Question

for example, i recieved from POST ip and mask:

$ip = 2001:db8::1428:55ab;
$mask = 48;

and i want divide this subnet, i choose for example mask and how many subnets i want, for example $mask = 50, subnets = 2

and my result is (tree in a table), like this:

ip                           mask         status
2001:db8::1428:55ab          48           divided
 - 2001:db8::??????          50           free
 - 2001:db8::??????          50           free

how can i do this? need help!

Was it helpful?

Solution

The $mask is actually the prefix-length. It is the number of bits that is 'fixed'. So a /48 prefix length means that the first 48 bits are fixed and the last (128 - 48 = ) 80 bits are available to be used.

In IPv6 a LAN always gets a /64. This means that with a /48 you get (64 - 48 = 16 bits. 216 = ) 65536 subnets.

IPv6 addresses and prefixes are written in hexadecimal. Each hexadecimal character is 4 bits. In IPv6 each group of numbers between : is 16 bits. Leading zeroes in each group can be omitted. So 2001:0db8:0000:0000:0000:0000:0000:0001 is the same as 2001:db8:0:0:0:0:0:1. The combination :: means that in that spot are only zeroes. So that address can also be written as2001:db8::1.

The information you give is a little confusing. You specify 2001:db8::1428:55ab/48. The problem is that you specify the last 32 bits of the IPv6 address (1428:55ab), while the mast specifies that those bits are not fixed. I will therefore use 2001:db8:1a2b::/48 as example.

Each increase in prefix length splits the previous prefix in two.

2001:db8:1a2b::/48 can be split into:

  • 2001:db8:1a2b::/49
  • 2001:db8:1a2b:8000::/49

2001:db8:1a2b::/49 can be split into:

  • 2001:db8:1a2b::/50
  • 2001:db8:1a2b:4000::/50

2001:db8:1a2b:8000::/49 can be split into:

  • 2001:db8:1a2b:8000::/50
  • 2001:db8:1a2b:c000::/50

Etc.

You could write it as a tree (just showing a few branches, I don't want to fill the page with the full 65536 subnets):

  • 2001:0db8:1a2b:0000::/48
    • 2001:0db8:1a2b:0000::/49
    • 2001:0db8:1a2b:8000::/49
      • 2001:0db8:1a2b:8000::/50
        • 2001:0db8:1a2b:8000::/51
        • 2001:0db8:1a2b:a000::/51
          • 2001:0db8:1a2b:a000::/52
            • 2001:0db8:1a2b:a000::/53
            • 2001:0db8:1a2b:a800::/53
          • 2001:0db8:1a2b:b000::/52
            • 2001:0db8:1a2b:b000::/53
            • 2001:0db8:1a2b:b800::/53
      • 2001:0db8:1a2b:c000:/50
      • etc.

As you can see it's not that easy to read. It's easier if you subnet on multiples of 4 because then it matches the hexadecimal characters:

  • 2001:0db8:1a2b:0000::/48
    • 2001:0db8:1a2b:0000::/52
    • 2001:0db8:1a2b:1000::/52
    • 2001:0db8:1a2b:2000::/52
      • 2001:0db8:1a2b:2000::/56
        • 2001:0db8:1a2b:2000::/60
          • 2001:0db8:1a2b:2000::/64
          • 2001:0db8:1a2b:2001::/64
          • ...
          • 2001:0db8:1a2b:200f::/64
        • 2001:0db8:1a2b:2010::/60
          • 2001:0db8:1a2b:2010::/64
          • 2001:0db8:1a2b:2011::/64
          • ...
          • 2001:0db8:1a2b:201f::/64
        • ...
        • 2001:0db8:1a2b:20f0::/60
    • 2001:0db8:1a2b:3000::/52
      • etc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top