WO2013078814A1 - Ip address allocation method and device - Google Patents

Ip address allocation method and device Download PDF

Info

Publication number
WO2013078814A1
WO2013078814A1 PCT/CN2012/074195 CN2012074195W WO2013078814A1 WO 2013078814 A1 WO2013078814 A1 WO 2013078814A1 CN 2012074195 W CN2012074195 W CN 2012074195W WO 2013078814 A1 WO2013078814 A1 WO 2013078814A1
Authority
WO
WIPO (PCT)
Prior art keywords
dhcp
address
client host
addresses
dhcp server
Prior art date
Application number
PCT/CN2012/074195
Other languages
French (fr)
Chinese (zh)
Inventor
张玉莹
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2013078814A1 publication Critical patent/WO2013078814A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5007Internet protocol [IP] addresses
    • H04L61/5014Internet protocol [IP] addresses using dynamic host configuration protocol [DHCP] or bootstrap protocol [BOOTP]

Definitions

  • DHCP Dynamic Host Configuration Protocol
  • IP Internet Protocol
  • the DHCP protocol adopts the client host-server (CLIENT-SERVER) mechanism, and the entire configuration process is automatically implemented. All configuration information is centrally controlled by the DHCP server (DHCP Server). By configuring the IP address to use the lease, you can achieve the IP address reuse effect. Because by default, the router does not send received broadcast packets from one subnet to another. When the DHCP server and the client host are not in the same subnet, the router acting as the default gateway of the client host must send the broadcast packet to the subnet where the DHCP server is located. This function is called DHCP Relay. The DHCP Relay implements transparent interaction between the DHCP client (DHCP Client) and the DHCP server (DHCP Server).
  • a DHCP relay network generally adopts a topology scheme as shown in FIG. 1.
  • the DHCP client host communicates with the DHCP relay layer through a Layer 2 transparent transmission network.
  • the DHCP relay agent and the DHCP server implement Layer 3 routing.
  • the DHCP packets need to be re-packaged when they pass through the DHCP relay agent.
  • the DHCP Relay network whenever a DHCP client host goes online, the DHCP Relay and the DHCP Server complete a DHCP process.
  • 2 is a flow chart of DHCP packet exchange of a client host according to the related art. As shown in FIG.
  • a DHCP client host needs to complete the network parameter acquisition through two exchanges, complete the renewal process through one interaction, and complete the transfer through one pass. Release process.
  • the number of packets between the DHCP relay agent and the DHCP server will be very large, occupy a large amount of bandwidth, increase unnecessary network traffic, and bring insecure factors to the network. Document processing capabilities are also a big challenge.
  • SUMMARY OF THE INVENTION In the related art, in a DHCP relay network, whenever a DHCP client host goes online, the DHCP Relay needs to complete a DHCP process with the DHCP server, thereby increasing the network traffic between the DHCP Relay and the DHCP Server.
  • a method for allocating an IP address including: after receiving a first dynamic host configuration protocol DHCP discovery message, the DHCP relay determines whether it is necessary to obtain a network protocol IP address from a DHCP server; If the result is yes, the DHCP relay acquires and stores a plurality of IP addresses from the DHCP server; and selects one of the obtained multiple IP addresses to be allocated to send the first DHCP discovery message.
  • Client host Preferably, in the case that the determining result is no, the method further includes: selecting an IP address from the locally stored IP addresses and assigning the IP address to the client host.
  • determining whether to obtain the network protocol IP address from the DHCP server comprises: determining whether the DHCP relay stores an IP address that is not allocated to the client host.
  • acquiring the plurality of IP addresses from the DHCP server includes: sending a second DHCP discovery message to the DHCP server; obtaining a request from the DHCP response message sent by the DHCP server to obtain the Multiple IP addresses.
  • the method further includes: sending, to the DHCP server, a DHCP request message that carries the multiple IP addresses; When the plurality of IP addresses are consistent with the IP address sent by the DHCP, the DHCP acknowledgement message sent by the DHCP server is received.
  • the method further includes: establishing a client host information table, where the client host information table is set to record a correspondence between the client host and an IP address allocated for the client host.
  • the server After receiving the leaving message sent by the client host, releasing the IP address assigned to the client host, deleting the information of the client host in the client host information table; determining that the DHCP server is the DHCP relay After the allocated time of the plurality of IP addresses reaches the first preset lease period, it is determined whether there is still information of the client host in the client host information table, and if the determination result is no, the DHCP is sent to the DHCP. The server sends a DHCP release message to release the plurality of IP addresses. If the determination result is yes, the plurality of IP addresses are renewed to the DHCP server.
  • the method further includes: when the second preset lease arrives, determining Receiving a leaving message from the client host, if not, sending a notification to the client host, informing the client host to renew the IP address selected from the obtained plurality of IP addresses, wherein The first preset lease period is greater than the second preset lease period.
  • an apparatus for allocating an IP address including: a first determining module, configured to: after receiving the first dynamic host configuration protocol DHCP discovery message, determine whether a network protocol needs to be obtained from a DHCP server An IP address; an obtaining module, configured to acquire and store a plurality of IP addresses from the DHCP server if the determination result is yes; and an allocation module configured to select one IP address allocation from the obtained plurality of IP addresses A client host that sends the first DHCP discovery message.
  • the allocating module is further configured to: if the result of the determination is negative, select an IP address from the locally stored IP addresses and assign the IP address to the client host.
  • the obtaining module includes: a sending unit, configured to send a second DHCP discovery message to the DHCP server; and an acquiring unit, configured to acquire a request to obtain the multiple IPs from a DHCP response message sent by the DHCP server address.
  • the device further includes: a sending module, configured to send a DHCP request message carrying the multiple IP addresses to the DHCP server; and a receiving module, configured to send the multiple IP addresses and the DHCP server If the IP addresses are the same, the DHCP confirmation message sent by the DHCP server is received.
  • the device further includes: an establishing module, configured to: after receiving the DHCP acknowledgement message, establish a client host information table, where the client host information table is set to record a client host and an IP address assigned to the client host
  • the release module is configured to release the IP address assigned to the client host after receiving the leaving message sent by the client host, and delete the information of the client host in the client host information table;
  • the setting is to determine that the IP address usage time in the DHCP relay reaches a preset lease period;
  • the second determining module is configured to determine whether there is still information about the client host in the client host information table;
  • the sending module is further configured to If the determination result of the second determining module is negative, sending a DHCP release message to the DHCP server, releasing all locally stored IP addresses; and renewing the module, setting the judgment result in the second determining module In the case of YES, the plurality of IP addresses are renewed to the DHCP server.
  • the DHCP relay can apply for multiple IP addresses to the DHCP server through one packet exchange, and implement batch application of the IP address and network parameters.
  • the DHCP relay can assign the IP address obtained from the DHCP server to the client host without having to apply for an IP address to the DHCP server when each client host goes online, thereby reducing the DHCP relay and the DHCP server. Network traffic.
  • FIG. 1 is a schematic diagram of a network topology of a DHCP relay network according to the related art
  • FIG. 2 is a flowchart of DHCP packet interaction of a client host according to the related art
  • FIG. 3 is an IP address according to an embodiment of the present invention.
  • FIG. 4 is a flowchart of a method for processing a DHCP Discover message by a DHCP relay according to a preferred embodiment of the present invention
  • FIG. 5 is a flowchart of a method for processing a DHCP Discover message by a DHCP server according to a preferred embodiment of the present invention
  • FIG. 6 is a flowchart of a method for processing a DHCP Offer message by a DHCP relay according to a preferred embodiment of the present invention
  • FIG. 7 is a flowchart of a method for processing a DHCP Request message by a DHCP server according to a preferred embodiment of the present invention
  • 8 is a flowchart of a method for processing a DHCP ACK message by a DHCP relay according to a preferred embodiment of the present invention
  • FIG. 9 is a flowchart of a method for processing a DHCP Release message by a DHCP Relay according to a preferred embodiment of the present invention
  • FIG. 11 is a block diagram showing the structure of a device for allocating a preferred IP address according to an embodiment of the present invention.
  • the DHCP Relay in a DHCP relay network, whenever a DHCP client host goes online, the DHCP Relay needs to complete a DHCP process with the DHCP server, thereby increasing the network traffic between the DHCP Relay and the DHCP Server.
  • the example provides a method and a device for allocating an IP address.
  • the DHCP relay can apply for multiple IP addresses to the DHCP server through a packet exchange, and implement batch application of the IP address and network parameters.
  • FIG. 3 is a flowchart of a method for allocating an IP address according to an embodiment of the present invention. As shown in FIG. 3, the method may include the following steps (step S302-step S306).
  • Step S302 After receiving the first dynamic host configuration protocol (DHCP) discovery message, the DHCP relay determines whether it is necessary to obtain a network protocol IP address from the DHCP server. Step S304, in a case where the determination result is YES, the DHCP relay acquires and stores a plurality of IP addresses from the DHCP server. Step S306, selecting one of the obtained multiple IP addresses to be assigned to the client host that sends the first DHCP discovery message. After receiving the DHCP discovery message, the method first determines whether it is necessary to obtain an IP address and a corresponding network parameter from the DHCP server, and if the judgment result is yes, obtain multiple IP addresses from the DHCP server, and obtain more from the DHCP server.
  • DHCP dynamic host configuration protocol
  • IP addresses allocated by the DHCP server can be saved, so that when other client hosts request to allocate an IP address and corresponding network parameters, the client host can be directly assigned an IP address and corresponding network parameters from the remaining IP addresses without
  • the DHCP server exchanges packets, which reduces network traffic between the DHCP Relay and the DHCP server and reduces the processing power of the DHCP Server. The above various steps are described below.
  • a DHCP relay network when a client host goes online, the IP address and corresponding network parameters can be obtained through a DHCP process.
  • the client host sends a DHCP discovery message to the DHCP Relay (DHCP Discover After receiving the DHCP discovery message, the DHCP Relay re-encapsulates the received DHCP discovery message and sends a re-encapsulated DHCP discovery message to the DHCP server to request the DHCP server to assign an IP address and corresponding network parameters.
  • the client host After receiving the re-encapsulated DHCP discovery message, the client host is assigned an IP address and corresponding network parameters, and sends a DHCP response message (DHCP OFFER) carrying the assigned IP address and corresponding network parameters to the DHCP Relay; the DHCP Relay receives the DHCP response.
  • DHCP OFFER DHCP response message
  • the IP address assigned by the DHCP server and the corresponding network parameters are sent to the client host, so that the client host accesses the network through the assigned IP address and corresponding network parameters.
  • the DHCP Relay obtains an IP address and corresponding network parameters for each online client from the DHCP server, so that a large number of packet interactions occur between the DHCP Relay and the DHCP server, thereby occupying the network. Bandwidth, and challenges the processing power of the DHCP Server.
  • the DHCP relay can apply for multiple IP addresses and corresponding network parameters to the DHCP server at one time in order to reduce the packet exchange between the DHCP relay and the DHCP server. .
  • the DHCP Relay When the client host goes online, the DHCP Relay will assign one of the multiple IP addresses requested by the DHCP server to the client host requesting the IP address and corresponding network parameters. During the above process, the DHCP relay does not need to exchange packets with the DHCP server, which reduces the network traffic between the DHCP relay and the DHCP server and reduces the processing requirements of the DHCP server. In addition, a related authentication mechanism can be adopted between the DHCP Relay and the DHCP Server to improve security performance. When the client host goes online, it sends a DHCP discovery message (that is, the first DHCP discovery message) to the DHCP relay.
  • a DHCP discovery message that is, the first DHCP discovery message
  • the DHCP relay After receiving the DHCP discovery message sent by the client host, the DHCP relay can determine whether it needs to obtain the IP address and corresponding network parameters from the DHCP server. When obtaining the IP address and corresponding network parameters from the DHCP server, obtain multiple IP addresses and corresponding network parameters from the DHCP server. When you do not need to obtain the IP address and corresponding network parameters from DHCP, select from the IP addresses stored in the DHCP Relay. An IP address is assigned to the client host. You can configure the conditions for the DHCP relay to apply for IP addresses and corresponding network parameters from the DHCP server in batches. The DHCP relay determines whether it needs to obtain an IP address from the DHCP server.
  • the DHCP relay agent receives the DHCP discovery message from the client host, the DHCP relay determines whether the number of remaining IP addresses in the DHCP relay is less than a preset threshold. When the number of IP addresses is less than the preset threshold, the DHCP relay obtains multiple IP addresses and corresponding network parameters from the DHCP server. When the number of remaining IP addresses in the DHCP relay is greater than the preset threshold, the DHCP relay can directly receive the remaining from the DHCP relay. The IP address is assigned to the client host in the IP address and the corresponding network parameters. Alternatively, after receiving the DHCP discovery message, it may be determined whether an IP address is stored in the DHCP Relay.
  • the DHCP relay stores an IP address, you can directly select an IP address and corresponding network parameters from the IP addresses stored in the DHCP relay, and assign them to the client host that requests the network parameters. If the DHCP relay does not store the client host, The IP address and the corresponding network parameters, the DHCP relay can obtain multiple IP addresses and corresponding network parameters from the DHCP server. After obtaining multiple IP addresses, the DHCP relay selects an IP address and corresponding network parameters from multiple IP addresses obtained. It is assigned to the client host that sends the DHCP discovery message, and the DHCP Relay can store the acquired multiple IP addresses and network parameters, and when other client hosts go online, they are assigned to other client hosts.
  • the DHCP relay may determine whether the DHCP discovery message is received for the first time in the current period, that is, after receiving the DHCP discovery message, determine whether the DHCP relay is The DHCP Receive message is received for the first time after each batch release of the IP address.
  • the DHCP Relay receives the DHCP Discover message for the first time, the DHCP Relay obtains multiple IP addresses and corresponding network parameters from the DHCP server.
  • the DHCP Relay is not the first Upon receiving the DHCP discovery message, it can be determined that the DHCP relay has obtained multiple IP addresses from the DHCP server.
  • the DHCP relay can select one IP address and corresponding network parameters from multiple IP addresses stored locally, and assign it to send DHCP discovery.
  • the client host of the message If the DHCP relay needs to obtain multiple IP addresses from the DHCP server, the DHCP relay can re-encapsulate the received DHCP discovery message and send a re-encapsulated DHCP discovery message (second DHCP discovery message) to the DHCP server to request DHCP Server.
  • the DHCP relay assigns multiple IP addresses and corresponding network parameters to the DHCP relay.
  • the DHCP server assigns an IP address to the DHCP relay according to the actual situation.
  • the IP address and corresponding network parameters can be carried in the DHCP response message and sent to the DHCP relay.
  • the DHCP relay receives the DHCP relay.
  • the DHCP response message sent by the DHCP server, and the multiple IP addresses assigned to it and the corresponding network parameters can be obtained from the DHCP response message.
  • the DHCP relay can send the received IP address and the corresponding network parameters to the DHCP server.
  • the IP address and the corresponding network parameters are carried in the DHCP request message (DHCP Request message), and the DHCP server allocates the IP address information.
  • the DHCP Relay After verifying that the IP address information received by the DHCP Relay is consistent with the IP address information assigned to it, the DHCP Relay sends a DHCP acknowledgment message (DHCP ACK message) to the DHCP Relay.
  • DHCP ACK message DHCP acknowledgment message
  • the DHCP Relay receives the DHCP acknowledgment message sent by the DHCP server and stores it.
  • the IP address assigned to it and the corresponding network parameters In practical applications, the number of assigned IP addresses can be determined by the DHCP Relay or by DHCP.
  • the DHCP Discovery message sent by the DHCP relay can carry the number of IP addresses to be applied for; the number of IP addresses assigned by the DHCP server is determined.
  • the DHCP server can determine the number of IP addresses assigned to it according to the DHCP relay. For example, according to the number of client hosts owned by the DHCP relay, the IP address of the DHCP relay and/or the DHCP relay application history, and the DHCP server. The amount of the assigned IP address, etc., determines the number of IP addresses assigned to the DHCP Relay.
  • the DHCP Relay may establish a client host information table for managing the IP address assigned to the client and the corresponding network parameters, and record the IP address and corresponding address of the client host and the client host. Correspondence of network parameters.
  • the client host When the client host is offline, it can send a Leave message to the DHCP Relay. After receiving the Leave message sent by the client host, the DHCP Relay releases the IP address assigned to the client host and deletes the information of the corresponding client host in the client host information table.
  • the IP address can be reassigned to the host requesting the IP address and corresponding network parameters. To increase the utilization of IP addresses, you can set a lease for the assigned IP address.
  • the DHCP server can assign a longer lease to the IP address segment.
  • the DHCP Relay assigns a shorter lease to the client host. The user's keep-alive can be implemented, and frequent packet exchange between the DHCP relay and the DHCP server is avoided.
  • the client can renew the IP address and corresponding network parameters to the DHCP relay.
  • the DHCP Relay can continue to the DHCP server when the long lease period allocated by the DHCP server for the IP address segment arrives. Rent IP address and network parameters.
  • the DHCP may release multiple IP addresses allocated by the DHCP server for the DHCP relay at one time, for example, when the DHCP relay determines the DHCP server.
  • the usage time of multiple IP addresses for example, an IP address segment
  • the preset lease period that is, the longer lease period mentioned above
  • the DHCP relay can use the Option field in the DHCP packet to complete the batch application of the IP address and corresponding network parameters between the DHCP Relay and the DHCP server.
  • two custom Option fields of the DHCP protocol may be used, which may be called Option-A and Option-B, respectively.
  • the DHCP Relay can be used to perform client host number allocation planning. For example, if the DHCP relay agent is configured to connect 100 client hosts, the DHCP relay agent will receive the DHCP Discover message from the first DHCP client to re-encapsulate the packet. Client host number planning information: Apply for 100 IP addresses and corresponding network parameters. As shown in Figure 4, after receiving the DHCP Discover message, the DHCP Relay can determine to send DHCP.
  • the client host of the Discover message is the first client host. If it is the first client host, DHCP Relay When the packet is re-encapsulated, the Option-A option field is inserted. This field carries the total number of user plans. If the client host is not the first client host, determine whether there is any remaining IP address segment requested by the DHCP relay. If so, the DHCP relay performs the DHCP server function to directly assign the IP address and network parameters to the DHCP client host. If there is no remaining IP address in the relay, the client host can be denied access and an alarm print is given. As shown in Figure 5, when the DHCP server receives the DHCP Discover message carrying Option-A, it determines whether the DHCP server identifies Option-A.
  • the DHCP server can identify Option-A, it can parse the parameter information carried in Option-A. (Request for IP address and the number of corresponding network addresses, DHCP Relay client host planning number, etc.). If the DHCP server can meet the requirements described in Option-A, you can assign 100 IP addresses at a time. You can also encapsulate the relevant network parameters into Option-B and insert the DHCP Offer packets to the DHCP Relay. If there are less than 100 IP addresses remaining in the DHCP Server, special handling is required.
  • the DHCP relay is not assigned an IP address, it is considered to be in an abnormal state, and an alarm is given; or, for each DHCP request, an IP address is assigned and an alarm is given; or according to the remaining IP address in the DHCP server.
  • the number is determined by the number of IP addresses assigned by the DHCP Relay. If the DHCP server does not support the Option-A option, you can directly ignore the Option-A option, perform normal process processing, and do not insert the Option-B option in the response packet. As shown in Figure 6, when the DHCP Relay receives the DHCP Offer packet, it determines whether the DHCP Offer packet carries the Option-B option.
  • the temporary user entry is created and sent to the DHCP server.
  • the DHCP Request message carrying the Option-A option is copied to the Option-A option and encapsulated in the DHCP Request message.
  • the DHCP Offer packet received by the DHCP Relay does not carry the Option-B option, the normal DHCP packet exchange process is performed.
  • the DHCP server receives the DHCP Request message carrying Option-A, it compares the received IP address and the corresponding network parameters with the temporary entries established on the DHCP server. If they are the same, the local user is established. The information is sent and the DHCP ACK packet carrying Option-B is sent for confirmation. If the packets are inconsistent, the user access is denied.
  • the DHCP message is a normal DHCP process. As shown in Figure 8, when the DHCP Relay receives the DHCP ACK packet, it determines whether to carry the Option-B option. If it is carried, the DHCP Relay establishes a user information table and sends a DHCP ACK packet to the first client. If the DHCP Offer message does not carry the Option-B option, the normal packet exchange process is performed. When the client in the network initiates the DHCP process to obtain the IP address and the corresponding network parameters, the DHCP relay can directly push the IP address and related parameters to act as a DHCP server without having to send packets between the DHCP relay and the DHCP server.
  • the packet only needs to be exchanged between the user and the DHCP relay.
  • the lease of the DHCP relay agent expires, a process of renewing the lease between the DHCP relay agent and the DHCP server is performed.
  • the interaction with the above-mentioned packets is similar.
  • the DHCP Relay receives the Leave message, it can determine whether it is the last user.
  • the DHCP relay can perform the following two methods: 1) clear local user information; 2) send a DHCP Release message to the DHCP server to release all IP addresses.
  • the DHCP relay When the user is not the last user, the DHCP relay does not need to exchange packets with the DHCP server. You only need to clear the user information locally.
  • the DHCP Relay can pre-bind the Media Access Control (MAC) address and IP address of the client host, and only assign an IP address to the bound MAC address to improve security. Sex.
  • the preferred embodiment of the present invention optimizes the interaction of the DHCP message, and overcomes the problem that the DHCP packet exchange data traffic is large in a large network topology, which brings a large burden to the DHCP server, and is fully compatible with the existing protocol standard. , greatly reducing the number of DHCP message interactions and improving security performance to a certain extent.
  • an IP address allocation apparatus is further provided, which can be located in a DHCP relay to allocate an IP address and corresponding network parameters to a client host in a DHCP network.
  • FIG. 10 is a structural block diagram of an apparatus for allocating an IP address according to an embodiment of the present invention. As shown in FIG. 10, the apparatus may include: a first determining module 10, an obtaining module 20, and an allocating module 30.
  • the first judging module 10 is configured to: after receiving the first DHCP discovery message (that is, the DHCP discovery message sent by the client host), determine whether it is necessary to obtain an IP address from the DHCP server (DHCP server); the acquiring module 20, and the first The determining module 10 is coupled to be configured to acquire and store a plurality of IP addresses from the DHCP server if the determination result is yes; the assigning module 30 is coupled to the obtaining module 20, and is configured to select from the acquired multiple IP addresses. An IP address is assigned to the client host that sent the first DHCP discovery message. To avoid increasing network traffic between the DHCP Relay and the DHCP Server, the DHCP Relay can apply to the DHCP Server for multiple IP addresses and corresponding network parameters at one time.
  • the DHCP Relay can assign one of the multiple IP addresses requested from the DHCP server to the client host requesting the IP address and the corresponding network parameters.
  • the DHCP relay does not need to exchange packets with the DHCP server, which can effectively reduce the network traffic between the DHCP relay and the DHCP server.
  • the DHCP does not need to process excessive DHCP packets, thus reducing the processing capacity of the DHCP server. Requirements.
  • the client host can send a DHCP discovery message to the DHCP relay.
  • the first determining module 10 can determine whether to obtain the IP address and the corresponding network parameter from the DHCP server.
  • the obtaining module 20 may obtain multiple IP addresses and corresponding network parameters from the DHCP server. If the DHCP relay does not need to obtain an IP address and corresponding network parameters from the DHCP server, the allocation module 30 may be locally from the DHCP relay. An IP address is selected from the stored IP addresses and assigned to the client host requesting the IP address and corresponding network parameters. You can configure the conditions for the DHCP relay to apply for IP addresses and corresponding network parameters from the DHCP server in batches.
  • the DHCP relay determines whether to obtain an IP address from the DHCP server based on the preset conditions. For example, after the DHCP discovery message of the client host is received, the first determining module 10 can determine whether the number of remaining IP addresses in the DHCP relay is less than a preset threshold. When the number of remaining IP addresses in the relay is less than a preset threshold, the obtaining module 20 may obtain multiple IP addresses and corresponding network parameters from the DHCP server. When the number of remaining IP addresses in the DHCP relay is greater than a preset threshold, the allocation module 30 The client host can be assigned an IP address and corresponding network parameters from the remaining IP addresses in the DHCP Relay.
  • the first determining module 10 may determine whether an IP address is stored in the DHCP relay. If the DHCP relay stores an IP address that can be used by the client host, the distribution module 30 can select an IP address and corresponding network parameter from the IP address stored in the DHCP relay, and assign it to the client host that requests the network parameter; The IP address is not stored, and the obtaining module 20 can obtain multiple IP addresses and corresponding network parameters from the DHCP server. After obtaining multiple IP addresses, the allocation module 30 selects an IP address and corresponding network parameters from the obtained IP addresses, and assigns them to the IP address.
  • the client host that sends the DHCP discovery message, and the DHCP Relay can store the acquired multiple IP addresses and network parameters, and when other client hosts go online, they are assigned to other client hosts. Further, after the DHCP relay receives the DHCP discovery message, the first determining module 10 determines whether the DHCP discovery message is received for the first time to receive the DHCP discovery message, that is, after receiving the DHCP discovery message, whether the DHCP relay is determined. It is the first time that a DHCP discovery message is received.
  • the obtaining module 20 can obtain multiple IP addresses and corresponding network parameters from the DHCP server; when the DHCP relay is not receiving the DHCP for the first time
  • the discovery message can be determined that the DHCP relay has obtained multiple IP addresses from the DHCP server, and the distribution module 30 can select one IP address and corresponding network parameters from the obtained multiple IP addresses, and allocate them to the corresponding client host.
  • the DHCP Relay can re-encapsulate the received DHCP discovery message and send the re-encapsulated DHCP to the DHCP server.
  • the discovery message (referred to as the second DHCP discovery message) requests the DHCP server to allocate multiple IP addresses and corresponding network parameters, and the DHCP server allocates an IP address to the DHCP Relay, and carries the allocated IP and corresponding network parameters in the DHCP response message. Sent to the DHCP Relay; DHCP Relay receives the DHCP Server
  • the obtaining module 20 may include: a sending unit, configured to send a second DHCP discovery message (ie, a re-encapsulated DHCP discovery message) to the DHCP server;
  • the obtaining unit is configured to obtain a request for acquiring multiple IP addresses and corresponding network parameters from a DHCP response message sent by the DHCP server.
  • the DHCP relay can send the received IP address to the DHCP server, and the DHCP authenticates the assigned IP address information.
  • the DHCP Relay is sent to the DHCP Relay.
  • a DHCP acknowledgement message is sent, and the DHCP relay receives the DHCP determination message sent by the DHCP server, and stores the assigned IP address and corresponding network parameters. Therefore, in a preferred embodiment of the present invention, as shown in FIG. 11, the foregoing apparatus may further include: a sending module 40, coupled to the acquiring module 20, configured to send a DHCP carrying multiple IP addresses to the DHCP server.
  • the request message 50 is coupled to the sending module 40 and configured to receive the DHCP acknowledgement message sent by the DHCP server when the multiple IP addresses match the IP address sent by the DHCP server.
  • the DHCP relay may establish a client host information table in order to manage the IP address and corresponding network parameters allocated thereto. Therefore, the foregoing apparatus may further include: an establishing module, configured to receive the DHCP After confirming the message, a client host information table is created, wherein the client host information table can record the correspondence between the client host and the IP address assigned to the client host.
  • the DHCP Relay can conveniently manage the IP address. When the client host is offline, it can send a Leave message to the DHCP Relay.
  • the DHCP Relay After receiving the Leave message sent by the client host, the DHCP Relay releases the IP address assigned to the client host and deletes the information of the corresponding client host in the client host information table.
  • the device may further include: a release module configured to: after receiving the leaving message sent by the client host, release the IP address assigned to the client host, and delete the information of the corresponding client host in the client host information table.
  • a release module configured to: after receiving the leaving message sent by the client host, release the IP address assigned to the client host, and delete the information of the corresponding client host in the client host information table.
  • the DHCP server can assign a longer lease to the IP address segment.
  • the DHCP Relay assigns a shorter lease to the client host.
  • the user's keep-alive can be implemented, and frequent packet exchange between the DHCP relay and the DHCP server is avoided.
  • the client host and the DHCP relay can renew the IP address and corresponding Network parameters.
  • the DHCP relay determines that the IP address usage time in the DHCP relay reaches the preset lease period, it determines whether there is still information about the client host in the client host information table. If the judgment result is no, the DHCP release is sent to the DHCP server. The message releases all IP addresses stored locally, and if the judgment result is yes, the DHCP server is renewed to allocate a plurality of IP addresses assigned thereto.
  • the foregoing apparatus may further include: a determining module, configured to determine that an IP address usage time in the DHCP relay reaches a preset lease period; and a second determining module, configured to determine whether a client exists in the client host information table The information of the host; if the judgment result is no, the sending module is further configured to send a DHCP release message to the DHCP server to release all the IP addresses stored locally; if the judgment result is yes, the renewal module is set to DHCP. The server renews the leased IP address.
  • the DHCP relay can apply for multiple IP addresses to the DHCP server through one packet exchange, and implement batch application of the IP address and network parameters.
  • the DHCP Relay can assign the IP address obtained from the DHCP server to the client host, which reduces the network traffic between the DHCP Relay and the DHCP Server.
  • the DHCP relay agent and the DHCP server can adopt the relevant authentication mechanism to improve security.
  • the DHCP relay can pre-bind the MAC address and IP address of the client host, and only assign IP addresses to the bound MAC address to improve security. Sex.
  • modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module.
  • the invention is not limited to any specific combination of hardware and software.
  • the above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Abstract

