With the popularity of IPv6 technology, DHCPv6 as a basic technology is more or less every IT people need to understand. This paper will rely on Tencent cloud CVM to analyze the working principle of DHCPv6 in detail, hoping to let more partners master DHCPv6 protocol. What is the DHCPv6 protocol? How does a client automatically obtain an IPV6 address for the first time? How can the CVM automatically obtain the IPv6 address used last time after being restarted? The author: Tencent Cloud after-sale architect Li Binwen.
Introduction to DHCPv6
Dynamic Host Configuration Protocol for IPv6 (DHCPv6) is a network Protocol used to assign IPv6 addresses, prefixes, and DNS configurations.
DHCPv6 is a protocol that runs between the client and server. Like DHCP in IPv4, all packets are based on UDP (port 546 is used for the client and port 547 is used for the server). However, there are no broadcast packets in IPv6. Therefore, DHCPv6 uses multicast packets (all DHCPv6 servers join and listen to the multicast group FF02::1:2 by default). The client does not need to configure an IPv6 address for the server.
1. Advantages of DHCPv6 protocol
Compared with other IPV6 address allocation methods, DHCPv6 has the following advantages:
-
In DHCPv6 mode, IPv6 addresses assigned to IPv6 hosts and specific IPv6 hosts can be recorded to facilitate network management.
-
DHCPv6 supports assigning IPv6 prefixes to network devices, facilitating automatic configuration of the entire network and hierarchical network management.
-
In addition to assigning IPv6 addresses and prefixes to IPv6 hosts, you can also assign network configuration parameters such as the IPv6 address of the DNS server.
2. DHCPv6 packet format
DHCPv6 belongs to the application layer of the OSI seven-layer protocol stack, so it needs to encapsulate the IPv6 header at the network layer and the UDP header at the transport layer.
3. DHCPv6 field comment
-
Msg-type: 8 bits in length, indicating the packet type. A total of 13 message types are defined.
-
Transaction-id: 24 bits in length, it indicates the interaction ID randomly generated by the DHCPv6 client (THE id of the packet interaction initiated by the server is 0). It identifies the DHCPv6 packets that exchange one time. For example, Solicit/Advertise indicates one interaction, and Request/Reply indicates another, and the two have different ids.
-
Options: Indicates an optional DHCPv6 field. The length varies according to the message type. This field contains the configuration information that the DHCPv6 server assigns to the IPv6 host, such as the client id, server ID, or valid life cycle.
4. Several common message types defined by DHCPv6
(1) Solicit, the DHCPv6 client uses Solicit message to discover the location of the DHCPv6 server.
(2) Advertise, the DHCPv6 server sends Advertise message to respond to Solicit message, and informs the client what DHCPv6 services it can provide.
(3) Request: The DHCPv6 client sends a Request packet to the DHCPv6 server to Request IPv6 addresses and other configuration information.
(4) Confirm: The DHCPv6 client sends a Confirm message to any reachable DHCPv6 server to check whether the IPv6 address it has obtained applies to the link.
(5) Reply. The DHCPv6 server sends Reply packets in the following situations:
-
The DHCPv6 server sends a Reply message carrying the address and configuration information to Solicit, Request, Renew, and Rebind packets received from the DHCPv6 client.
-
The DHCPv6 server sends a Reply message with configuration Information to respond to the received Information-request message.
-
This parameter is used to respond to Confirm, Release, or Decline messages sent by the DHCPv6 client.
(6) Decline, the DHCPv6 client sends a Decline message to the DHCPv6 server, stating that one or more addresses assigned by the DHCPv6 server have been used by other clients on the link where the DHCPv6 client resides.
Obtain IPV6 address resolution for the first time
The CVM accesses Tencent Cloud IPv6 network for the first time and automatically obtains an IPv6 address through DHCPv6, as shown in the following interactive packets:
1. Discovery phase
The client CVM (cloud server) sends a solicit-message to find the DHCPv6 server and requests the DHCPv6 server (Tencent cloud virtual component) to allocate an IPv6 address and network configuration parameters for it.
Since THE CVM does not know the IPv6 address of the DHCPv6 server, it sends solicitation messages to all DHCPv6 servers within the same link using the multicast address: FF02::1:2.
Solicit message carries information about the client’s DUID, the non-temporary address to Solicit, and other network configuration parameters.
2. Provision phase
After receiving a solicitation message, the DHCPv6 server selects the latest IPv6 address for solicitation in ascending order, and sends a Advertise message to the CVM in unicast mode.
Advertise packets contain the SERVER DUID, client DUID, IPv6 address assigned to the client, and lease information.
3. Selection stage
Solicit packets are sent in groups, so if multiple DHCPv6 servers exist in the same solicitation range, the servers that receive the Solicit packets will respond to Solicit packets.
If multiple DHCPv6 servers respond to the Advertise message to the DHCPv6 client, the DHCPv6 client selects the Advertise message with the highest priority (the DHCPv6 server can include Preference in the Advertise message, In order to control the client’s selection of servers), the client sends a Request packet in multicast mode to all DHCPv6 servers in the same link range. The Request packet contains the DUID of the DHCPv6 server (with a high priority), the DUID of the client, and the IPv6 address of the client.
4. Confirmation phase
After receiving a Request packet, the DHCPv6 server checks the server DUID information contained in the packet.
-
If the server DUID carried in the packet is not the DUID of the local server, the device does not respond to the Request packet and recycles the IPv6 address requested in the Request packet.
-
If the server DUID carried in the packet is the local server DUID, the server responds to the Reply packet in unicast mode to confirm that the IPv6 address requested in the Request packet is allocated to the client.
5. CVM processing on the client
After receiving a Reply packet, the CLIENT CVM sends Neighbor Solicitation packets to check whether other clients in the link use the same IPv6 address. If no Reply is received within a specified period, the client can use the IPv6 address.
Note: If a Neighbor Solicitation message is received, another client uses the address, and the CVM sends a unicast Decline message to the server. Solicit and send another soliciting message to Solicit a new available IPv6 address. After receiving the Decline packet, the service end classifies the IPv6 address contained in the packet as a conflict address.
3. Obtain IPV6 address resolution after the restart
This is not the first time for the CVM to access Tencent cloud IPv6 network, and DHCPv6 automatically obtains IPv6 address packets as follows:
First, when the client CVM (cloud server) is not connected to the IPv6 network for the first time (for example, after being restarted or enabled after the NETWORK adapter is disabled), the CVM sends a Confirm message using the multicast address FF02::1:2 to Confirm whether the previous IPv6 address of the CVM is still available.
Second, after receiving the Confirm message, the DHCPv6 server (Tencent Cloud virtual component) checks whether all IP addresses in the Confirm message apply to the CVM.
If all the IPv6 addresses in the Confirm packet have passed the soliciting packet, the server responds to a close Reply packet. If the client receives a close Reply packet, it sends a Solicit message and asks for an IPv6 address again. .
Third, after receiving a Reply message, the client CVM sends Neighbor Solicitation messages to check whether other clients in the link range use the same IPv6 address. If no Reply is received within a specified time, the CVM can use the address.
The client automatically obtains IPv6 addresses for the first time and not for the first time through DHCPv6. This article also describes the functions of six common types of DHCPv6 packets.