IPv6 stands for Internet Protocol Version 6, which is the next-generation IP protocol designed by the Internet Engineering Task Force (IETF) to replace IPv4. It is said that the number of addresses it has is enough to encode an address for every grain of sand in the world. The biggest problem with IPv4 is the lack of network address (public IP) resources. Whether it is PCs, mobile phones or PADs, they all need IP addresses. IPv4 is facing the dilemma of being exhausted, which seriously restricts the application and development of the Internet. The use of IPv6 can not only solve the problem of the number of network address resources, but also solve the obstacles for various access devices to connect to the Internet. IPv6 addresses and specifications will gradually become popular. On March 23, 2020, the Ministry of Industry and Information Technology issued the "Notice on Launching a Special Action to Improve IPv6 End-to-End Connectivity in 2020", requiring that by the end of 2020, the number of active IPv6 connections will reach 1.15 billion, a 43% increase from the target of 800 million connections in 2019. With the development and gradual popularization of IPv6, our software will also add support for IPv6 addresses, not just IPv4. This article briefly sorts out the IP address structure and allocation method of IPv6, and also introduces the basic usage methods, which are shared with everyone here. 1. Definition of IPv6 address structure The concepts of nodes, links, sites, and interfaces in IPv6 are as follows:
1. IPv6 address representation 1) Hexadecimal notation: An IPv6 address consists of 128 bits, grouped into 16 bits, and each 16-bit group is written as 4 hexadecimal numbers separated by colons.
2) The representation method is not case-sensitive: 16-bit hexadecimal numbers are not case-sensitive, such as:
3) The leading zeros in each group can be simplified: The leading zeros in each 16-bit group in the IPv6 address can be removed for simplified representation, such as:
4) When the middle bits are consecutively 0: You can omit the consecutive 0s and use :: instead (note that :: can only appear once, otherwise it is impossible to determine how many omitted 0s there are). This symbol can also be used to compress the adjacent consecutive zero bits at the front and end of the address, as shown below:
5) In a mixed IPv4 and IPv6 environment: x:x:x:x:x:x:dddd, where x is the hexadecimal value of the 6 high-order 16-bit groups in the address, and d is the decimal value of the 4 low-order 8-bit groups in the address (standard IPv4 representation). For example, the address 0:0:0:0:0:0:13.1.68.3,
6) Use text IPv6 address in URL: Text address should be enclosed by symbols '[' and ']'. For example, text IPv6 address
7) Prefix representation method:
For example, 2001:0DB8:0:CD30::/60 When writing a node address and the prefix of the node address (for example, the node's subnet prefix), the two are combined and written as follows: Node Address
Both can be abbreviated as
2. EUI-64 format EUI-64 format: Extended Unique Identifier In IPV6, the stateless autoconfiguration mechanism uses the EUI-64 format to automatically configure the IPV6 address. The so-called stateless autoconfiguration refers to a mechanism that allows nodes to configure their own IPV6 addresses when there is no DHCP server in the network. EUI-64 construction rules: Generate an IPV6 address based on the interface's MAC address plus a fixed prefix. Working principle: Automatically expand the 48-bit Ethernet MAC address to 64 bits, and then add a 64-bit prefix to form an IPV6 address Step 1 : Split the 48-bit MAC address in the middle and insert a fixed value FFFE 0050:3EE4:4C00-->0050:3EFF:FEE4:4C00 Step 2: Invert the 7th bit. If it was originally 0, it will become 1. If it was originally 1, it will become 0. 0050:3EFF:FEE4:4C00-->0250:3EFF:FEE4:4C00 Step 3. Add a prefix: For example, add the link-local address prefix FE80, FE80::0250:3EFF:FEE4:4C00. This is a complete IPV6 address. Reason for reversal: In the MAC address, the 7th bit is 1 for local management and 0 for global management; in the EUI-64 format, the 7th bit is 1 for global uniqueness and 0 for local uniqueness 3. IPv6 address classification
4. IPv6 unicast address An identifier for a single interface, used for one-to-one connections. An IPv6 unicast address consists of two parts: a subnet prefix and an interface ID. The subnet prefix is assigned by IANA, ISPs, and other organizations. The interface identifier is currently defined as 64 bits and can be generated by the local link identifier MAC or by using a random algorithm in EUI-64 format to ensure uniqueness. There are six types: 1) Global unicast addresses can be aggregated Currently allocated address prefixes:
The prefixes currently used for IPv6 Internet operations are:
2) Link-local address When the node enables IPv6, each interface will automatically generate a local link address. The prefix 64 bits is fixed, and the subsequent 64 bits of the interface ID are constructed according to the EUI-64 format. Link-local addresses can only communicate on the local link and cannot be routed. 3) Site-local address IPV6 private network addresses, like IPV4 private network addresses, can only be used within a site and cannot be used on the public network. Site-local addresses were originally designed for site-internal addressing that did not require a global prefix. Site-local addresses are now deprecated, and new implementations MUST no longer support the special properties of this prefix as defined in [RFC3513] (i.e., new implementations MUST treat this prefix as global unicast). Existing implementations and deployments may continue to use this prefix. 4) Unsure of address The unicast address 0:0:0:0:0:0:0:0 is called an uncertain address. It cannot be assigned to any node. An example of its application is that when a host is initialized, before the host obtains its own address, the uncertain address can be placed in the source address field of any IPv6 packet it sends. The uncertain address cannot be used as the destination address in an IPv6 packet, nor can it be used in the IPv6 routing header; 5) Loopback address The unicast address 0:0:0:0:0:0:0:1 is called the loopback address. A node uses it to send IPv6 packets to itself. It cannot be assigned to any physical interface. 6) ipv6 address with embedded ipv4 address There are two categories: IPv4-compatible IPv6 addresses and IPv4-mapped IPv6 addresses. Ipv4-compatible ipv6 address: ipv4 addresses must be globally unique. Addresses such as ::13.1.68.3, where the first 96 bits are all 0, are mainly used in an automatic tunnel technology. Messages with this address as the destination will be automatically encapsulated in an IPv4 tunnel. Since this technology cannot solve the problem of address exhaustion, it has gradually been abandoned. IPv4-mapped IPv6 address: For example, ::FFFF.129.144.52.38, the first 80 bits are all 0, the middle 16 bits are all 1, and the last 32 bits are IPv4 addresses. This address is used to represent nodes that only support IPv4 with IPv6 addresses. On IPv6 nodes that support dual stacks, when an IPv6 application sends a destination message with this address, the message actually sent is an IPv4 message (the destination address is the IPv4 address in the "IPv4-mapped IPv6 address"). 5. IPv6 Anycast Address In one-to-near mode, multiple devices share one address. An IPv6 anycast address is a global address assigned to a set of interfaces belonging to different nodes. The address format is the same as that of an IPv6 unicast address and is used to identify the addresses of a group of interfaces. Generally, these interfaces belong to different nodes. Assign the same IPv6 address to devices with the same function. The sender sends a packet with the anycast address as the destination. After the router receives the packet, it forwards it to the device with the address closest to it. When a unicast address is assigned to multiple interfaces, the unicast address automatically becomes an anycast address. As shown in the following two figures, the first one has a non-conflicting address, and the second one has the same address as another host. When two hosts on the same link are configured with the same IPv6 address, the address behind it is marked as "copy". use: One of the uses of IPv6 anycast addresses is to identify a group of routers belonging to the same organization that provides Internet services. These addresses can be used as intermediate forwarding routers in the IPv6 routing header to enable packets to be forwarded through a specific group of routers. Another use is to identify a group of routers in a specific subnet. The message only needs to be received by one of the routers. Some of these anycast addresses are already defined, such as the subnet router anycast address, which has the following format. The "subnet prefix" in an anycast address is used to identify a specific link. This anycast address is syntactically identical to the unicast address of the interface on that link with the interface identifier set to 0. A message sent to the subnet router anycast address is delivered to a router in the subnet. All routers must support subnet anycast addresses. Subnet router anycast addresses are used when a node needs to communicate with one of all routers on a remote subnet (it doesn't matter which one). For example, a mobile node needs to communicate with one of all mobility agents on its "home" subnet. Anycast addresses have the following limitations:
6. IPv6 multicast address One-to-many mode. IPv6 multicast addresses are used to identify a group of interfaces, which generally belong to different nodes. A node may belong to 0 or more multicast groups. Messages sent to a multicast address are received by all interfaces identified by the multicast address. 1) IPv6 multicast address format definition: FF00::/8 in: ① 11111111: 8 bits. Identifies this address as a multicast address ② Flags: 4 bits. The flag field is defined as follows: The highest 3 bits are reserved and must be 0.
③ Scope: 4 bits. Used to mark the application scope of this multicast group. ④ group ID Identifies a multicast group (may be permanent or temporary, the scope is defined by scope) 2) IPv6 permanently allocated multicast addresses The current permanently assigned ("well-known") multicast groups are as follows: Reserved multicast addresses:
Addresses of all nodes:
All router addresses:
The address of the requested node:
The above address is formed by the unicast or anycast address of the requested node: take the lower 24 bits of the unicast or anycast address of the requested node and add the prefix FF02:0:0:0:0:1:FF00::/104 in front. For each unicast address or anycast address configured on the interface of a node or router, a corresponding multicast address of the requested node is automatically generated. It is only valid in the local link scope. Features:
effect:
7. IPv6 addresses that must be supported 1) IPv6 addresses that nodes must support
2) IPv6 addresses that the router must support
2. IPv6 Address Allocation 1. Address configuration IPv6 supports two address autoconfiguration modes: stateless address autoconfiguration and stateful address autoconfiguration. Stateless address autoconfiguration:
During the autoconfiguration process, the host does the following:
Stateful address automatic configuration: such as Dynamic Host Configuration Protocol (DHCP), requires a DHCP server to obtain address configuration information from the DHCP server through the client/server mode. 2. Address allocation ① Global unicast address space allocation The Internet Assigned Number Authority (IANA) is responsible for the allocation of IPv6 address space. Currently, IANA allocates 2001::/16 from the entire aggregatable global unicast address space (format prefix 001). ② IPv6 experimental network address allocation (6BONE) The 6BONE network is a global IPv6 experimental network that uses the network prefix 3ffe:0000::/16. Each pseudo top-level aggregation is allocated a /28 prefix in the range of 3ffe:0800::/28, supporting up to 2048 pseudo top-level aggregations. The end site obtains a /48 prefix from the upstream provider, and each site can be further subdivided into multiple /64 prefixes. The 6BONE network allocates addresses in a hierarchical structure. The address space is defined by IANA and the allocation strategy is defined in RFC2921 (6BONE Pseudo Top-level Aggregation and Network Layer Aggregation Format). 3. Use of IPv6 1) First enable ipv6, as follows: Local testing uses the Windows environment. Or command line form: ipv6 install In XP system, you can use netsh-->interface-->ipv6-->install to install the ipv6 protocol. You can also add the protocol part as shown in the figure below, and then install ipv6. After enabling IPv6, the host will automatically generate an IPv6 link-local address. 2) You can also manually configure the ipv6 address You can use the interface configuration: It can also be configured via the command line:
3) Check the IPv6 address ipconfig When you check, you will find that the tunnel address is as follows: IPv6 and IPv4 communicate through tunnels, which requires the support of special protocols and equipment, such as teredo in the above picture. This will be introduced in the next case study when there is an opportunity. When Teredo is enabled, a Teredo tunnel address will be created, which is usually used to communicate with external hosts. For local testing, you can use a local link address or a manually configured address. Note: Generally, the link local automatic generation uses the EUI-64 format as the interface ID based on the MAC address, but this is not the case on my computer. When I checked other computers, they were generated based on the MAC, and it seems to be generated using a random code. As long as the address is unique within the link, it will be fine. 4) A brief introduction to IPv6 ① PfcNtop and PfcPton PfcNtop and PfcPton provided by the PFC module encapsulate the functions of inet_ntop and inet_pton, and are mainly used to convert IP addresses and their string representations. ② Structure PFC_IPADDR
The structure provided by the protocol component to represent ipv4 or ipv6.
PFC_IPV6_ADDR_SIZE is a 16-byte macro. So the ipv6 address is represented by a 16-byte u8 array. m_wScopeId is mainly used for link-local addresses, because link-local addresses are unique on a link, and a host can use the same link-local address to access two different links, so scopeid is used to distinguish them. This field corresponds to uint32_t sin6_scope_id in the sockaddr_in6 structure. After testing, if the system has only one link-local address, win7 and win10 do not need to fill in this field to communicate with the machines on the link, but there is a problem with communicating with the XP system. ③ getaddrinfo function Get the IP address. The gethostbyname and gethostbyaddr functions only support IPv4, while getaddrinfo supports both IPv4 and IPv6. It returns a linked list of sockaddr structures instead of an address list. This method is not encapsulated by the protocol component yet. Please use it if you have the need. at last IPv6 involves a lot of things, and some of the concepts are sometimes difficult to understand. You must look up information and then understand them. This article only introduces part of IPv6 based on rfc4291. You will need to refer to more information on other aspects of IPv6 in the future. |
<<: Network as a Service (NaaS) Demand is Changing the Enterprise Market
On June 2, it was reported that the technical sta...
On February 24, the 2021 Mobile World Congress Sh...
The fifth generation of mobile communication tech...
Historical data has shown that performance has a ...
According to a recent study conducted by the Glob...
The last time the tribe shared information about ...
[51CTO.com original article] 2021 is the first ye...
Many friends often leave messages asking, how to ...
Recently, the three major operators have announce...
Nowadays, the https protocol is widely valued and...
As the world becomes increasingly connected and t...
Usually, our applications do not need to handle t...
What is the difference between the Internet of Id...
In the first half of this year, with the skyrocke...
On March 15, 2018, the 11th Microsoft Accelerator...