Disclosed are an IP address allocation method and device. The method comprises: after a dynamic host configuration protocol (DHCP) relay receives a first DHCP discovery message, determining whether to acquire Internet Protocol (IP) addresses from a DHCP server; if yes, acquiring multiple IP addresses from the DHCP server and storing the IP addresses; and selecting an IP address from the acquired IP addresses, and allocating the IP address to a client host that transmits the first DHCP detection message. Through the present invention, the network traffic between the DHCP relay and DHCP server in a DHCP network is reduced, and meanwhile, the requirement for the processing capacity of the DHCP server is lowered.

Description

IP地址的分配方法及装置 技术领域 本发明涉及通信领域, 具体而言, 涉及一种 IP地址的分配方法及装置。 背景技术 动态主机配置协议 (Dynamic Host Configure Protocol, 简称为 DHCP), 实现为主 机分配网络协议 (Internet Protocol, 简称为 IP) 地址及其他网络参数, 是一种动态配 置协议。  TECHNICAL FIELD The present invention relates to the field of communications, and in particular to a method and an apparatus for allocating an IP address. A Dynamic Host Configuration Protocol (DHCP) is a dynamic configuration protocol that allocates Internet Protocol (IP) addresses and other network parameters to the host.
DHCP 协议采用客户主机-服务器 (CLIENT-SERVER) 机制, 整个配置过程自动 实现, 所有配置信息由 DHCP服务器 (DHCP Server) 集中控制。 通过配置 IP地址使 用租期, 可以达到 IP地址复用效果。 由于默认情况下, 路由器不会将收到的广播包从一个子网发送到另一个子网。 而 当 DHCP服务器和客户主机不在同一个子网时, 充当客户主机默认网关的路由器必须 将广播包发送到 DHCP服务器所在的子网,这一功能就称为 DHCP中继 (DHCP Relay)。 DHCP Relay实现了 DHCP客户主机 (DHCP Client) 禾 P DHCP服务器 (DHCP Server) 之间的透明交互。 目前, DHCP中继网络一般采用如图 1所示的拓扑方案。 DHCP客户主机经过若 干二层透传网络实现与 DHCP Relay的二层互通, DHCP Relay和 DHCP Server实现三 层路由可达, DHCP报文经过 DHCP Relay时需要重新报文封装。在 DHCP Relay的网 络中, 每当一个 DHCP客户主机上线一次, DHCP Relay就会和 DHCP Server完成一 次 DHCP过程。 图 2是根据相关技术的客户主机 DHCP报文交互的流程图, 如图 2所示, 一个 DHCP客户主机需要通过两次交换完成网络参数的获得,通过一次交互完成续租过程, 通过一次传递完成释放过程。当存在大量 DHCP客户主机上线时, DHCP Relay和 DHCP Server之间的报文数量将非常可观, 占用大量带宽, 增加不必要的网络流量, 并且给 网络带来不安全因素, 同时对 DHCP Server的报文处理能力也是一个很大的挑战。 发明内容 针对相关技术中,在 DHCP中继网络中,每当一个 DHCP客户主机上线一次, DHCP Relay需要与 DHCP Server完成一次 DHCP过程,从而增加 DHCP Relay和 DHCP Server 之间的网络流量的问题, 本发明提供了一种 IP地址的分配方法及装置, 以至少解决上 述问题。 根据本发明的一个实施例, 提供了一种 IP地址的分配方法, 包括: DHCP中继接 收到第一动态主机配置协议 DHCP发现消息后,判断是否需要从 DHCP服务器获取网 络协议 IP地址; 在判断结果为是的情况下, 所述 DHCP中继从所述 DHCP服务器获 取并存储多个 IP地址; 从获取的所述多个 IP地址中选择一个 IP地址分配给发送所述 第一 DHCP发现消息的客户主机。 优选地, 在所述判断结果为否的情况下, 所述方法还包括: 从本地存储的 IP地址 中选择一个 IP地址分配给所述客户主机。 优选地, 判断是否从 DHCP服务器获取网络协议 IP地址包括: 判断所述 DHCP 中继是否存储有未分配给客户主机的 IP地址。 优选地, 在判断结果为是的情况下, 从 DHCP服务器获取多个 IP地址包括: 向所 述 DHCP服务器发送第二 DHCP发现消息; 从所述 DHCP服务器发送的 DHCP响应 消息中获取请求获取所述多个 IP地址。 优选地,从所述 DHCP服务器发送的 DHCP响应消息中获取请求获取所述多个 IP 地址之后,所述方法还包括: 向所述 DHCP服务器发送携带所述多个 IP地址的 DHCP 请求消息; 在所述多个 IP地址与所述 DHCP发送的 IP地址一致的情况下, 接收所述 DHCP服务器发送的 DHCP确认消息。 优选地, 接收所述 DHCP服务器发送的 DHCP确认消息之后, 所述方法还包括: 建立客户主机信息表, 其中, 所述客户主机信息表设置为记录客户主机与为客户主机 分配的 IP地址的对应关系; 接收到客户主机发送的离开报文后, 释放为所述客户主机 分配的 IP 地址, 删除所述客户主机信息表中所述客户主机的信息; 确定所述 DHCP 服务器为所述 DHCP中继分配的所述多个 IP地址的使用时间达到第一预设租期后,判 断所述客户主机信息表中是否还存在有客户主机的信息, 在判断结果为否的情况下, 向所述 DHCP服务器发送 DHCP释放消息, 释放所述多个 IP地址, 在判断结果为是 的情况下, 向所述 DHCP服务器续租所述多个 IP地址。 优选地, 在从获取的所述多个 IP 地址中选择一个 IP 地址分配给发送所述第一 DHCP发现消息的客户主机之后, 所述方法还包括: 在第二预设租期到达时, 判断是 否接收来来自所述客户主机的离开报文, 如果没有, 则向所述客户主机发送通知, 通 知所述客户主机续租从获取的所述多个 IP地址中选择的所述 IP地址, 其中, 所述第 一预设租期大于所述第二预设租期。 根据本发明的另一个实施例, 提供了一种 IP地址的分配装置, 包括: 第一判断模 块, 设置为接收到第一动态主机配置协议 DHCP发现消息后, 判断是否需要从 DHCP 服务器获取网络协议 IP 地址; 获取模块, 设置为在判断结果为是的情况下, 从所述 DHCP服务器获取并存储多个 IP地址; 分配模块, 设置为从获取的所述多个 IP地址 中选择一个 IP地址分配给发送所述第一 DHCP发现消息的客户主机。 优选地, 所述分配模块还设置为: 在所述判断结果为否的情况下, 从本地存储的 IP地址中选择一个 IP地址分配给所述客户主机。 优选地, 所述获取模块包括: 发送单元, 设置为向所述 DHCP 服务器发送第二 DHCP发现消息; 获取单元, 设置为从所述 DHCP服务器发送的 DHCP响应消息中获 取请求获取所述多个 IP地址。 优选地, 所述装置还包括: 发送模块, 设置为向所述 DHCP服务器发送携带所述 多个 IP地址的 DHCP请求消息; 接收模块, 设置为在所述多个 IP地址与所述 DHCP 服务器发送的 IP地址一致的情况下, 接收所述 DHCP服务器发送的 DHCP确认消息。 优选地, 所述装置还包括: 建立模块, 设置为接收到所述 DHCP确认消息后, 建 立客户主机信息表, 其中, 所述客户主机信息表设置为记录客户主机与为客户主机分 配的 IP地址的对应关系; 释放模块, 设置为在接收到客户主机发送的离开报文后, 释 放为所述客户主机分配的 IP地址, 删除所述客户主机信息表中所述客户主机的信息; 确定模块,设置为判断 DHCP中继中的 IP地址使用时间达到预设租期;第二判断模块, 设置为判断所述客户主机信息表中是否还存在有客户主机的信息; 所述发送模块, 还 设置为在所述第二判断模块的判断结果为否的情况下, 向所述 DHCP 服务器发送 DHCP释放消息, 释放本地存储的所有 IP地址; 续租模块, 设置为在所述第二判断模 块的判断结果为是的情况下, 向所述 DHCP服务器续租所述多个 IP地址。 通过本发明, DHCP Relay可以通一次报文交互, 向 DHCP Server申请多个 IP地 址, 实现 IP地址及网络参数的批量申请。 在客户主机上线时, DHCP Relay可以为客 户主机分配从 DHCP Server中获取的 IP地址, 而不必在每一个客户主机上线时都向 DHCP Server申请 IP地址,从而降低了 DHCP Relay与 DHCP Server之间的网络流量。 附图说明 此处所说明的附图用来提供对本发明的进一步理解, 构成本申请的一部分, 本发 明的示意性实施例及其说明用于解释本发明, 并不构成对本发明的不当限定。 在附图 中: 图 1是根据相关技术的 DHCP中继网络的网络拓扑的示意图; 图 2是根据相关技术的客户主机 DHCP报文交互的流程图; 图 3是根据本发明实施例的 IP地址的分配方法的流程图; 图 4是根据本发明优选实施例的 DHCP Relay对 DHCP Discover报文处理方法的 流程图; 图 5是根据本发明优选实施例的 DHCP Server对 DHCP Discover报文处理方法的 流程图; 图 6是根据本发明优选实施例的 DHCP Relay对 DHCP Offer报文处理方法的流程 图; 图 7是根据本发明优选实施例的 DHCP Server对 DHCP Request报文处理方法的 流程图; 图 8是根据本发明优选实施例的 DHCP Relay对 DHCP ACK报文处理方法的流程 图; 图 9是根据本发明优选实施例的 DHCP Relay对 DHCP Release报文处理方法的流 程图; 图 10是根据本发明实施例的 IP地址的分配装置的结构框图; 图 11是根据本发明实施例的一种优选的 IP地址的分配装置的结构框图。 具体实施方式 下文中将参考附图并结合实施例来详细说明本发明。 需要说明的是, 在不冲突的 情况下, 本申请中的实施例及实施例中的特征可以相互组合。 针对相关技术中,在 DHCP中继网络中,每当一个 DHCP客户主机上线一次, DHCP Relay需要与 DHCP Server完成一次 DHCP过程,从而增加 DHCP Relay和 DHCP Server 之间的网络流量的问题, 本发明实施例提供了一种 IP地址的分配方法及装置, 在本发 明实施例中, DHCP Relay可以通过一次报文交互, 向 DHCP Server申请多个 IP地址, 实现 IP地址及网络参数的批量申请。 在客户主机上线时, DHCP Relay可以为客户主 机分配从 DHCP Server中获取的 IP地址, 降低了 DHCP Relay与 DHCP Server之间的 网络流量。 根据本发明实施例, 提供了一种 IP地址的分配方法, 可以但不限于在如图 2所示 的 DHCP中继网络中的 DHCP Relay中实现 DHCP客户主机 IP地址及网络参数的批量 申请。 图 3是根据本发明实施例的 IP地址的分配方法的流程图, 如图 3所示, 该方法可 以包括以下几个步骤 (步骤 S302-步骤 S306)。 步骤 S302, DHCP中继接收到第一动态主机配置协议 (DHCP) 发现消息后, 判 断是否需要从 DHCP服务器获取网络协议 IP地址。 步骤 S304, 在判断结果为是的情况下, DHCP中继从 DHCP服务器获取并存储多 个 IP地址。 步骤 S306, 从获取的多个 IP地址中选择一个 IP地址分配给发送第一 DHCP发现 消息的客户主机。 通过本发明实施例, 接收到 DHCP发现消息后, 首先判断是否需要从 DHCP服务 器获取 IP地址及相应网络参数,在判断结果为是的情况下,从 DHCP服务器获取多个 IP地址, 从获取的多个 IP中选取一个 IP地址及相应网络参数, 分配给请求分配 IP地 址及相应网络参数的客户主机。 同时, 可以保存 DHCP服务器分配的多个 IP地址, 从 而当其他客户主机请求分配 IP地址及相应网络参数时, 可以直接从剩余的 IP地址中 为客户主机分配 IP地址及相应网络参数, 而无需与 DHCP Server进行报文交互, 从而 降低 DHCP Relay与 DHCP Server之间的网络流量, 同时降低对 DHCP Server处理能 力的要求。 下面对上述各个步骤进行描述。 目前, 在 DHCP中继网络中, 客户主机上线时, 可以通过 DHCP过程获取 IP地 址及相应网络参数。 客户主机向 DHCP Relay发送 DHCP发现消息 (DHCP Discover 报文), DHCP Relay接收到 DHCP发现消息后, 对接收到的 DHCP发现消息进行重新 封装, 并向 DHCP Server发送重新封装后的 DHCP发现消息, 请求 DHCP Server分配 IP地址及相应网络参数; DHCP Server接收到重新封装的 DHCP发现消息后, 为客户 主机分配 IP地址及相应网络参数,并向 DHCP Relay发送携带分配的 IP地址及相应网 络参数的 DHCP响应消息 (DHCP OFFER); DHCP Relay接收到 DHCP响应消息后, 将 DHCP Server分配的 IP地址及相应网络参数发送至客户主机,从而客户主机通过分 配的 IP地址及相应网络参数接入网络。 然而, 当存在大量客户主机上线时, DHCP Relay从 DHCP Server分别为每一个上 线的客户主机获取 IP地址及相应网络参数, 从而 DHCP Relay和 DHCP Server之间将 产生大量的报文交互, 从而占用网络带宽, 并且对 DHCP Server的处理能力带来挑战。 为了减少 DHCP Relay与 DHCP Server之间的报文交互, 以降低 DHCP Relay与 DHCP Server之间的网络流量,在本发明实施例中, DHCP Relay可以一次向 DHCP Server申 请多个 IP地址及相应网络参数。 客户主机上线时, DHCP Relay将从 DHCP Server申 请的多个 IP地址中的一个分配给请求 IP地址及相应网络参数的客户主机。 在上述过 程中, DHCP Relay无需与 DHCP Server进行报文交互,从而降低 DHCP Relay与 DHCP Server之间的网络流量, 降低对 DHCP Server处理能力的要求。 此外, 在 DHCP Relay 和 DHCP Server之间可以采用相关认证机制, 提高安全性能。 客户主机上线时,向 DHCP Relay发送 DHCP发现消息(即第一 DHCP发现消息), DHCP Relay接收到客户主机发送的 DHCP发现消息后, 可以判断是否需要从 DHCP 服务器获取 IP地址及相应网络参数, 在需要从 DHCP Server获取 IP地址及相应网络 参数时, 从 DHCP Server获取多个 IP地址及相应网络参数; 在不需要从 DHCP获取 IP地址及相应网络参数时, 从 DHCP Relay中存储的 IP地址中选取一个 IP地址分配 给客户主机。 在实际应用中根据需要, 可以配置 DHCP Relay从 DHCP Server批量申请 IP地址 及相应网络参数的条件, DHCP Relay根据预设条件判断是否需要从 DHCP Server获取 IP地址。 例如, 设置在 DHCP Relay剩余的 IP地址数量的预设阈值, DHCP Relay接 收到客户主机的 DHCP发现消息后, 判断 DHCP Relay中剩余的 IP地址的数量是否小 于预设阈值, 当 DHCP Relay中剩余的 IP地址的数量小于预设阈值时, DHCP Relay 从 DHCP Server中获取多个 IP地址及相应网络参数;当 DHCP Relay中剩余的 IP地址 的数量大于预设阈值时, 可以直接从 DHCP Relay中剩余的 IP地址中为客户主机分配 IP地址及相应网络参数。 或者, 也可以在接收到 DHCP发现消息后, 判断 DHCP Relay中是否存储有 IP地 址。 如果 DHCP Relay中存储有 IP地址, 可以直接从 DHCP Relay中存储的 IP地址中 选取一个 IP地址及相应网络参数,分配给请求网络参数的客户主机;如果 DHCP Relay 中未存储可供客户主机使用的 IP 地址及相应网络参数, DHCP Relay可以从 DHCP Server获取多个 IP地址及相应网络参数, 获取到多个 IP地址后, DHCP Relay从获取 的多个 IP地址中选取一个 IP地址及相应网络参数, 分配给发送 DHCP发现消息的客 户主机, 并且 DHCP Relay可以存储获取的多个 IP地址及网络参数, 在其他客户主机 上线时, 分配给其他客户主机。 进一步地, 还可以设置在 DHCP Relay在接收到 DHCP发现消息后, 判断接收到 DHCP发现消息是否为当前周期中第一次接收到 DHCP发现消息, 即接收到 DHCP发 现消息后,判断 DHCP Relay是否是在每一次批量释放 IP地址之后第一次接收到 DHCP 发现消息, 当 DHCP Relay是第一次接收到 DHCP发现消息, DHCP Relay从 DHCP Server获取多个 IP地址及相应网络参数; 当 DHCP Relay不是第一次接收到 DHCP发 现消息,可以确定 DHCP Relay已经从 DHCP Server中获取到多个 IP地址, DHCP Relay 可以从本地存储的多个 IP地址中选取一个 IP地址及相应网络参数,分配给发送 DHCP 发现消息的客户主机。 如果 DHCP Relay需要从 DHCP Server获取多个 IP地址, DHCP Relay可以对接收 到的 DHCP发现消息进行重新封装,并向 DHCP Server发送重新封装后的 DHCP发现 消息 (第二 DHCP发现消息), 请求 DHCP Server为 DHCP Relay分配多个 IP地址及 相应网络参数, DHCP Server根据实际情况为 DHCP Relay分配 IP地址, 并可以将分 配的 IP及相应网络参数携带在 DHCP响应消息中, 发送至 DHCP Relay; DHCP Relay 接收 DHCP Server发送的 DHCP响应消息,并可以从 DHCP响应消息中获取为其分配 的多个 IP地址及相应的网络参数。 同时, DHCP Relay可以将接收到的 IP地址及相应网络参数发送至 DHCP Server, 例如, 将 IP地址及相应网络参数携带在 DHCP请求消息 (DHCP Request报文) 中, DHCP Server对分配的 IP地址信息进行验证, 验证 DHCP Relay接收到的 IP地址信息 与为其分配的 IP地址信息一致后, 向 DHCP Relay发送 DHCP确认消息 (DHCP ACK 报文), DHCP Relay接收 DHCP Server发送的 DHCP确定消息, 并存储为其分配的 IP 地址及相应网络参数。 在实际应用中, 分配 IP地址的数量可以由 DHCP Relay确定, 也可以由 DHCPThe DHCP protocol adopts the client host-server (CLIENT-SERVER) mechanism, and the entire configuration process is automatically implemented. All configuration information is centrally controlled by the DHCP server (DHCP Server). By configuring the IP address to use the lease, you can achieve the IP address reuse effect. Because by default, the router does not send received broadcast packets from one subnet to another. When the DHCP server and the client host are not in the same subnet, the router acting as the default gateway of the client host must send the broadcast packet to the subnet where the DHCP server is located. This function is called DHCP Relay. The DHCP Relay implements transparent interaction between the DHCP client (DHCP Client) and the DHCP server (DHCP Server). Currently, a DHCP relay network generally adopts a topology scheme as shown in FIG. 1. The DHCP client host communicates with the DHCP relay layer through a Layer 2 transparent transmission network. The DHCP relay agent and the DHCP server implement Layer 3 routing. The DHCP packets need to be re-packaged when they pass through the DHCP relay agent. In the DHCP Relay network, whenever a DHCP client host goes online, the DHCP Relay and the DHCP Server complete a DHCP process. 2 is a flow chart of DHCP packet exchange of a client host according to the related art. As shown in FIG. 2, a DHCP client host needs to complete the network parameter acquisition through two exchanges, complete the renewal process through one interaction, and complete the transfer through one pass. Release process. When a large number of DHCP client hosts come online, the number of packets between the DHCP relay agent and the DHCP server will be very large, occupy a large amount of bandwidth, increase unnecessary network traffic, and bring insecure factors to the network. Document processing capabilities are also a big challenge. SUMMARY OF THE INVENTION In the related art, in a DHCP relay network, whenever a DHCP client host goes online, the DHCP Relay needs to complete a DHCP process with the DHCP server, thereby increasing the network traffic between the DHCP Relay and the DHCP Server. The invention provides a method and an apparatus for allocating an IP address to at least solve the above problems. According to an embodiment of the present invention, a method for allocating an IP address is provided, including: after receiving a first dynamic host configuration protocol DHCP discovery message, the DHCP relay determines whether it is necessary to obtain a network protocol IP address from a DHCP server; If the result is yes, the DHCP relay acquires and stores a plurality of IP addresses from the DHCP server; and selects one of the obtained multiple IP addresses to be allocated to send the first DHCP discovery message. Client host. Preferably, in the case that the determining result is no, the method further includes: selecting an IP address from the locally stored IP addresses and assigning the IP address to the client host. Preferably, determining whether to obtain the network protocol IP address from the DHCP server comprises: determining whether the DHCP relay stores an IP address that is not allocated to the client host. Preferably, if the determination result is yes, acquiring the plurality of IP addresses from the DHCP server includes: sending a second DHCP discovery message to the DHCP server; obtaining a request from the DHCP response message sent by the DHCP server to obtain the Multiple IP addresses. Preferably, after obtaining the request to acquire the multiple IP addresses from the DHCP response message sent by the DHCP server, the method further includes: sending, to the DHCP server, a DHCP request message that carries the multiple IP addresses; When the plurality of IP addresses are consistent with the IP address sent by the DHCP, the DHCP acknowledgement message sent by the DHCP server is received. Preferably, after receiving the DHCP confirmation message sent by the DHCP server, the method further includes: establishing a client host information table, where the client host information table is set to record a correspondence between the client host and an IP address allocated for the client host. After receiving the leaving message sent by the client host, releasing the IP address assigned to the client host, deleting the information of the client host in the client host information table; determining that the DHCP server is the DHCP relay After the allocated time of the plurality of IP addresses reaches the first preset lease period, it is determined whether there is still information of the client host in the client host information table, and if the determination result is no, the DHCP is sent to the DHCP. The server sends a DHCP release message to release the plurality of IP addresses. If the determination result is yes, the plurality of IP addresses are renewed to the DHCP server. Preferably, after selecting one of the obtained multiple IP addresses to be allocated to the client host that sends the first DHCP discovery message, the method further includes: when the second preset lease arrives, determining Receiving a leaving message from the client host, if not, sending a notification to the client host, informing the client host to renew the IP address selected from the obtained plurality of IP addresses, wherein The first preset lease period is greater than the second preset lease period. According to another embodiment of the present invention, an apparatus for allocating an IP address is provided, including: a first determining module, configured to: after receiving the first dynamic host configuration protocol DHCP discovery message, determine whether a network protocol needs to be obtained from a DHCP server An IP address; an obtaining module, configured to acquire and store a plurality of IP addresses from the DHCP server if the determination result is yes; and an allocation module configured to select one IP address allocation from the obtained plurality of IP addresses A client host that sends the first DHCP discovery message. Preferably, the allocating module is further configured to: if the result of the determination is negative, select an IP address from the locally stored IP addresses and assign the IP address to the client host. Preferably, the obtaining module includes: a sending unit, configured to send a second DHCP discovery message to the DHCP server; and an acquiring unit, configured to acquire a request to obtain the multiple IPs from a DHCP response message sent by the DHCP server address. Preferably, the device further includes: a sending module, configured to send a DHCP request message carrying the multiple IP addresses to the DHCP server; and a receiving module, configured to send the multiple IP addresses and the DHCP server If the IP addresses are the same, the DHCP confirmation message sent by the DHCP server is received. Preferably, the device further includes: an establishing module, configured to: after receiving the DHCP acknowledgement message, establish a client host information table, where the client host information table is set to record a client host and an IP address assigned to the client host The release module is configured to release the IP address assigned to the client host after receiving the leaving message sent by the client host, and delete the information of the client host in the client host information table; The setting is to determine that the IP address usage time in the DHCP relay reaches a preset lease period; the second determining module is configured to determine whether there is still information about the client host in the client host information table; the sending module is further configured to If the determination result of the second determining module is negative, sending a DHCP release message to the DHCP server, releasing all locally stored IP addresses; and renewing the module, setting the judgment result in the second determining module In the case of YES, the plurality of IP addresses are renewed to the DHCP server. Through the invention, the DHCP relay can apply for multiple IP addresses to the DHCP server through one packet exchange, and implement batch application of the IP address and network parameters. When the client host goes online, the DHCP relay can assign the IP address obtained from the DHCP server to the client host without having to apply for an IP address to the DHCP server when each client host goes online, thereby reducing the DHCP relay and the DHCP server. Network traffic. BRIEF DESCRIPTION OF THE DRAWINGS The accompanying drawings, which are set to illustrate,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, In the drawings: FIG. 1 is a schematic diagram of a network topology of a DHCP relay network according to the related art; FIG. 2 is a flowchart of DHCP packet interaction of a client host according to the related art; FIG. 3 is an IP address according to an embodiment of the present invention. FIG. 4 is a flowchart of a method for processing a DHCP Discover message by a DHCP relay according to a preferred embodiment of the present invention; FIG. 5 is a flowchart of a method for processing a DHCP Discover message by a DHCP server according to a preferred embodiment of the present invention; FIG. 6 is a flowchart of a method for processing a DHCP Offer message by a DHCP relay according to a preferred embodiment of the present invention; FIG. 7 is a flowchart of a method for processing a DHCP Request message by a DHCP server according to a preferred embodiment of the present invention; 8 is a flowchart of a method for processing a DHCP ACK message by a DHCP relay according to a preferred embodiment of the present invention; FIG. 9 is a flowchart of a method for processing a DHCP Release message by a DHCP Relay according to a preferred embodiment of the present invention; A block diagram of a device for allocating an IP address of an embodiment of the invention; FIG. 11 is a block diagram showing the structure of a device for allocating a preferred IP address according to an embodiment of the present invention. BEST MODE FOR CARRYING OUT THE INVENTION Hereinafter, the present invention will be described in detail with reference to the accompanying drawings. It should be noted that the embodiments in the present application and the features in the embodiments may be combined with each other without conflict. In the related art, in a DHCP relay network, whenever a DHCP client host goes online, the DHCP Relay needs to complete a DHCP process with the DHCP server, thereby increasing the network traffic between the DHCP Relay and the DHCP Server. The example provides a method and a device for allocating an IP address. In the embodiment of the present invention, the DHCP relay can apply for multiple IP addresses to the DHCP server through a packet exchange, and implement batch application of the IP address and network parameters. When the client host goes online, the DHCP Relay can assign the IP address obtained from the DHCP server to the client host, which reduces the network traffic between the DHCP Relay and the DHCP Server. According to the embodiment of the present invention, a method for allocating an IP address is provided, which may be, but is not limited to, a bulk application for implementing a DHCP client host IP address and network parameters in a DHCP Relay in the DHCP relay network as shown in FIG. 2 . FIG. 3 is a flowchart of a method for allocating an IP address according to an embodiment of the present invention. As shown in FIG. 3, the method may include the following steps (step S302-step S306). Step S302: After receiving the first dynamic host configuration protocol (DHCP) discovery message, the DHCP relay determines whether it is necessary to obtain a network protocol IP address from the DHCP server. Step S304, in a case where the determination result is YES, the DHCP relay acquires and stores a plurality of IP addresses from the DHCP server. Step S306, selecting one of the obtained multiple IP addresses to be assigned to the client host that sends the first DHCP discovery message. After receiving the DHCP discovery message, the method first determines whether it is necessary to obtain an IP address and a corresponding network parameter from the DHCP server, and if the judgment result is yes, obtain multiple IP addresses from the DHCP server, and obtain more from the DHCP server. Select one IP address and corresponding network parameters from the IPs, and assign them to the client host requesting the IP address and corresponding network parameters. At the same time, multiple IP addresses allocated by the DHCP server can be saved, so that when other client hosts request to allocate an IP address and corresponding network parameters, the client host can be directly assigned an IP address and corresponding network parameters from the remaining IP addresses without The DHCP server exchanges packets, which reduces network traffic between the DHCP Relay and the DHCP server and reduces the processing power of the DHCP Server. The above various steps are described below. Currently, in a DHCP relay network, when a client host goes online, the IP address and corresponding network parameters can be obtained through a DHCP process. The client host sends a DHCP discovery message to the DHCP Relay (DHCP Discover After receiving the DHCP discovery message, the DHCP Relay re-encapsulates the received DHCP discovery message and sends a re-encapsulated DHCP discovery message to the DHCP server to request the DHCP server to assign an IP address and corresponding network parameters. After receiving the re-encapsulated DHCP discovery message, the client host is assigned an IP address and corresponding network parameters, and sends a DHCP response message (DHCP OFFER) carrying the assigned IP address and corresponding network parameters to the DHCP Relay; the DHCP Relay receives the DHCP response. After the message, the IP address assigned by the DHCP server and the corresponding network parameters are sent to the client host, so that the client host accesses the network through the assigned IP address and corresponding network parameters. However, when a large number of client hosts are online, the DHCP Relay obtains an IP address and corresponding network parameters for each online client from the DHCP server, so that a large number of packet interactions occur between the DHCP Relay and the DHCP server, thereby occupying the network. Bandwidth, and challenges the processing power of the DHCP Server. In the embodiment of the present invention, the DHCP relay can apply for multiple IP addresses and corresponding network parameters to the DHCP server at one time in order to reduce the packet exchange between the DHCP relay and the DHCP server. . When the client host goes online, the DHCP Relay will assign one of the multiple IP addresses requested by the DHCP server to the client host requesting the IP address and corresponding network parameters. During the above process, the DHCP relay does not need to exchange packets with the DHCP server, which reduces the network traffic between the DHCP relay and the DHCP server and reduces the processing requirements of the DHCP server. In addition, a related authentication mechanism can be adopted between the DHCP Relay and the DHCP Server to improve security performance. When the client host goes online, it sends a DHCP discovery message (that is, the first DHCP discovery message) to the DHCP relay. After receiving the DHCP discovery message sent by the client host, the DHCP relay can determine whether it needs to obtain the IP address and corresponding network parameters from the DHCP server. When obtaining the IP address and corresponding network parameters from the DHCP server, obtain multiple IP addresses and corresponding network parameters from the DHCP server. When you do not need to obtain the IP address and corresponding network parameters from DHCP, select from the IP addresses stored in the DHCP Relay. An IP address is assigned to the client host. You can configure the conditions for the DHCP relay to apply for IP addresses and corresponding network parameters from the DHCP server in batches. The DHCP relay determines whether it needs to obtain an IP address from the DHCP server. For example, after the DHCP relay agent receives the DHCP discovery message from the client host, the DHCP relay determines whether the number of remaining IP addresses in the DHCP relay is less than a preset threshold. When the number of IP addresses is less than the preset threshold, the DHCP relay obtains multiple IP addresses and corresponding network parameters from the DHCP server. When the number of remaining IP addresses in the DHCP relay is greater than the preset threshold, the DHCP relay can directly receive the remaining from the DHCP relay. The IP address is assigned to the client host in the IP address and the corresponding network parameters. Alternatively, after receiving the DHCP discovery message, it may be determined whether an IP address is stored in the DHCP Relay. If the DHCP relay stores an IP address, you can directly select an IP address and corresponding network parameters from the IP addresses stored in the DHCP relay, and assign them to the client host that requests the network parameters. If the DHCP relay does not store the client host, The IP address and the corresponding network parameters, the DHCP relay can obtain multiple IP addresses and corresponding network parameters from the DHCP server. After obtaining multiple IP addresses, the DHCP relay selects an IP address and corresponding network parameters from multiple IP addresses obtained. It is assigned to the client host that sends the DHCP discovery message, and the DHCP Relay can store the acquired multiple IP addresses and network parameters, and when other client hosts go online, they are assigned to other client hosts. Further, after receiving the DHCP discovery message, the DHCP relay may determine whether the DHCP discovery message is received for the first time in the current period, that is, after receiving the DHCP discovery message, determine whether the DHCP relay is The DHCP Receive message is received for the first time after each batch release of the IP address. When the DHCP Relay receives the DHCP Discover message for the first time, the DHCP Relay obtains multiple IP addresses and corresponding network parameters from the DHCP server. When the DHCP Relay is not the first Upon receiving the DHCP discovery message, it can be determined that the DHCP relay has obtained multiple IP addresses from the DHCP server. The DHCP relay can select one IP address and corresponding network parameters from multiple IP addresses stored locally, and assign it to send DHCP discovery. The client host of the message. If the DHCP relay needs to obtain multiple IP addresses from the DHCP server, the DHCP relay can re-encapsulate the received DHCP discovery message and send a re-encapsulated DHCP discovery message (second DHCP discovery message) to the DHCP server to request DHCP Server. The DHCP relay assigns multiple IP addresses and corresponding network parameters to the DHCP relay. The DHCP server assigns an IP address to the DHCP relay according to the actual situation. The IP address and corresponding network parameters can be carried in the DHCP response message and sent to the DHCP relay. The DHCP relay receives the DHCP relay. The DHCP response message sent by the DHCP server, and the multiple IP addresses assigned to it and the corresponding network parameters can be obtained from the DHCP response message. At the same time, the DHCP relay can send the received IP address and the corresponding network parameters to the DHCP server. For example, the IP address and the corresponding network parameters are carried in the DHCP request message (DHCP Request message), and the DHCP server allocates the IP address information. After verifying that the IP address information received by the DHCP Relay is consistent with the IP address information assigned to it, the DHCP Relay sends a DHCP acknowledgment message (DHCP ACK message) to the DHCP Relay. The DHCP Relay receives the DHCP acknowledgment message sent by the DHCP server and stores it. The IP address assigned to it and the corresponding network parameters. In practical applications, the number of assigned IP addresses can be determined by the DHCP Relay or by DHCP.
Server确定。 在 DHCP Relay确定分配 IP地址的数量时, DHCP Relay发送的 DHCP 发现消息中可以携带申请分配 IP地址的数量; 在 DHCP Server确定分配 IP地址的数 量时, DHCP Server可以根据 DHCP Relay的情况确定为其分配的 IP地址的数量, 例 如, 根据 DHCP Relay拥有的客户主机数量, 禾口 /或 DHCP Relay的 IP地址申请历史记 录, 以及 DHCP Server中未分配的 IP地址的余量等,确定为 DHCP Relay分配 IP地址 的数量。 在本发明实施例的一个优选实施方式中, DHCP Relay为了管理为其分配的 IP地 址及相应网络参数, 可以建立客户主机信息表, 用来记录客户主机与为该客户主机分 配的 IP地址及相应网络参数的对应关系。 客户主机在离线时, 可以向 DHCP Relay发 送离开报文, DHCP Relay接收到客户主机发送的离开报文后, 释放为客户主机分配的 IP地址, 删除客户主机信息表中相应客户主机的信息。 在其他客户主机上线时, 可将 IP地址再次分配给请求 IP地址及相应网络参数的主机。 为了提高 IP地址的利用率, 可以为已分配的 IP地址设置租期, 优选地, DHCP Server可以为 IP地址段分配一个较长的租期, DHCP Relay为客户主机分配一个较短 租期, 这样可以实现用户的保活, 也避免了 DHCP Relay和 DHCP Server之间的频繁 报文交互。在 IP地址的租期达到时, 客户主机可以向 DHCP Relay续租 IP地址及相应 网络参数, 在 DHCP Server为 IP地址段分配的较长的租期到达时, DHCP Relay也可 以继续向 DHCP Server续租 IP地址及网络参数。 在本发明实施例中, 为了减少 DHCP 中继与 DHCP服务器之间的信令交互, DHCP可以一次性释放 DHCP服务器为该 DHCP 中继分配的多个 IP地址, 例如, 当 DHCP中继确定 DHCP服务器分配的多个 IP地址 (例如, 一个 IP地址段) 的使用时间达到预设租期 (即上述的较长的租期) 时, 判断 客户主机信息表中是否还存在有客户主机的信息,在判断结果为否的情况下,向 DHCP 服务器发送 DHCP释放消息,释放本地存储的所有 IP地址,在判断结果为是的情况下, 向 DHCP服务器续租为其分配的多个 IP地址。 在本发明的一个优选实施例中, DHCP Relay可以利用 DHCP报文中的 Option字 段, 完成 DHCP Relay和 DHCP Server之间 IP地址及相应网络参数的批量申请。 在本发明优选实施例中, 可以利用 DHCP协议的 2个自定义 Option字段, 可以分 别称为 Option-A和 Option-B。 可以在 DHCP Relay做客户主机数分配规划。 例如, 规 划该 DHCP Relay下挂 100个客户主机, 那么当该 DHCP Relay收到第一个 DHCP客 户主机发来的 DHCP Discover报文进行报文重新封装时, 插入 Option-A, Option-A中 含有客户主机数规划信息: 申请 100个 IP地址及相应网络参数。 如图 4所示, 当 DHCP Relay收到 DHCP Discover报文后, 可以判断发送 DHCPServer is ok. When the DHCP relay determines the number of IP addresses to be assigned, the DHCP Discovery message sent by the DHCP relay can carry the number of IP addresses to be applied for; the number of IP addresses assigned by the DHCP server is determined. When the amount is exceeded, the DHCP server can determine the number of IP addresses assigned to it according to the DHCP relay. For example, according to the number of client hosts owned by the DHCP relay, the IP address of the DHCP relay and/or the DHCP relay application history, and the DHCP server. The amount of the assigned IP address, etc., determines the number of IP addresses assigned to the DHCP Relay. In a preferred embodiment of the present invention, the DHCP Relay may establish a client host information table for managing the IP address assigned to the client and the corresponding network parameters, and record the IP address and corresponding address of the client host and the client host. Correspondence of network parameters. When the client host is offline, it can send a Leave message to the DHCP Relay. After receiving the Leave message sent by the client host, the DHCP Relay releases the IP address assigned to the client host and deletes the information of the corresponding client host in the client host information table. When other client hosts are online, the IP address can be reassigned to the host requesting the IP address and corresponding network parameters. To increase the utilization of IP addresses, you can set a lease for the assigned IP address. Preferably, the DHCP server can assign a longer lease to the IP address segment. The DHCP Relay assigns a shorter lease to the client host. The user's keep-alive can be implemented, and frequent packet exchange between the DHCP relay and the DHCP server is avoided. When the lease of the IP address is reached, the client can renew the IP address and corresponding network parameters to the DHCP relay. The DHCP Relay can continue to the DHCP server when the long lease period allocated by the DHCP server for the IP address segment arrives. Rent IP address and network parameters. In the embodiment of the present invention, in order to reduce signaling interaction between the DHCP relay and the DHCP server, the DHCP may release multiple IP addresses allocated by the DHCP server for the DHCP relay at one time, for example, when the DHCP relay determines the DHCP server. When the usage time of multiple IP addresses (for example, an IP address segment) reaches the preset lease period (that is, the longer lease period mentioned above), it is determined whether there is still information about the client host in the client host information table. If the result of the determination is negative, a DHCP release message is sent to the DHCP server, and all IP addresses stored locally are released. If the determination result is YES, the DHCP server is renewed to a plurality of IP addresses assigned thereto. In a preferred embodiment of the present invention, the DHCP relay can use the Option field in the DHCP packet to complete the batch application of the IP address and corresponding network parameters between the DHCP Relay and the DHCP server. In the preferred embodiment of the present invention, two custom Option fields of the DHCP protocol may be used, which may be called Option-A and Option-B, respectively. The DHCP Relay can be used to perform client host number allocation planning. For example, if the DHCP relay agent is configured to connect 100 client hosts, the DHCP relay agent will receive the DHCP Discover message from the first DHCP client to re-encapsulate the packet. Client host number planning information: Apply for 100 IP addresses and corresponding network parameters. As shown in Figure 4, after receiving the DHCP Discover message, the DHCP Relay can determine to send DHCP.
Discover报文的客户主机是否为第一个客户主机,如果是第一个客户主机, DHCP Relay 在对该报文进行重新封装时, 插入 Option-A选项字段, 该字段携带总的用户规划数。 如果该客户主机不是第一个客户主机, 再判断 DHCP Relay申请的 IP地址段是否有剩 余, 如果有, 则 DHCP Relay执行 DHCP Server的功能, 直接向 DHCP客户主机分配 IP地址及网络参数, 如果 DHCP Relay中没有剩余 IP地址, 则可以拒绝该客户主机接 入, 并且给出告警打印。 如图 5所示, 当 DHCP Server收到携带 Option-A的 DHCP Discover报文, 判断 DHCP服务器是否识别 Option-A, 如果该 DHCP Server能够识别 Option-A, 可以解析 Option-A中携带的参数信息 (申请 IP地址及相应网络地址的数量、 DHCP Relay客户 主机规划数等信息)。 如果 DHCP Server能够满足 Option-A中描述的要求, 则可以一 次分配 100个 IP地址,并可以将相关网络参数一起封装到 Option-B中,插入 DHCP Offer 报文, 发送给 DHCP Relay。 如果 DHCP Server中剩余的 IP地址不足 100个, 就需要 特殊处理。 例如, 不为该 DHCP Relay分配 IP地址, 认为这是不正常状态, 并且给出 告警; 或者, 为每一次 DHCP请求, 分配一个 IP地址, 并给出告警; 或者根据 DHCP Server中剩余的 IP地址的数量确定为 DHCP Relay分配的 IP地址的数量。如果该 DHCP Server不支持 Option-A选项, 那么可直接忽略 Option-A选项, 进行普通流程处理, 也 不会在应答报文中插入 Option-B选项。 如图 6所示, 当 DHCP Relay收到 DHCP Offer报文, 判断 DHCP Offer报文是否 携带 Option-B选项, 如果报文携带正确的 Option-B选项, 则建立临时用户表项, 向 DHCP Server发送携带 Option-A选项的 DHCP Request报文, 将 Option-B选项中的信 息复制到 Option-A选项并封装到 DHCP Request报文中。 如果 DHCP Relay收到的 DHCP Offer报文不携带 Option-B选项, 则执行普通 DHCP报文交互流程。 如图 7所示, 当 DHCP Server收到携带 Option-A的 DHCP Request报文, 对比接 收到的 IP地址及相应网络参数与 DHCP Server上建立的临时表项是否一致,如果一致, 则建立本地用户信息, 并发送携带 Option-B的 DHCP ACK报文进行确认。 如果不一 致则拒绝用户接入;当 DHCP Request报文中不含有 Option-A选项,说明是普通 DHCP 流程, 则执行普通 DHCP报文交互。 如图 8所示, 当 DHCP Relay接收到 DHCP ACK报文, 判断是否携带 Option-B选 项,如果携带,则 DHCP Relay建立用户信息表,并向第一个客户主机发送 DHCP ACK 报文。 如果 DHCP Offer报文没有携带 Option-B选项则进行普通报文的交互过程。 当 网络中的客户主机再次发起 DHCP过程获取 IP地址及相应网络参数时, DHCP Relay 可以直接推送 IP地址及相关参数, 充当 DHCP Server的作用, 而无需在 DHCP Relay 禾口 DHCP Server之间进行报文交互。 当已经获得 IP及网络参数的客户主机进行续租时,报文只需在用户和 DHCP Relay 之间完成交互即可。 当 DHCP Relay的地址段租期到期, 可以在 DHCP Relay和 DHCP Server之间完成一个续租流程, 与上述报文交互类似, 在此不做赘述。 如图 9所示, 当 DHCP Relay收到离开报文时, 可以判断是否为最后一个用户。 当该用户为最后一个离开的用户时, DHCP Relay可以进行以下两种方式处理: 1 ) 清 除本地用户信息; 2) 向 DHCP Server发送 DHCP Release消息, 将所有 IP地址释放。 当该用户不是最后一个用户, 则 DHCP Relay无需和 DHCP Server进行报文交互, 只 需在本地清除用户信息即可。 在实际应用中, 还可以在 DHCP Relay对客户主机的媒体接入控制(Media Access Control, 简称为 MAC) 地址和 IP地址进行预先绑定, 只为绑定的 MAC地址分配 IP 地址, 以提高安全性。 通过本发明优选实施例,对 DHCP报文交互进行优化,克服了在大型网络拓扑中, DHCP报文交互数据流量较大, 给 DHCP Server带来较大负担的问题, 并且完全兼容 现有协议标准, 大幅度减少 DHCP报文交互数量, 并在一定程度提高安全性能。 根据本发明实施例, 还提供了一种 IP地址的分配装置, 可以位于 DHCP Relay中 在 DHCP网络中实现为客户主机分配 IP地址及相应网络参数。 图 10是根据本发明实施例的 IP地址的分配装置的结构框图, 如图 10所示, 该装 置可以包括: 第一判断模块 10、获取模块 20和分配模块 30。其中, 第一判断模块 10, 设置为接收到第一 DHCP发现消息(即客户主机发送的 DHCP发现消息)后, 判断是 否需要从 DHCP服务器 (DHCP Server)获取 IP地址; 获取模块 20, 与第一判断模块 10相耦合, 设置为在判断结果为是的情况下, 从 DHCP服务器获取并存储多个 IP地 址; 分配模块 30, 与获取模块 20相耦合, 设置为从获取的多个 IP地址中选择一个 IP 地址分配给发送第一 DHCP发现消息的客户主机。 为了避免增加 DHCP Relay与 DHCP Server之间的网络流量, DHCP Relay可以一 次向 DHCP Server申请多个 IP地址及相应网络参数。 当网络中的客户主机上线时, DHCP Relay可以将从 DHCP Server申请的多个 IP地址中的一个分配给请求 IP地址及 相应网络参数的客户主机。在这个过程中, DHCP Relay无需与 DHCP Server进行报文 交互,从而能够有效地降低 DHCP Relay与 DHCP Server之间的网络流量, 同时 DHCP 无需处理过多的 DHCP报文, 从而降低对 DHCP Server处理能力的要求。 客户主机上线时, 可以向 DHCP Relay发送 DHCP发现消息, DHCP Relay接收到 客户主机发送的 DHCP发现消息后, 第一判断模块 10可以判断是否从 DHCP服务器 获取 IP地址及相应网络参数, 在需要从 DHCP获取 IP地址及相应网络参数时, 获取 模块 20可以从 DHCP Server获取多个 IP地址及相应网络参数; 如果 DHCP Relay不 需要从 DHCP Server获取 IP地址及相应网络参数, 分配模块 30可以从 DHCP Relay 本地存储的 IP地址中选取一个 IP地址, 分配给请求 IP地址及相应网络参数的客户主 机。 在实际应用中根据需要, 可以配置 DHCP Relay从 DHCP Server批量申请 IP地址 及相应网络参数的条件, DHCP Relay根据预设条件判断是否从 DHCP Server获取 IP 地址。 例如, 设置在 DHCP Relay剩余的 IP地址数量的预设阈值, 接收到客户主机的 DHCP发现消息后,第一判断模块 10可以判断 DHCP Relay中剩余的 IP地址的数量是 否小于预设阈值, 当 DHCP Relay中剩余的 IP地址的数量小于预设阈值时, 获取模块 20可以从 DHCP Server中获取多个 IP地址及相应网络参数; 当 DHCP Relay中剩余的 IP地址的数量大于预设阈值时, 分配模块 30可以从 DHCP Relay中剩余的 IP地址中 为客户主机分配一个 IP地址及相应网络参数。 或者, 第一判断模块 10也可以在接收到 DHCP发现消息后, 判断 DHCP Relay中 是否存储有 IP地址。如果 DHCP Relay中存储有可供客户主机使用的 IP地址, 分配模 块 30可以从 DHCP Relay中存储的 IP地址中选取一个 IP地址及相应网络参数, 分配 给请求网络参数的客户主机; 如果 DHCP Relay中未存储 IP地址, 获取模块 20可以 从 DHCP Server获取多个 IP地址及相应网络参数, 获取到多个 IP地址后, 分配模块 30从获取的 IP地址中选取一个 IP地址及相应网络参数, 分配给发送 DHCP发现消息 的客户主机, 并且 DHCP Relay可以存储获取的多个 IP地址及网络参数, 在其他客户 主机上线时, 分配给其他客户主机。 进一步地, 还可以设置在 DHCP Relay在接收到 DHCP发现消息后, 第一判断模 块 10判断接收到 DHCP发现消息是否为第一次接收到 DHCP发现消息, 即接收到 DHCP发现消息后判断 DHCP Relay是否是第一次接收到 DHCP发现消息, 当 DHCP Relay是第一次接收到 DHCP发现消息,获取模块 20可以从 DHCP Server获取多个 IP 地址及相应网络参数; 当 DHCP Relay不是第一次接收到 DHCP发现消息, 可以确定 DHCP Relay已经从 DHCP Server中获取到多个 IP地址,分配模块 30可以从已获取的 多个 IP地址中选取一个 IP地址及相应网络参数, 分配给相应的客户主机。 在获取模块 20可以从 DHCP Server获取多个 IP地址的情况下, DHCP Relay可以 对接收到的 DHCP发现消息进行重新封装,并向 DHCP Server发送重新封装后的 DHCP 发现消息 (称为第二 DHCP发现消息), 请求 DHCP Server为其分配多个 IP地址及相 应网络参数, DHCP Server为 DHCP Relay分配 IP地址, 将分配的 IP及相应网络参数 携带在 DHCP响应消息中发送至 DHCP Relay; DHCP Relay接收 DHCP Server发送的Whether the client host of the Discover message is the first client host. If it is the first client host, DHCP Relay When the packet is re-encapsulated, the Option-A option field is inserted. This field carries the total number of user plans. If the client host is not the first client host, determine whether there is any remaining IP address segment requested by the DHCP relay. If so, the DHCP relay performs the DHCP server function to directly assign the IP address and network parameters to the DHCP client host. If there is no remaining IP address in the relay, the client host can be denied access and an alarm print is given. As shown in Figure 5, when the DHCP server receives the DHCP Discover message carrying Option-A, it determines whether the DHCP server identifies Option-A. If the DHCP server can identify Option-A, it can parse the parameter information carried in Option-A. (Request for IP address and the number of corresponding network addresses, DHCP Relay client host planning number, etc.). If the DHCP server can meet the requirements described in Option-A, you can assign 100 IP addresses at a time. You can also encapsulate the relevant network parameters into Option-B and insert the DHCP Offer packets to the DHCP Relay. If there are less than 100 IP addresses remaining in the DHCP Server, special handling is required. For example, the DHCP relay is not assigned an IP address, it is considered to be in an abnormal state, and an alarm is given; or, for each DHCP request, an IP address is assigned and an alarm is given; or according to the remaining IP address in the DHCP server. The number is determined by the number of IP addresses assigned by the DHCP Relay. If the DHCP server does not support the Option-A option, you can directly ignore the Option-A option, perform normal process processing, and do not insert the Option-B option in the response packet. As shown in Figure 6, when the DHCP Relay receives the DHCP Offer packet, it determines whether the DHCP Offer packet carries the Option-B option. If the packet carries the correct Option-B option, the temporary user entry is created and sent to the DHCP server. The DHCP Request message carrying the Option-A option is copied to the Option-A option and encapsulated in the DHCP Request message. If the DHCP Offer packet received by the DHCP Relay does not carry the Option-B option, the normal DHCP packet exchange process is performed. As shown in Figure 7, when the DHCP server receives the DHCP Request message carrying Option-A, it compares the received IP address and the corresponding network parameters with the temporary entries established on the DHCP server. If they are the same, the local user is established. The information is sent and the DHCP ACK packet carrying Option-B is sent for confirmation. If the packets are inconsistent, the user access is denied. If the DHCP Request message does not contain the Option-A option, the DHCP message is a normal DHCP process. As shown in Figure 8, when the DHCP Relay receives the DHCP ACK packet, it determines whether to carry the Option-B option. If it is carried, the DHCP Relay establishes a user information table and sends a DHCP ACK packet to the first client. If the DHCP Offer message does not carry the Option-B option, the normal packet exchange process is performed. When the client in the network initiates the DHCP process to obtain the IP address and the corresponding network parameters, the DHCP relay can directly push the IP address and related parameters to act as a DHCP server without having to send packets between the DHCP relay and the DHCP server. Interaction. When the client host that has obtained the IP and network parameters renews the lease, the packet only needs to be exchanged between the user and the DHCP relay. When the lease of the DHCP relay agent expires, a process of renewing the lease between the DHCP relay agent and the DHCP server is performed. The interaction with the above-mentioned packets is similar. As shown in Figure 9, when the DHCP Relay receives the Leave message, it can determine whether it is the last user. When the user is the last user to leave, the DHCP relay can perform the following two methods: 1) clear local user information; 2) send a DHCP Release message to the DHCP server to release all IP addresses. When the user is not the last user, the DHCP relay does not need to exchange packets with the DHCP server. You only need to clear the user information locally. In the actual application, the DHCP Relay can pre-bind the Media Access Control (MAC) address and IP address of the client host, and only assign an IP address to the bound MAC address to improve security. Sex. The preferred embodiment of the present invention optimizes the interaction of the DHCP message, and overcomes the problem that the DHCP packet exchange data traffic is large in a large network topology, which brings a large burden to the DHCP server, and is fully compatible with the existing protocol standard. , greatly reducing the number of DHCP message interactions and improving security performance to a certain extent. According to an embodiment of the present invention, an IP address allocation apparatus is further provided, which can be located in a DHCP relay to allocate an IP address and corresponding network parameters to a client host in a DHCP network. FIG. 10 is a structural block diagram of an apparatus for allocating an IP address according to an embodiment of the present invention. As shown in FIG. 10, the apparatus may include: a first determining module 10, an obtaining module 20, and an allocating module 30. The first judging module 10 is configured to: after receiving the first DHCP discovery message (that is, the DHCP discovery message sent by the client host), determine whether it is necessary to obtain an IP address from the DHCP server (DHCP server); the acquiring module 20, and the first The determining module 10 is coupled to be configured to acquire and store a plurality of IP addresses from the DHCP server if the determination result is yes; the assigning module 30 is coupled to the obtaining module 20, and is configured to select from the acquired multiple IP addresses. An IP address is assigned to the client host that sent the first DHCP discovery message. To avoid increasing network traffic between the DHCP Relay and the DHCP Server, the DHCP Relay can apply to the DHCP Server for multiple IP addresses and corresponding network parameters at one time. When the client host in the network goes online, the DHCP Relay can assign one of the multiple IP addresses requested from the DHCP server to the client host requesting the IP address and the corresponding network parameters. In this process, the DHCP relay does not need to exchange packets with the DHCP server, which can effectively reduce the network traffic between the DHCP relay and the DHCP server. At the same time, the DHCP does not need to process excessive DHCP packets, thus reducing the processing capacity of the DHCP server. Requirements. When the client host goes online, it can send a DHCP discovery message to the DHCP relay. After the DHCP relay receives the DHCP discovery message sent by the client host, the first determining module 10 can determine whether to obtain the IP address and the corresponding network parameter from the DHCP server. When obtaining the IP address and the corresponding network parameter, the obtaining module 20 may obtain multiple IP addresses and corresponding network parameters from the DHCP server. If the DHCP relay does not need to obtain an IP address and corresponding network parameters from the DHCP server, the allocation module 30 may be locally from the DHCP relay. An IP address is selected from the stored IP addresses and assigned to the client host requesting the IP address and corresponding network parameters. You can configure the conditions for the DHCP relay to apply for IP addresses and corresponding network parameters from the DHCP server in batches. The DHCP relay determines whether to obtain an IP address from the DHCP server based on the preset conditions. For example, after the DHCP discovery message of the client host is received, the first determining module 10 can determine whether the number of remaining IP addresses in the DHCP relay is less than a preset threshold. When the number of remaining IP addresses in the relay is less than a preset threshold, the obtaining module 20 may obtain multiple IP addresses and corresponding network parameters from the DHCP server. When the number of remaining IP addresses in the DHCP relay is greater than a preset threshold, the allocation module 30 The client host can be assigned an IP address and corresponding network parameters from the remaining IP addresses in the DHCP Relay. Alternatively, after receiving the DHCP discovery message, the first determining module 10 may determine whether an IP address is stored in the DHCP relay. If the DHCP relay stores an IP address that can be used by the client host, the distribution module 30 can select an IP address and corresponding network parameter from the IP address stored in the DHCP relay, and assign it to the client host that requests the network parameter; The IP address is not stored, and the obtaining module 20 can obtain multiple IP addresses and corresponding network parameters from the DHCP server. After obtaining multiple IP addresses, the allocation module 30 selects an IP address and corresponding network parameters from the obtained IP addresses, and assigns them to the IP address. The client host that sends the DHCP discovery message, and the DHCP Relay can store the acquired multiple IP addresses and network parameters, and when other client hosts go online, they are assigned to other client hosts. Further, after the DHCP relay receives the DHCP discovery message, the first determining module 10 determines whether the DHCP discovery message is received for the first time to receive the DHCP discovery message, that is, after receiving the DHCP discovery message, whether the DHCP relay is determined. It is the first time that a DHCP discovery message is received. When the DHCP relay receives the DHCP discovery message for the first time, the obtaining module 20 can obtain multiple IP addresses and corresponding network parameters from the DHCP server; when the DHCP relay is not receiving the DHCP for the first time The discovery message can be determined that the DHCP relay has obtained multiple IP addresses from the DHCP server, and the distribution module 30 can select one IP address and corresponding network parameters from the obtained multiple IP addresses, and allocate them to the corresponding client host. When the obtaining module 20 can obtain multiple IP addresses from the DHCP server, the DHCP Relay can re-encapsulate the received DHCP discovery message and send the re-encapsulated DHCP to the DHCP server. The discovery message (referred to as the second DHCP discovery message) requests the DHCP server to allocate multiple IP addresses and corresponding network parameters, and the DHCP server allocates an IP address to the DHCP Relay, and carries the allocated IP and corresponding network parameters in the DHCP response message. Sent to the DHCP Relay; DHCP Relay receives the DHCP Server
DHCP响应消息, 从中获取为其分配的 IP地址及相应的网络参数。 因此, 在本发明实 施例的一个优选实施方式中, 为了实现上述目的, 获取模块 20可以包括: 发送单元, 设置为向 DHCP服务器发送第二 DHCP发现消息(即重新封装后的 DHCP发现消息); 获取单元, 设置为从 DHCP服务器发送的 DHCP响应消息中获取请求获取多个 IP地 址及相应的网络参数。 同时, DHCP Relay可以将接收到的 IP地址发送至 DHCP服务器, DHCP对分配 的 IP地址信息进行验证, 验证通过后, 例如, 接收到的 IP地址信息与分配的 IP地址 信息一致后, 向 DHCP Relay发送 DHCP确认消息, DHCP Relay接收 DHCP服务器发 送的 DHCP确定消息, 并存储为其分配的 IP地址及相应网络参数。 因此, 在本发明实 施例的一个优选实施方式中, 如图 11所示, 上述装置还可以包括: 发送模块 40, 与 获取模块 20相耦合,设置为向 DHCP服务器发送携带多个 IP地址的 DHCP请求消息; 接收模块 50, 与发送模块 40相耦合, 设置为在多个 IP地址与 DHCP服务器发送的 IP地址一致的情况下,接收 DHCP服务器发送的 DHCP确认消息。通过本优选实施方 式, 可以提高 IP地址分配的可靠性, 保证 IP地址分配的准确性。 在本发明实施例的一个优选实施方式中, DHCP Relay为了管理为其分配的 IP地 址及相应网络参数, 可以建立客户主机信息表, 因此, 上述装置还可以包括: 建立模 块, 设置为接收到 DHCP确认消息后, 建立客户主机信息表, 其中, 客户主机信息表 可以记录客户主机与为客户主机分配的 IP 地址的对应关系。 通过本优选实施方式, DHCP Relay可以方便的对 IP地址进行管理。 客户主机在离线时, 可以向 DHCP Relay发送离开报文, DHCP Relay接收到客户 主机发送的离开报文后, 释放为客户主机分配的 IP地址, 删除客户主机信息表中相应 客户主机的信息。 在其他客户主机上线时, 可将 IP地址在此分配给请求 IP地址及相 应网络参数的主机。 因此, 上述装置还可以包括: 释放模块, 设置为在接收到客户主 机发送的离开报文后, 释放为客户主机分配的 IP地址, 删除客户主机信息表中对应的 客户主机的信息。 为了提高 IP地址的利用率, 可以为已分配的 IP地址设置租期, 优选地, DHCP Server可以为 IP地址段分配一个较长的租期, DHCP Relay为客户主机分配一个较短 租期, 这样可以实现用户的保活, 也避免了 DHCP Relay和 DHCP Server之间的频繁 报文交互。在 IP地址的租期达到时, 客户主机和 DHCP Relay可以续租 IP地址及相应 网络参数。 DHCP中继确定 DHCP中继中的 IP地址使用时间达到预设租期后, 判断 客户主机信息表中是否还存在有客户主机的信息,在判断结果为否的情况下,向 DHCP 服务器发送 DHCP释放消息,释放本地存储的所有 IP地址,在判断结果为是的情况下, 向 DHCP服务器续租为其分配的多个 IP地址。 为了实现上述目的, 上述装置还可以包括: 确定模块, 设置为判断 DHCP中继中 的 IP地址使用时间达到预设租期; 第二判断模块, 设置为判断客户主机信息表中是否 还存在有客户主机的信息; 在判断结果为否的情况下, 发送模块还设置为向 DHCP服 务器发送 DHCP释放消息, 释放本地存储的所有 IP地址; 在判断结果为是的情况下, 续租模块设置为向 DHCP服务器续租为期分配的 IP地址。 从以上的描述中, 可以看出, 本发明实施例实现了如下技术效果: DHCP Relay 可以通过一次报文交互, 向 DHCP Server申请多个 IP地址, 实现 IP地址及网络参数 的批量申请。 在客户主机上线时, DHCP Relay可以为客户主机分配从 DHCP Server 中获取的 IP地址, 降低了 DHCP Relay与 DHCP Server之间的网络流量。同时, DHCP Relay与 DHCP Server之间可以采用相关认证机制,提高安全性;还可以在 DHCP Relay 对客户主机的 MAC和 IP地址进行预先绑定, 只为绑定的 MAC地址分配 IP地址, 提 高安全性。 显然, 本领域的技术人员应该明白, 上述的本发明的各模块或各步骤可以用通用 的计算装置来实现, 它们可以集中在单个的计算装置上, 或者分布在多个计算装置所 组成的网络上, 可选地, 它们可以用计算装置可执行的程序代码来实现, 从而, 可以 将它们存储在存储装置中由计算装置来执行, 并且在某些情况下, 可以以不同于此处 的顺序执行所示出或描述的步骤, 或者将它们分别制作成各个集成电路模块, 或者将 它们中的多个模块或步骤制作成单个集成电路模块来实现。 这样, 本发明不限制于任 何特定的硬件和软件结合。 以上所述仅为本发明的优选实施例而已, 并不用于限制本发明, 对于本领域的技 术人员来说, 本发明可以有各种更改和变化。 凡在本发明的精神和原则之内, 所作的 任何修改、 等同替换、 改进等, 均应包含在本发明的保护范围之内。 The DHCP response message, from which the IP address assigned to it and the corresponding network parameters are obtained. Therefore, in a preferred embodiment of the present invention, in order to achieve the above object, the obtaining module 20 may include: a sending unit, configured to send a second DHCP discovery message (ie, a re-encapsulated DHCP discovery message) to the DHCP server; The obtaining unit is configured to obtain a request for acquiring multiple IP addresses and corresponding network parameters from a DHCP response message sent by the DHCP server. At the same time, the DHCP relay can send the received IP address to the DHCP server, and the DHCP authenticates the assigned IP address information. After the verification is passed, for example, after the received IP address information is consistent with the assigned IP address information, the DHCP Relay is sent to the DHCP Relay. A DHCP acknowledgement message is sent, and the DHCP relay receives the DHCP determination message sent by the DHCP server, and stores the assigned IP address and corresponding network parameters. Therefore, in a preferred embodiment of the present invention, as shown in FIG. 11, the foregoing apparatus may further include: a sending module 40, coupled to the acquiring module 20, configured to send a DHCP carrying multiple IP addresses to the DHCP server. The request message 50 is coupled to the sending module 40 and configured to receive the DHCP acknowledgement message sent by the DHCP server when the multiple IP addresses match the IP address sent by the DHCP server. With the preferred embodiment, the reliability of IP address allocation can be improved, and the accuracy of IP address allocation can be ensured. In a preferred embodiment of the present invention, the DHCP relay may establish a client host information table in order to manage the IP address and corresponding network parameters allocated thereto. Therefore, the foregoing apparatus may further include: an establishing module, configured to receive the DHCP After confirming the message, a client host information table is created, wherein the client host information table can record the correspondence between the client host and the IP address assigned to the client host. Through the preferred embodiment, the DHCP Relay can conveniently manage the IP address. When the client host is offline, it can send a Leave message to the DHCP Relay. After receiving the Leave message sent by the client host, the DHCP Relay releases the IP address assigned to the client host and deletes the information of the corresponding client host in the client host information table. When other client hosts are online, the IP address can be assigned here to the host requesting the IP address and the corresponding network parameters. Therefore, the device may further include: a release module configured to: after receiving the leaving message sent by the client host, release the IP address assigned to the client host, and delete the information of the corresponding client host in the client host information table. To increase the utilization of IP addresses, you can set a lease for the assigned IP address. Preferably, the DHCP server can assign a longer lease to the IP address segment. The DHCP Relay assigns a shorter lease to the client host. The user's keep-alive can be implemented, and frequent packet exchange between the DHCP relay and the DHCP server is avoided. When the lease of the IP address is reached, the client host and the DHCP relay can renew the IP address and corresponding Network parameters. After the DHCP relay determines that the IP address usage time in the DHCP relay reaches the preset lease period, it determines whether there is still information about the client host in the client host information table. If the judgment result is no, the DHCP release is sent to the DHCP server. The message releases all IP addresses stored locally, and if the judgment result is yes, the DHCP server is renewed to allocate a plurality of IP addresses assigned thereto. In order to achieve the above object, the foregoing apparatus may further include: a determining module, configured to determine that an IP address usage time in the DHCP relay reaches a preset lease period; and a second determining module, configured to determine whether a client exists in the client host information table The information of the host; if the judgment result is no, the sending module is further configured to send a DHCP release message to the DHCP server to release all the IP addresses stored locally; if the judgment result is yes, the renewal module is set to DHCP. The server renews the leased IP address. From the above description, it can be seen that the following technical effects are implemented in the embodiment of the present invention: The DHCP relay can apply for multiple IP addresses to the DHCP server through one packet exchange, and implement batch application of the IP address and network parameters. When the client host goes online, the DHCP Relay can assign the IP address obtained from the DHCP server to the client host, which reduces the network traffic between the DHCP Relay and the DHCP Server. At the same time, the DHCP relay agent and the DHCP server can adopt the relevant authentication mechanism to improve security. The DHCP relay can pre-bind the MAC address and IP address of the client host, and only assign IP addresses to the bound MAC address to improve security. Sex. Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein. The steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software. The above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Claims

