Как найти префикс ipv6

IPv4 addresses have a subnet mask but instead of typing something like 255.255.255.0 we use a prefix length for IPv6. Here is an example of an IPv6 prefix:

2001:1111:2222:3333::/64

This is pretty much the same as using 192.168.1.1 /24. The number behind the / are the number of bits that we use for the prefix. In the example above it means that 2001:1111:2222:3333 is the prefix (64 bits) and everything behind it can be used for hosts.

When calculating subnets for IPv4 we can use the subnet mask to determine the network address and for IPv6 we can do something alike. For any given IPv6 address we can calculate what the prefix is but it works a bit different.

Let me show you what I’m talking about, here’s an IPv6 address that could be assigned to a host:

2001:1234:5678:1234:5678:ABCD:EF12:1234/64

What part from this IPv6 address is the prefix and what part identifies the host?

IPv6 prefix host blue green

Since we use a /64 it means that the first 64 bits are the prefix. Each hexadecimal character represents 4 binary bits so that means that this part is the prefix:

2001:1234:5678:1234

This part has 16 hexadecimal characters. 16 x 4 means 64 bits. So that’s the prefix right there. The rest of the IPv6 address identifies the host:

5678:ABCD:EF12:1234

So we figured out that “2001:1234:5678:1234” is the prefix part but writing it down like this is not correct. To write down the prefix correctly we need to add zeros at the end of this prefix so that it is a 128 bit address again and add the prefix length:

IPv6 prefix host blue green arrows

2001:1234:5678:1234:0000:0000:0000:0000/64 is a valid prefix but we can shorten it. This string of zeros can be removed and replace by a single ::

2001:1234:5678:1234::/64

That’s the shortest way to write down the prefix. Let’s look at another example:

3211::1234:ABCD:5678:1010:CAFE/64

Before we can see what the prefix is, we should write down the complete address as this one has been shortened (see the :: ). Just add the zeros until we have a full 128 bit address again:

3211:0000:0000:1234:ABCD:5678:1010:CAFE/64

We still have a prefix length of 64 bits. A single hexadecimal character represents 4 binary bits, so the first 16 hexadecimal characters are the prefix:

3211:0000:0000:1234

Now we can add zeros at the end to make it a 128 bit address again and add the prefix length:

3211:0000:0000:1234::/64

That’s a good looking prefix but we can make it a little shorter:

3211:0:0:1234::/64

4 zeroes in a row can be replaced by a single one, so “3211:0:0:1234::/64” is the shortest we can make this prefix.

Depending on the prefix length it makes the calculations very easy or (very) difficult. In the examples I just showed you both prefixes had a length of 64. What if I had a prefix length of /53 or something?

Each hexadecimal character represents 4 binary bits. When your prefix length is a multiple of 16 then it’s easy to calculate because 16 binary bits represent 4 hexadecimal characters.

Here’s an illustration:

IPv6 hexadecimal to binary

So with a prefix length of 64 we have 4 “blocks” with 4 hexadecimal characters each which makes it easy to calculate. When the prefix length is a multiple of 4 then it’s still not too bad because the boundary will be a single hexadecimal character.

When the prefix length is not a multiple of 16 or 4 it means we have to do some binary calculations. Let me give you an example!

2001:1234:abcd:5678:9877:3322:5541:aabb/53

This is our IPv6 address and I would like to know the prefix for this address. Where do I start?

First I have to determine in what “block” my 53rd bit is located:

IPv6 address 53rd bit

Somewhere in the blue block we will find the 53rd bit. To know what the prefix is we will have to calculate those hexadecimal characters to binary:

IPv6 hexadecimal to binary 53th bit

We now have the block that contains the 53rd, this is where the boundary is between “prefix” and “host”:

Introduction

We are in the transition phase from IPv4 to IPv6 addressing structure, and I believe that the network engineers should easily plan their IPv6 addressing /subnetting infrastructure without any error. In this article, I tried to explain how IPv6 subnetting works by giving examples.