权 利 要 求 书 Claim
1. 一种 IP地址的分配方法, 包括: 1. A method for allocating an IP address, including:
动态主机配置协议 DHCP中继接收到第一 DHCP发现消息后,判断是否需 要从 DHCP服务器获取网络协议 IP地址;  Dynamic host configuration protocol After receiving the first DHCP discovery message, the DHCP relay determines whether it needs to obtain the network protocol IP address from the DHCP server.
在判断结果为是的情况下,所述 DHCP中继从所述 DHCP服务器获取并存 储多个 IP地址;  In a case where the determination result is yes, the DHCP relay acquires and stores a plurality of IP addresses from the DHCP server;
从获取的所述多个 IP地址中选择一个 IP地址分配给发送所述第一 DHCP 发现消息的客户主机。  Selecting one of the obtained multiple IP addresses is assigned to the client host that sends the first DHCP discovery message.
2. 根据权利要求 1所述的方法, 其中, 在所述判断结果为否的情况下, 所述方法 还包括: 从本地存储的 IP地址中选择一个 IP地址分配给所述客户主机。 2. The method according to claim 1, wherein, in the case that the determination result is negative, the method further comprises: selecting an IP address from the locally stored IP addresses and assigning to the client host.
3. 根据权利要求 1所述的方法, 其中, 判断是否从 DHCP服务器获取网络协议 IP 地址包括: 3. The method according to claim 1, wherein determining whether to obtain a network protocol IP address from a DHCP server comprises:
判断所述 DHCP中继是否存储有未分配给客户主机的 IP地址。  It is determined whether the DHCP relay stores an IP address that is not allocated to the client host.
4. 根据权利要求 1所述的方法, 其中, 在判断结果为是的情况下, 从 DHCP服务 器获取多个 IP地址包括: 4. The method according to claim 1, wherein, in a case where the determination result is yes, obtaining a plurality of IP addresses from the DHCP server includes:
向所述 DHCP服务器发送第二 DHCP发现消息;  Sending a second DHCP discovery message to the DHCP server;
从所述 DHCP服务器发送的 DHCP响应消息中获取请求获取所述多个 IP 地址。  Obtaining a request from the DHCP response message sent by the DHCP server to acquire the plurality of IP addresses.
5. 根据权利要求 4所述的方法, 其中, 从所述 DHCP服务器发送的 DHCP响应消 息中获取请求获取所述多个 IP地址之后, 所述方法还包括: The method according to claim 4, wherein, after obtaining the request for acquiring the plurality of IP addresses from the DHCP response message sent by the DHCP server, the method further includes:
向所述 DHCP服务器发送携带所述多个 IP地址的 DHCP请求消息; 在所述多个 IP地址与所述 DHCP服务器发送的 IP地址一致的情况下, 接 收所述 DHCP服务器发送的 DHCP确认消息。  And sending, by the DHCP server, a DHCP request message that carries the multiple IP addresses; and if the multiple IP addresses are consistent with the IP address sent by the DHCP server, receiving a DHCP confirmation message sent by the DHCP server.
6. 根据权利要求 5所述的方法, 其中, 接收所述 DHCP服务器发送的 DHCP确认 消息之后, 所述方法还包括: The method according to claim 5, wherein, after receiving the DHCP acknowledgement message sent by the DHCP server, the method further includes:
建立客户主机信息表, 其中, 所述客户主机信息表设置为记录客户主机与 为客户主机分配的 IP地址的对应关系; 接收到客户主机发送的离开报文后, 释放为所述客户主机分配的 IP地址, 删除所述客户主机信息表中所述客户主机的信息; Establishing a client host information table, where the client host information table is set to record a correspondence between the client host and an IP address assigned to the client host; After receiving the leaving message sent by the client host, releasing the IP address assigned to the client host, and deleting the information of the client host in the client host information table;
确定所述 DHCP服务器为所述 DHCP中继分配的所述多个 IP地址的使用 时间达到第一预设租期后, 判断所述客户主机信息表中是否还存在有客户主机 的信息,在判断结果为否的情况下,向所述 DHCP服务器发送 DHCP释放消息, 释放所述多个 IP地址, 在判断结果为是的情况下, 向所述 DHCP服务器续租 所述多个 IP地址。  After determining that the usage time of the multiple IP addresses allocated by the DHCP server for the DHCP relay reaches a first preset lease period, determining whether there is still information about the client host in the client host information table, If the result is no, a DHCP release message is sent to the DHCP server to release the plurality of IP addresses. If the determination result is yes, the plurality of IP addresses are renewed to the DHCP server.
7. 根据权利要求 6所述的方法,其中,在从获取的所述多个 IP地址中选择一个 IP 地址分配给发送所述第一 DHCP发现消息的客户主机之后, 所述方法还包括: 在第二预设租期到达时, 判断是否接收来来自所述客户主机的离开报文, 如果没有, 则向所述客户主机发送通知, 通知所述客户主机续租从获取的所述 多个 IP地址中选择的所述 IP地址, 其中, 所述第一预设租期大于所述第二预 设租期。 The method according to claim 6, wherein after selecting one of the plurality of acquired IP addresses to be allocated to the client host that sends the first DHCP discovery message, the method further includes: When the second preset lease arrives, it is determined whether a departure message from the client host is received, and if not, a notification is sent to the client host to notify the client host to renew the obtained multiple IPs from the lease. The IP address selected in the address, where the first preset lease period is greater than the second preset lease period.
8. —种 IP地址的分配装置, 包括: 8. A device for allocating an IP address, comprising:
第一判断模块, 设置为接收到第一动态主机配置协议 DHCP发现消息后, 判断是否需要从 DHCP服务器获取网络协议 IP地址;  The first determining module is configured to: after receiving the first dynamic host configuration protocol DHCP discovery message, determine whether the network protocol IP address needs to be obtained from the DHCP server;
获取模块, 设置为在判断结果为是的情况下, 从所述 DHCP服务器获取并 存储多个 IP地址;  Obtaining a module, configured to acquire and store a plurality of IP addresses from the DHCP server if the determination result is yes;
分配模块, 设置为从获取的所述多个 IP地址中选择一个 IP地址分配给发 送所述第一 DHCP发现消息的客户主机。  And an allocating module, configured to select one of the obtained multiple IP addresses to be assigned to the client host that sends the first DHCP discovery message.
9. 根据权利要求 8所述的装置, 其中, 所述分配模块还设置为: 在所述判断结果 为否的情况下,从本地存储的 IP地址中选择一个 IP地址分配给所述客户主机。 9. The apparatus according to claim 8, wherein the allocating module is further configured to: when the determination result is negative, select an IP address from the locally stored IP addresses and assign the IP address to the client host.
10. 根据权利要求 8所述的装置, 其中, 所述获取模块包括: The device according to claim 8, wherein the obtaining module comprises:
发送单元, 设置为向所述 DHCP服务器发送第二 DHCP发现消息; 获取单元,设置为从所述 DHCP服务器发送的 DHCP响应消息中获取请求 获取所述多个 IP地址。  And a sending unit, configured to send a second DHCP discovery message to the DHCP server, where the acquiring unit is configured to acquire the multiple IP addresses from the DHCP response message sent by the DHCP server.
11. 根据权利要求 10所述的装置, 其中, 所述装置还包括: The device according to claim 10, wherein the device further comprises:
发送模块,设置为向所述 DHCP服务器发送携带所述多个 IP地址的 DHCP 请求消息; 接收模块, 设置为在所述多个 IP地址与所述 DHCP服务器发送的 IP地址 一致的情况下, 接收所述 DHCP服务器发送的 DHCP确认消息。 a sending module, configured to send, to the DHCP server, a DHCP request message that carries the multiple IP addresses; The receiving module is configured to receive a DHCP acknowledgement message sent by the DHCP server if the multiple IP addresses are consistent with the IP address sent by the DHCP server.
12. 根据权利要求 11所述的装置, 其中, 所述装置还包括: 12. The device according to claim 11, wherein the device further comprises:
建立模块, 设置为接收到所述 DHCP确认消息后, 建立客户主机信息表, 其中,所述客户主机信息表设置为记录客户主机与为客户主机分配的 IP地址的 对应关系;  The establishing module is configured to: after receiving the DHCP confirmation message, establish a client host information table, where the client host information table is set to record a correspondence between the client host and an IP address assigned to the client host;
释放模块, 设置为在接收到客户主机发送的离开报文后, 释放为所述客户 主机分配的 IP地址, 删除所述客户主机信息表中所述客户主机的信息;  The release module is configured to: after receiving the leaving message sent by the client host, release the IP address assigned to the client host, and delete the information of the client host in the client host information table;
确定模块, 设置为判断 DHCP中继中的 IP地址使用时间达到预设租期; 第二判断模块, 设置为判断所述客户主机信息表中是否还存在有客户主机 的信息;  The determining module is configured to determine that the IP address usage time in the DHCP relay reaches a preset lease period; the second determining module is configured to determine whether there is still information about the client host in the client host information table;
所述发送模块, 还设置为在所述第二判断模块的判断结果为否的情况下, 向所述 DHCP服务器发送 DHCP释放消息, 释放本地存储的所有 IP地址; 续租模块, 设置为在所述第二判断模块的判断结果为是的情况下, 向所述 DHCP服务器续租所述多个 IP地址。  The sending module is further configured to: when the determination result of the second determining module is negative, send a DHCP release message to the DHCP server, release all locally stored IP addresses; and renew the renting module, set to When the determination result of the second determination module is YES, the plurality of IP addresses are renewed to the DHCP server.
PCT/CN2012/074195 2011-12-01 2012-04-17 Ip address allocation method and device WO2013078814A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110393246.6 2011-12-01
CN2011103932466A CN102413203A (en) 2011-12-01 2011-12-01 IP (Internet Protocol) address allocation method and device