I also wrote and distributed a free IPv6 Subnetting Tool / Calculator both with C# and Java JDK 17 application frameworks. It lets you plan/subnet your assigned address for all 128bits. You can find the applications in the second part of this article.

I distributed the applications in the hope that it will be useful for your subnet calculations. I will try to develop the software continuously, so please don’t hesitate to comment/inform for any bugs or new feature suggestions.

1. How Does ‘/’ (slash or prefix-length notation) Work with IPv6?

The ‘/’ indicates the number of bits which are fixed for your subnetwork. Fixed means that you do not have any control on these bits, you must not change them (I like to call them “don’t touch only watch bits“). IPv6 is 128 bits long and your network/organization is assigned “128 minus /prefix-lengthValue” and these are the bits given under your control. You can do your subnetting with these bits and assign addresses to your computer/car/mobile/etc.

For example, assume that the prefix ‘2001:db8:1234::/48’ is assigned to your network by your service provider (or by RIPE, ARIN, etc). In this case, /48 indicates that starting from the left-most bit up to and including the 48th bit, these bits are fixed and must not be changed (don’t touch only watch). And the rest of the bits which have the length of 128-48=80bits are given to your control, i.e., for addressing and subnetting.

So, the importance of ‘/’ prefix-length is that it indicates the boundary of your network. In other words, from which number your assigned network starts and at which number it ends.

2. Finding IPv6 Start and End Addresses of our Subnet

If we have for example 192.168.3.0/24 subnet prefix, then 24 bits are fixed. You must not change these bits. And our netmask will be 255.255.255.0, we can do subnetting by using 32-24=8bits by taking care of subnet and broadcast addresses, as we all know very well with our IPv4 experience.

2.1 Three Useful Bitwise Operators: & , | , ~

& (AND), | (OR), ~ (NOT or bit INVERTER): We will use these three bitwise operators in our calculations. I think everybody is familiar -at least from university digital logic courses- and knows how they operate. I will not explain the details here again. You can search for ‘bitwise operators’ for further information.

Now with our IPv6 subnet-prefix assigned, how can we find our subnets and starting and end addresses of it? We can easily calculate them with the help of these three logic operators as follows. I will try to demonstrate on both IPv4 and IPv6.

With IPv4

What is our mask if we have ‘/24’? Remember CIDR notation, it is simply 255.255.255.0 which is 24 bits all ‘set‘ or ‘all one‘ starting from the left-most bit up to and including 24th bit.

Finding Start Address is to ‘AND‘ the address with your mask which is:

(192.168.3.5) & (255.255.255.0) = 192.168.3.0 

This is our Starting Address, or as we call Network address.

Finding End Address is to ‘OR‘ the address with your inverted (NOT) mask which is:

(192.168.3.5) | ~(255.255.255.0) = 192.168.3.255 

This is our End Address, or as we call Broadcast address.

With IPv6

What is our mask if we have ‘/48’? Simply it is ffff:ffff:ffff:: for which all 48 bits are ‘set‘ or ‘all one‘ starting from the left-most bits up to and including 48th bit. As you can see, the evaluation way of the mask is exactly the same as in IPv4. As for our IPv6 subnet prefix ‘2001:db8:1234::/48’, again the same calculation method applies. It is also useful to remember that we always use ‘hexadecimal’ instead of decimal numbers for addressing since IPv6 is completely based on hexadecimal numbers. So,

Finding Start Address is to ‘AND‘ the address with your mask which is:

(2001:db8:1234::) & (ffff:ffff:ffff::) = 2001:db8:1234::

Finding End Address is to ‘OR‘ the address with your inverted (NOT) mask which is:

(2001:db8:1234::) | ~(ffff:ffff:ffff::) = 2001:db8:1234:ffff:ffff:ffff:ffff:ffff

As a result, for the subnet-prefix ‘2001:db8:1234::/48’ we have the range or interval of our subnet:

IPv6 subnet Start Address> 2001:db8:1234:0:0:0:0:0 (or compressing zeros 2001:db8:1234::) 
IPv6 subnet   End Address> 2001:db8:1234:ffff:ffff:ffff:ffff:ffff

Also remember that we don’t have broadcast mechanism in IPv6, so we don’t have broadcast address.

3. How to Subnet with IPv6 Subnet-prefix?

As we know, our first prefix-length indicates the fixed bits and we can borrow bits starting from (but excluding) prefix-length value towards the right-most bit (from left to right).

Example

Let’s use the subnet-prefix ‘2001:db8:1234::/48‘, and borrow 2 bits for subnetting.

The beauty of number conversion shows itself when we do hexadecimal to binary conversion. When converting from hex-to-binary or vice versa, you can simply and directly convert each hex-digit into binary form without caring about the digit weights. In hexadecimal notation, each hex-digit corresponds to 4 bits, usually called as ‘nibble‘. Our example address in expanded form and with nibbles are:

  2    0    0    1  :   0    d    b    8  :   1    2    3    4  :  0    0   ...(the rest zeros)

0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 0000 0000 ...(the rest zeros)

Let’s borrow 2 bits which are 49th and 50th bits:

0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 0000 … (all the rest zeros)

By borrowing 2 bits, we can have 22= 4 unique subnets, which are:

0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 0000 ...(the rest zeros)
0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 0100 ...(the rest zeros) 
0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 1000 ...(the rest zeros) 
0010 0000 0000 0001 : 0000 1101 1011 1000 : 0001 0010 0011 0100 : 1100 ...(the rest zeros) 

Let’s convert these numbers back into hexadecimal and see the result:

2001:db8:1234:0000::/50 (First subnet)    
2001:db8:1234:4000::/50 (Second subnet)   
2001:db8:1234:8000::/50 (Third subnet)    
2001:db8:1234:c000::/50 (Fourth subnet)   

If you are a service provider, you can assign these subnet-prefixes to your customers one by one with ‘/50’ prefix-length, e.g., 2001:db8:1234:0000::/50 for one customer, and 2001:db8:1234:4000::/50 for other, etc.

And now your customers should know the End of their assigned address space. At this point, remember finding Start and End addresses of our subnet and perform the calculations.

First of all, your customers will have mask of ‘/50’ which is all 50 bits ‘set’ or all 50 bits are ‘ones’ giving us the mask of ‘ffff:ffff:ffff:c000::‘. Now using this mask, we can easily calculate the start-end addresses, i.e., the range or interval of our subnet. Let’s do it one by one.

1st. Customer subnet Start address= 
(2001:db8:1234:0000::) & (ffff:ffff:ffff:c000::) = 2001:db8:1234:0000:0:0:0:0 = 2001:db8:1234::
1st. Customer subnet End address= 
(2001:db8:1234:0000::) |~(ffff:ffff:ffff:c000::) = 2001:db8:1234:3fff:ffff:ffff:ffff:ffff

2nd. Customer subnet Start address= 
(2001:db8:1234:4000::) & (ffff:ffff:ffff:c000::) = 
                  2001:db8:1234:4000:0:0:0:0 = 2001:db8:1234:4000::
2nd. Customer subnet End address= 
(2001:db8:1234:4000::) |~(ffff:ffff:ffff:c000::) = 2001:db8:1234:7fff:ffff:ffff:ffff:ffff

3rd. Customer subnet Start address= 
(2001:db8:1234:8000::) & (ffff:ffff:ffff:c000::) = 
                  2001:db8:1234:8000:0:0:0:0 = 2001:db8:1234:8000::
3rd. Customer subnet End address= 
(2001:db8:1234:8000::) |~(ffff:ffff:ffff:c000::) = 2001:db8:1234:bfff:ffff:ffff:ffff:ffff

4th. Customer subnet Start address= 
(2001:db8:1234:c000::) & (ffff:ffff:ffff:c000::) = 
                  2001:db8:1234:c000:0:0:0:0= 2001:db8:1234:c000::
4th. Customer subnet End address= 
(2001:db8:1234:c000::) |~(ffff:ffff:ffff:c000::) = 2001:db8:1234:ffff:ffff:ffff:ffff:ffff