Publications (1)

Publication Number Publication Date
WO2013078814A1 true WO2013078814A1 (en) 2013-06-06

Family

ID=45915045

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/074195 WO2013078814A1 (en) 2011-12-01 2012-04-17 Ip address allocation method and device

Country Status (2)

Country Link
CN (1) CN102413203A (en)
WO (1) WO2013078814A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112118330A (en) * 2020-09-22 2020-12-22 青岛海信传媒网络技术有限公司 DHCP (dynamic host configuration protocol) network reconnection method and display equipment
CN113542446A (en) * 2021-06-11 2021-10-22 杭州玖欣物联科技有限公司 Gateway equipment IP address remote management method based on lwm2m protocol
CN115150361A (en) * 2022-06-06 2022-10-04 北京交通大学 Distributed heterogeneous network equipment address management method

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102413203A (en) * 2011-12-01 2012-04-11 中兴通讯股份有限公司 IP (Internet Protocol) address allocation method and device
CN102685264A (en) * 2012-05-08 2012-09-19 北京星网锐捷网络技术有限公司 Dynamic host configuration protocol address allocation method, relay equipment and server
CN102685270B (en) * 2012-05-25 2015-06-17 杭州华三通信技术有限公司 Method and equipment for distributing dynamic addresses
CN102769678B (en) * 2012-07-23 2015-09-23 杭州华三通信技术有限公司 A kind of dhcp address distribution method and device
CN104618891B (en) * 2013-11-04 2018-10-19 华为终端(东莞)有限公司 A kind of communication means, terminal and core network entity
CN104955025B (en) * 2014-03-29 2018-11-30 华为技术有限公司 A kind of address resource method for releasing and device, system
CN104394014A (en) * 2014-11-20 2015-03-04 浪潮电子信息产业股份有限公司 Method for rapidly generating 10-gigabit network IPs (Internet Protocol) in a batch mode under Linux system
CN106254567A (en) * 2015-06-15 2016-12-21 中兴通讯股份有限公司 A kind of method and apparatus obtaining address
CN106789165A (en) * 2016-11-28 2017-05-31 上海斐讯数据通信技术有限公司 The network configuration system and method for a kind of batch cloud terminal device
CN106713520A (en) * 2016-11-29 2017-05-24 上海斐讯数据通信技术有限公司 Method for configuring network addresses in batches, and terminal management system
EP3609162B1 (en) 2017-04-27 2021-10-27 Huawei Technologies Co., Ltd. Method and terminal for realizing data service
CN107343058B (en) * 2017-07-06 2020-09-04 北京网瑞达科技有限公司 IP address distribution system and working method thereof
CN108600407B (en) * 2018-03-28 2022-03-01 新华三技术有限公司 IP address allocation method, device, equipment and machine readable storage medium
CN109561170B (en) * 2018-12-25 2021-10-08 迈普通信技术股份有限公司 Address pool creating method and device, address pool management system and storage medium
CN115801733A (en) * 2023-02-02 2023-03-14 天翼云科技有限公司 Network address allocation method and device, electronic equipment and readable medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005277937A (en) * 2004-03-25 2005-10-06 Canon Inc Communication method and communication apparatus
CN1949784A (en) * 2005-10-12 2007-04-18 华为技术有限公司 IP address requesting method for DHCP client by DHCP repeater
CN102355404A (en) * 2011-08-09 2012-02-15 北京星网锐捷网络技术有限公司 Method of dynamic multiple network segment address distribution supported by dynamic host configuration protocol (DHCP) repeater and apparatus thereof
CN102413203A (en) * 2011-12-01 2012-04-11 中兴通讯股份有限公司 IP (Internet Protocol) address allocation method and device

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100560744B1 (en) * 2003-09-25 2006-03-13 삼성전자주식회사 Apparatus and method for managing IP address based on DHCP
CN101068208B (en) * 2007-06-05 2010-06-02 华为技术有限公司 Method, system and proxy equipment for dynamic distributing network address
CN101304372B (en) * 2008-06-18 2011-04-13 华为技术有限公司 Method, equipment and system for collocating access control list
CN101534329B (en) * 2009-04-16 2012-05-02 华为技术有限公司 IP address assignment method and system
CN102035724A (en) * 2009-09-30 2011-04-27 华为技术有限公司 Method, device and system for realizing message forwarding
CN101741925A (en) * 2009-12-14 2010-06-16 中兴通讯股份有限公司 Method for allocating access addresses and access equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005277937A (en) * 2004-03-25 2005-10-06 Canon Inc Communication method and communication apparatus
CN1949784A (en) * 2005-10-12 2007-04-18 华为技术有限公司 IP address requesting method for DHCP client by DHCP repeater
CN102355404A (en) * 2011-08-09 2012-02-15 北京星网锐捷网络技术有限公司 Method of dynamic multiple network segment address distribution supported by dynamic host configuration protocol (DHCP) repeater and apparatus thereof
CN102413203A (en) * 2011-12-01 2012-04-11 中兴通讯股份有限公司 IP (Internet Protocol) address allocation method and device

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112118330A (en) * 2020-09-22 2020-12-22 青岛海信传媒网络技术有限公司 DHCP (dynamic host configuration protocol) network reconnection method and display equipment
CN113542446A (en) * 2021-06-11 2021-10-22 杭州玖欣物联科技有限公司 Gateway equipment IP address remote management method based on lwm2m protocol
CN113542446B (en) * 2021-06-11 2023-04-07 杭州玖欣物联科技有限公司 Gateway equipment IP address remote management method based on lwm m protocol
CN115150361A (en) * 2022-06-06 2022-10-04 北京交通大学 Distributed heterogeneous network equipment address management method
CN115150361B (en) * 2022-06-06 2023-08-29 北京交通大学 Address management method for distributed heterogeneous network equipment