Notice that each of the subnet-prefixes can also be used again to perform subnetting. For example, the 4th customer may use the subnet-prefix ‘2001:db8:1234:d000::/50’ to do subnetting by borrowing bits again say from /50 to /54, according to their needs of course.

4. Idea of Parent (or root) prefix

When you apply to your service provider (or RIPE, ARIN, APNIC, LACNIC, etc.) for an IPv6 prefix range, they will assign a prefix for you with ‘/xy’ prefix-length. For example, assume that ‘2001:db8:1234::/48’ was assigned for your network infrastructure. In this case, ‘2001:db8:1234::/48’ will be your parent (or root) prefix since all your sub-assignments must be created under your parent prefix. It is similar to the parent (root) node of a tree data structure – similarly used in our internet DNS system.

In addition, when you create new subnet prefixes, each of them may also be called as ‘parent (or root)’. We may say that it’s similar to ‘network address’ of a subnet that we use in IPv4. But keep in mind that we don’t have network or broadcast address mechanism in IPv6.

Let’s give an example: Assume that you have the prefix ‘2001:db8:1234:4000::/50’ and created 4 new sub-prefixes by borrowing 2 bits (similar to subnetting example above), which are:

p0> 2001:db8:1234:4000::/52
p1> 2001:db8:1234:5000::/52
p2> 2001:db8:1234:6000::/52
p3> 2001:db8:1234:7000::/52

Here we can say that ‘2001:db8:1234:4000::/50’ is the parent of the four prefixes above.

 (Parent or root prefix)
2001:db8:1234:4000::/50     (Child prefixes)
                      __ 2001:db8:1234:4000::/52
                       |_ 2001:db8:1234:5000::/52
                       |_ 2001:db8:1234:6000::/52
                       |_ 2001:db8:1234:7000::/52

Notice that each child prefix may also be a parent prefix. When you use the application, the prefix (first trackbar) value will define the parent prefix. If you use database with the application, parent prefixes are automatically inserted into the database as equal prefix and parent prefix values.

Summary

In order to find the starting and end address of your subnet, you only need to know IPv6 address and prefix-length value. Remember these bitwise operations (which are also valid for IPv4):

(IPv6 Address) &  (/prefix-length mask) is equal to (IPv6 subnet Start address)
(IPv6 Address) | ~(/prefix-length mask) is equal to (IPv6 subnet End address)

(Follow the link for the second part of this article: Subnetting with IPv6 Part 2/2[^] )

History

  • 28th September, 2013: v1.0
  • 26th January, 2014, v1.1: A few typing corrections
  • 13th November, 2017, v2.0: Java application is based on JavaFX
  • 23rd October, 2019: C# v4.0 (based on .NET 4.7.2) and JavaFX v3.3
  • 6th January, 2020: C# v4.1 (based on .NET 4.8 and with IPv4 mode available)
  • 9th June, 2022: C# v5.0 and Java v4.0 based on Java JDK 17 (JavaFX will not be used)

This article, along with any associated source code and files, is licensed under The BSD License

Время на прочтение
4 мин

Количество просмотров 6.1K

Введение

Данная статья является переводом конкретного раздела, описывающего базовые операции над IPv6-адресами из учебника CCNA 200-301 Volume 1 от автора Wendell Odom.

Сокращение IPv6 адресов

Базовые правила:

  • Два двоеточия подряд – это 2 или более гекстета адреса с нулями.

  • Их “::” можно использовать всего один раз на весь IPv6-адрес.

    Можно так 3124::DEAD:CAFE:0:0:0 или так 3124:0:0:DEAD:CAFE::, но нельзя вот так 3124::DEAD:CAFE::

    Например: 210F::CCCC:0:0:D – считаем, у нас 210F – первый гекстет, далее двойное двоеточие, далее идут CCCC:0:0:D – это еще 4 гекстета, итого 5 гекстетов. Так всего в IPv6-адресе 8 гекстетов, то 8-5=3 гекстета недостающих, заполняем их нулями и получаем 210F:0000:0000:0000:CCCC:0000:0000:000D

  • Если перед буквами (hex) или цифрами, кроме нуля в гекстете идут нули, то их можно отсекать.

  • Если нули идут после букв (hex) или цифр – их оставляем , иначе после обратного процесса мы получим другой адрес.
    Например: ABCD:0020 – в сокращенном виде выглядит как ABCD:20, а ABCD:2000не сокращается.

Разберем несколько примеров:

Дано

С сокращением

2340:0000:0010:0100:1000:ABCD:0101:1010

2340:0:10:100:1000:ABCD:101:1010

30A0:ABCD:EF12:3456:0ABC:B0B0:9999:9009

30A0:ABCD:EF12:3456:ABC:B0B0:9999:9009

2222:3333:4444:5555:0000:0000:6060:0707

2222:3333:4444:5555:0:0:6060:707

3210:0000:0000:0000:0000:0000:0000:0000

3210::

210F:0000:0000:0000:CCCC:0000:0000:000D

210F::CCCC:0:0:D

34BA:000B:000B:0000:0000:0000:0000:0020

34BA:B:B::20

FE80:0000:0000:0000:DEAD:BEFF:FEEF:CAFE

FE80::DEAD:BEFF:FEED:CAFE

FE80:0000:0000:0000:FACE:BAFF:FEBE:CAFE

FE80::FACE:BAFF:FEBE:CAFE

Нахождение части подсетей IPv6-адреса

Допустим, на ПК клиента установлен такой адрес: 2000:1234:5678:9ABC:1234:5678:9ABC:1111/64. Так как максимальный префикс для IPv6 =128, то 64 – есть половина – то есть 4 гекстета из 8, таким образом, 2000:1234:5678:9ABC – часть подсети, а 1234:5678:9ABC:1111 – часть хостов.

Для написания номера подсети приводим часть хостов к нулю и получаем такое: 2000:1234:5678:9ABC:0000:0000:0000:0000/64, а в сокращенном виде: 2000:1234:5678:9ABC::/64

Разберем несколько примеров:

Дано

Подсеть

С сокращением

2340:0:10:100:1000:ABCD:101:1010/64

2340:0:10:100:0000:0000:0000:0000/64

2340:0:10:100::/64

30A0:ABCD:EF12:3456:ABC:B0B0:9999:9009/64

30A0:ABCD:EF12:3456:0000:0000:0000:0000/64

30A0:ABCD:EF12:3456::/64

2222:3333:4444:5555::6060:707/64

2222:3333:4444:5555:0000:0000:0000:0000/64

2222:3333:4444:5555::/64

3210::ABCD:101:1010/64

3210:0000:0000:0000:0000/64

3210:0:0:0:0/64

А теперь разберем несколько более сложных примеров:

Дано: 2000:1234:5678:9ABC:1234:5678:9ABC:1111/56
Каждый гекстет есть 16 бит, так как всего 8 гекстетов и 128 бит, таким образом 16*8 = 128, значит половина гекстета = 8 бит.
В данном случае, нам нужно отсчитать 3 целых гекстет и половину 4-го, получаем 3*16+8=56 бит.

Итого получаем такую часть подсети: 2000:1234:5678:9A00:0000:0000:0000:0000/56
или в сокращенном виде: 2000:1234:5678:9A00::/56

Тут можно легко допустить ошибку, посчитав, что, так как у нас префикс=56 бит, то после 9A мы должны были отсечь 2 символа, но это не так. Они остаются: 9A00, потому что, если отсечь два нуля в конце в дальнейшем может превратится в 009А, что является уже другим адресом.

Разберем несколько примеров с различными префиксами:

Дано

С сокращением

34BA:B:B:0:5555:0:6060:707/80

34BA:B:B:0:5555::/80

3124::DEAD:CAFE:FF:FE00:1/80

3124:0:0:DEAD:CAFE::/80