Also Published As

Publication number Publication date
CN102413203A (en) 2012-04-11

Similar Documents

Publication Publication Date Title
WO2013078814A1 (en) Ip address allocation method and device
US9143479B2 (en) DHCP proxy in a subscriber environment
US7577146B2 (en) Network element modifying the DHCP lease timer
WO2009089741A1 (en) Method, device and system for selecting service network
WO2013091395A1 (en) Public network address allocation method, device and system
WO2004032421A1 (en) A method for adding devices to management system
WO2013163944A1 (en) Iaas service cloud account sharing method, sharing platform and network device
WO2008138242A1 (en) Management method, apparatus and system of session connection
WO2014015775A1 (en) Ipv6 address stateless auto-configuration system, data card, and implementation method thereof
WO2012079474A1 (en) Address allocation processing method, apparatus, and system
WO2007051407A1 (en) Evolved mobile communication system and a terminal register method thereof
WO2011085586A1 (en) Method, apparatus and network system for tunnel establishment
WO2013097067A1 (en) Method, device and system for realizing communication after virtual machine migration
WO2012051868A1 (en) Firewall policy distribution method, client, access server and system
WO2009089780A1 (en) Method for establishing data connection in mobile network, mobile network and policy control entity
WO2011147074A1 (en) Method, system and corresponding apparatus for implementing policy and charging control
WO2009071009A1 (en) Method for discovering network element devices automatically, device and system
CN112583910B (en) Equipment access method and device of Internet of things platform, electronic equipment and storage medium
WO2012034413A1 (en) Method for dual stack user management and broadband access server
WO2009046666A1 (en) Addressing method of policy decision function entity, network element and network system
WO2011140919A1 (en) Method, device, server and system for accessing service wholesale network
WO2012174914A1 (en) Method and device for controlling address configuration manner
CN103442328B (en) A kind of method for controlling quality of service of internet-of-things terminal and system
WO2010000157A1 (en) Configuration method, device and system for access device
WO2014201600A1 (en) Session management method, address management method and relevant device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 12852647

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 12852647

Country of ref document: EP

Kind code of ref document: A1