2BCD::FACE:BEFF:FEBE:CAFE/48

2BCD:0000:0000::/48

3FED:F:E0:D00:FACE:BAFF:FE00:0/48

3FED:F:E0::/48

210F:A:B:C:CCCC:B0B0:9999:9009/40

210F:A:0::/40

34BA:B:B:0:5555:0:6060:707/36

34BA:B:0::/36

3124::DEAD:CAFE:FF:FE00:1/60

3124:0:0:DEA0::/60

2BCD::FACE:1:BEFF:FEBE:CAFE/56

2BCD:0000:0000:FA00::/56

Учимся понимать как работает механизм по автоматической выдаче IPv6-адресов на основе MAC-адресов хостов

Дано: 2001:DB8:1:1::/64
MAC: B8:0C:BE:EF:CA:FE, в дальнейшем буду разделять точкой на 3 октета: B80C.BEEF.CAFE

Первым делом необходимо разделить MAC-адрес пополам
и добавить посередине значение: FFFE, по итогу получаем такую запись: B80C:BEFF:FEEF:CAFE

Далее, берем первые 2 символа получившейся записи – это B8, очевидно, что это в шестнадцатеричном (HEX) формате.

Необходимо перевести B8 в двоичный вид, получаем: 1011 1000, но это еще не все. Из двоичной записи берем 7-й бит и инвертируем его (1 в 0 или 0 в 1) и получаем такую запись: 1011 1010, а теперь обратно переводим в HEX-формат, получаем BA (B=1011, A=1010). Наконец-то подставляем вместо B8 наш результат BA и получаем: BA0C:BEFF:FEEF:CAFE, а эту запись добавляем в конец адреса из Дано и получаем результат: 2001:DB8:1:1:BA0C:BEFF:FEEF:CAFE

Разберем несколько примеров:

Префикс

MAC-адрес

Результат

Мои расчеты

2001:DB8:1:1::/64

0013.ABAB.1001

2001:DB8:1:1:0213:ABFF:FEAB:1001

2001:DB8:1:1::/64

AA13.ABAB.1001

2001:DB8:1:1:A813:ABFF:FEAB:1001

AA=1010 1010=1010 1000, 1010=A, 1000=8

2001:DB8:1:1::/64

000С.BEEF.CAFE

2001:DB8:1:1:020C:BEFF:FEEF:CAFE

2001:DB8:1:1::/64

B80C.BEEF.CAFE

2001:DB8:1:1:BA0C:BEFF:FEEF:CAFE

B8=1011 1000=1011 1010, BA

2001:DB8:FE:FE::/64

0C0C.ABAC.CABA

2001:DB8:FE:FE:0E0C:ABFF:FEAC:CABA

0C=0000 1100=0000 1110, 0E

2001:DB8:FE:FE::/64

0A0C.ABAC.CABA

2001:DB8:FE:FE:080C:ABFF:FEAC:CABA

0A=0000 1010=0000 1000, 08

When engineers first encounter IPv6, the most obvious and recognizable feature of the protocol is the IP address. It is quite different than the IPv4 one and at first, it seems hard to grasp. The other distinct difference is that IPv6 includes new address types such as link-local addresses. In this lesson, we are going to see that working with IPv6 addresses is not that hard. There are rules to shorten down the address and make it easier to work with.

An IPv6 address is 128 bits in length and is written as eight groups of four hexadecimal digits. Each group is separated from the others by colons (:) as shown in figure 1. Hexadecimal characters are not case sensitive, therefore an address can be written either in uppercase or lowercase, both are equivalent.

Example of an IPv6 address

Figure 1. Example of an IPv6 address

The eight groups make a total of 32 hexadecimal digits, four bits each, which makes a total of 128 bits. RFC 4291 says that the preferred representation of an IPv6 address is x:x:x:x:x:x:x:x and RFC 5952 recommends that the address is written in lowercase.

It is obvious that IPv6 addresses are long and hard to remember and work with. That’s why there are rules that can significantly shorten the address

Shortening IPv6 addresses

There are two rules, described in RFCs 2373 and 5952, that help engineers to reduce the length of the address representation. It’s important to understand from the very beginning that using these two rules shortens only the representation of the address, the address itself is always 128 bits.

Rule 1: Omit groups of all zeros

The first rule that we are going to look at is called Zero Compression. It says that a double colon (::) can replace a single, contiguous string of one or more groups consisting of all 0s. Example 1 illustrates the use of this rule.

Shortening IPv6 addresses, Example 1

Figure 2 – Applying Zero Compression – example 1

Note that Groups 4,5,6 and 7 of the IP address are all zeros. The rule says that we can replace them with a single double colon. There is one very important aspect of this rule – this zero compression with a double colon can be applied only once! Because otherwise, the original IPv6 address cannot be recreated from the shorted representation.

IMPORTANT –  The :: can only appear once in an IPv6 address.

Example 2 illustrates this. Note that there are two contiguous strings of zeros – Group 4 and 5, and Group 7. Having in mind that we can use only one double colon, we can either replace groups 4 and 5 with :: or group 7, but not both.

Applying Zero Compression - example 2

Figure 3 – Applying Zero Compression – example 2

Rule 2: Omit Leading zeros

The other way to shorten addresses is to omit leading zeros in any group of 4 hexadecimal digits. The rule applies only to leading zeros and no trailing zeros. Even if a group consists of 4 zeros 0000 we can only omit the leading 3 – 0000. This is illustrated in the following example.

Applying Zero Compression - example 3

Figure 4 – Applying Zero Compression – example 3

Note that all underscored groups have at least on leading zero. For groups 2,3 and 8, the rules are pretty straightforward, you just remove the leading zeros and that’s about it. But if you look at group 4 for example, you cannot remove all four zeros, so the trailing zero highlighted in yellow must remain.

Combining Rule 1 and 2

The shortest possible representation is achieved by combining both rules we have discussed. Let’s get the IP address from example 3 and apply rule 1 and rule 2 at the same time.

Applying Zero Compression - example 4

Figure 5 – Applying Zero Compression – example 4

You can see that after we apply both rules, the resulting representation is significantly shorter.

Common Mistakes

There are several common mistakes people make when they start applying these techniques. Let’s look at several examples and highlight the key points.

IPv6 address
2001:0cb0:0000:0000:0fc0:0000:0000:0abc

Correctly Shortened
2001:cb0::fc0:0:0:abc
2001:cb0:0:0:fc0::abc

Common Mistake 1 - using :: twice
2001:cb0::fc0::abc

Common Mistake 2 - removing trailing zeros
2001:cb::fc:0:0:abc

In this example, in the original address, there are two consecutive strings of zeros, in groups 3 and 4, and in groups 6 and 7. People often try to replace both with :: and end up with two double colons in the shortened address. This is not allowed though, because it creates an ambiguous address representation. The other common mistake is to remove trailing zeros. Note the hex digits in group 2 – 0cb0, people often remove both 0s, but only the leading zero is allowed to be removed.

Let’s have a look at a few more examples.

Example 1 - The match-all address
IPv6 address - 0000:0000:0000:0000:0000:0000:0000:0000
Shortened - ::

This is one appears very often in questions regarding IPv6 addresses. It is a valid address similar to 0.0.0.0 in IPv4 and its shortened representation is just a double colon. 

Example 2 - The loopback address
IPv6 address - 0000:0000:0000:0000:0000:0000:0000:0001
Shortened - ::1

The above example is the well-knows v6 loopback address. This is the v6 alternative to the well-known 127.0.0.1 in IPv4.

Example 3 - The all-nodes address
IPv6 address - ff02:0000:0000:0000:0000:0000:0000:0001
Shortened - ff02::1

The above example is the well-knows all-nodes multicast address. This is the v6 alternative to the well-known 224.0.0.1 in IPv4. The last example we are going to look at is a random link-local address. 

Example 2 - A random link-local address
IPv6 address - fe80:0000:0000:0000:0f19:1faf:008:5010
Shortened - fe80::f19:1faf:8:5010

It is very important to understand both rules for shortening addresses and to be able to apply them correctly on any random IPv6 address. There are at least a few questions in the CCNA exam that are related in some way to this topic.

Prefix Length

In IPv4, the network portion of the address is written as a dotted-decimal network mask such as 255.255.255.0 and is called a subnet mask. It can also be represented as classless inter-domain routing (CIDR) notation such as /24 indicating that the first 24 bits of the IP address is the network portion.

In IPv6, there is no dotted-decimal representation but only CIDR notation such as /126. Therefore, there is only one way to write an IPv6 prefix:

ipv6-address/prefix-length

The prefix length is a decimal value showing that the number of leftmost bits of the address is the network portion. Let’s take 2001:aaaa:bbbb:cccc:0:0:0:10/64 for example. The netmask length of 64 means that the IPv6 subnet is 2001:aaaa:bbbb:cccc::/64 and  2001:aaaa:bbbb:cccc::10 is a node in this subnet. 

IPv6 Prefix Notation

Figure 6. IPv6 Prefix Notation

Typically in IPv6, engineers choose prefix lengths that are multiples of four. That makes the prefix easier to understand without using a subnet calculator. Look at the example in figure 6, each additional 4 in the prefix length moves the network portion of the address one hexadecimal digit to the right. 

Table 1 – IPv6 Subnetting Example

Prefix Lenght Network Portion Total Addresses
/4 2:: 124
/8 20:: 120
/12 200:: 116
/16 2001:: 112
/20 2001:0:: 108
/24 2001:0d:: 104
/28 2001:0df:: 100
/32 2001:0df8:: 96
/36 2001:0df8:0:: 92
/40 2001:0df8:00:: 88
/44 2001:0df8:00f:: 84
/48 2001:0df8:00f2:: 80
/52 2001:0df8:00f2:0:: 76
/56 2001:0df8:00f2:00:: 72
/60 2001:0df8:00f2:000:: 68
/64 2001:0df8:00f2:0000:: 64

Summary

  • An IPv6 address is a string of 128 bits represented as 32 hexadecimal digits grouped in eight groups separated by colons.
  • Due to its length, it is hard to work with. Two rules have been introduced that shorten the address representation.
    • Rule 1, called Zero Compression, omits a group of consecutive zeros and replaces them with a double colon (::). This can only be applied once per IPv6 address, otherwise, the shortened representation becomes ambiguous.
    • Rule 2 omits leading zeros in a every group of hexadecimal digits. It does not apply to trailing zeros though.
  • The prefix length of IPv6 address is written in CIDR notation like ipv6-address/prefix-length. There is no dotted-decimal representation such as 255.255.255.0 in IPv6.
  • There are at least a few questions in the CCNA exam that are related in some way to address shortening using the above rules.

Сетевые IPv6-адреса. Длина префикса IPv6-адреса. CCNA Routing and Switching.

Префикс /64

Как вы помните, префикс, или сетевая часть адреса IPv4, может быть обозначен маской подсети в десятичном формате с разделительными точками или длиной префикса (запись с наклонной чертой). Например, IPv4-адрес 192.168.1.10 с маской подсети в десятичном формате с разделительными точками 255.255.255.0 эквивалентен записи 192.168.1.10/24.

Протокол IPv6 использует длину префикса для обозначения префиксной часть адреса. IPv6 не использует для маски подсети десятичное представление с разделительными точками. Длина префикса обозначает сетевую часть IPv6-адреса с помощью записи вида «IPv6-адрес/длина префикса».

Диапазон длины префикса может составлять от 0 до 128. Традиционная длина IPv6-префикса для локальных (LAN) и других типов сетей — /64. Это означает, что длина префикса, или сетевая часть адреса, составляет 64 бита, а оставшиеся 64 бита остаются для идентификатора интерфейса (узловой части) адреса.

Источник: Академия Cisco.

Метки: CCNA, Cisco, Routing and Switching.

Добавить комментарий