Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In order to fix the IP address of the terminal equipment under the fixed port in the home broadband network, the IP address of the terminal equipment can be allocated through TR069(CPE wide area network management protocol). The home gateway user account is used by a user of the home gateway device and is only allowed to log in a private network. The initial password is randomly generated when the home gateway leaves a factory, and is marked on the product identifier, so that the initial password can be changed. The ITMS (management system) manages and maintains the home gateway equipment through TR069, allocates the IP address of the terminal equipment under the fixed port, and the TR069 is a four-layer network management protocol and can complete the automatic discovery, registration and address acquisition of the equipment. At present, China telecom has issued 'China telecom LAN uplink e8-C terminal technical specification', and fixing the IP address of terminal equipment under a fixed port is a mature application of the protocol.
The method has high requirements on the system and the equipment, on one hand, a special management system ITMS is needed, and the software and hardware cost of the whole network is increased; on the other hand, the terminal device is required to support TR 069. This difficulty is even greater for large networks (such as campus networks), where many end devices cannot support the TR069 protocol. In particular, industrial equipment generally only supports simple three-layer interworking and IP address acquisition, cannot support a complicated network management protocol such as TR069, and also does not support login configuration of operation and maintenance personnel.
In order to solve the problem of allocating an IP address of a terminal device under a fixed port in a large network, the prior art provides an IP address allocation method based on a DHCP technique, specifically, a method of inserting DHCP Relay information through an Option of Option 82. A DHCP relay agent is opened on the switch.
The switch adds the Option82 to the tail of the received request message and then relays the request message to the DHCP server. The sub Option 1 (proxy circuit ID) of the DHCP Option82 is default to port information (VLan name plus physical port name) of the switch to which the DHCP client is connected, and the proxy circuit ID may also be configured by the user, and the sub Option 2 (proxy remote ID) of the Option82 is the MAC address of the DHCP relay device itself.
After receiving the DHCP request message forwarded by the switch, the DHCP server allocates an IP address and other information to the DHCP client according to the information carried by the Option in the message and a predetermined strategy, and then sends a response message with DHCP configuration information and Option82 information to the switch for allocating the IP address.
However, in the above method, the fields of Option82 include the switch port, VLAN, and MAC of the switch. It appears that the IP address of the DHCP client under the switch port can be bound. But there is a problem: that is, if the switch can connect multiple DHCP clients under the port, the DHCP server cannot know which DHCP client should be assigned an IP address, how do the other remaining DHCP clients that are not assigned an IP address? The strategy of fixing one IP address under one port of a switch presents a major problem in larger networks (campus networks).
Based on the above research, the present embodiment provides a method and an apparatus for allocating an IP address to solve the above problem.
Fig. 1 is a schematic diagram of a network system to which the IP address assignment method provided in the embodiment of the present application is applied.
The network system includes aDHCP server 10, acore switch 20, anaccess switch 30, and aDHCP client 40. Wherein DHCPserver 10 is connected to a branch network through acore switch 20, whereincore switch 20 may be a three-tier switch. Theaccess switch 30 is connected to thecore switch 20 and theDHCP client 40, and in this embodiment, in order to effectively manage the network, theaccess switch 30 is generally a management-type switch, and a plurality of terminal devices can be connected to theaccess switch 30. The DHCPclient 40 may be a terminal device such as a PC terminal, a mobile terminal (e.g., a mobile phone), and the like.
In the network system, the DHCPclient 40 communicates with the DHCPserver 10 through theaccess switch 30 and thecore switch 20, the DHCPclient 40 sends an IP address request message to the DHCPserver 10, and the DHCPserver 10 allocates an IP address to the DHCPclient 40 after receiving the IP address request message of theDHCP client 40.
Fig. 2 is a schematic block diagram of aDHCP server 10 according to an embodiment of the present disclosure. TheDHCP server 10 includes an IPaddress allocating apparatus 110, amemory 120, and aprocessor 130.
Thememory 120 and theprocessor 130 may be directly or indirectly electrically connected to each other to enable data transmission or interaction. The IP address assignment means 110 comprises at least one computer program or software functional module, which may be stored in thememory 120 in the form of software (software) or firmware (firmware), and theprocessor 130 is configured to execute the executable module stored in thememory 120, such as the IP address assignment means 110 stored in thememory 120.
It should be understood thatDHCP server 10 may also include more or fewer components than shown in fig. 2, and may have a completely different configuration than shown in fig. 2, which is not limited by the present embodiment. The components shown in fig. 2 may be implemented by software, hardware, or a combination thereof. Correspondingly,DHCP server 10 may also be implemented in hardware and/or software.
Fig. 3 is a schematic flowchart of an IP address assignment method applicable to thenetwork system 10 shown in fig. 1 according to an embodiment of the present disclosure. The specific procedures and steps of the method are described in detail below.
In step S301, theaccess switch 30 determines whether the destination port receiving the IP address request packet sent by theDHCP client 40 is a port in which a fixed IP address segment allocation mode is configured in advance.
When theDHCP client 40 first accesses theaccess switch 30, theDHCP client 40 sends an IP address request message to enable theDHCP server 10 to allocate an IP address to the first accessedDHCP client 40, where the first accessedDHCP client 40 may be theDHCP client 40 accessed on a port of theaccess switch 30 which is not originally connected to theDHCP client 40; or on the port of theaccess switch 30 to which theDHCP client 40 was originally connected, the newly accessedDHCP client 40 may be used to replace theDHCP client 40 that has failed on the port.
Theaccess switch 30 may obtain a destination port receiving the IP address request packet according to the received packet, where the destination port may be obtained by identifying according to a source MAC address of the packet or a port of theaccess switch 30 in the packet, and determining the destination port.
In the present embodiment, the IP address configuration modes set by the ports of theaccess switch 30 include a fixed IP address configuration mode and a fixed IP address segment configuration mode. For the same port, the port can only select a configuration mode. The fixed IP address configuration mode is that a specific IP address can be applied under a port, but the IP address is not specified, and theDHCP server 10 determines a specific allocated IP address; the fixed IP address field configuration mode refers to that a specific IP address field can be applied under a port, and the IP address field is specified, such as IP address fields 192.168.100.100-192.168.100.105.
The IP address configuration mode of the setting port can be set in a mode of command line input or a mode of WEB page input. After completing the corresponding configuration of the ports, theaccess switch 30 records the configuration information of each port.
Theaccess switch 30 determines the IP address configuration mode of the destination port according to the configuration information of the destination port receiving the IP address request message sent by theDHCP client 40.
In this embodiment, if theaccess switch 30 detects that the destination port has not set the IP address mode, it directly forwards the IP address request message to theDHCP server 10, and allocates an IP address to the client under the port according to the existing IP address allocation method.
Step S302, if the destination port is configured with a fixed IP address field allocation mode in advance, adding identification information for identifying the fixed IP address field allocation mode in the IP address request message, and sending the processed IP address request message to the DHCP server.
Optionally, in this step, the identification information includes a MAC address of theaccess switch 30, a port number of the destination port, and an IP address application content, where the IP address application content is used to apply for an IP address in the fixed IP address field.
When the destination port is judged to be pre-configured with the fixed IP address segment allocation mode, the MAC address of theaccess switch 30 and the port number of the destination port are added in the IP address request message according to the preset Option requirement.
Specifically, the MAC address of theaccess switch 30 and the port number of the destination port may be encapsulated according to DHCP-allowed protocol fields, where the DHCP-allowed protocol fields include, but are not limited to, Option43, Option82, and the like. After selecting the corresponding Option, filling in the MAC address and the port number of the destination port of theaccess switch 30 according to the requirement of the selected Option, adding the filling content to the IP address request message, and encapsulating the IP address request message.
And adding IP address application content in the encapsulated IP address request message according to a preset Option requirement, and encapsulating the IP address request message again after adding the IP address application content and then sending the encapsulated IP address request message to the DHCP server.
In this embodiment, if the destination port is configured with the fixed IP address configuration mode in advance, when the identification information is added, only the MAC address of theaccess switch 30 and the port number of the destination port are added in the IP address request message according to the preset Option requirement. And encapsulates the IP address request packet added with the MAC address of theaccess switch 30 and the port number of the destination port, and sends the encapsulated IP address request packet to theDHCP server 10.
In this embodiment, the application content of the application IP address field may refer to the table in fig. 4, where the application content of the IP address includes an application type, an address field length, a manner of applying for a fixed IP address field, whether IP addresses in the IP address field are continuous, a start IP address, an end IP address, and the like. Wherein, in the application content of the IP address field, the application type is the application appointed IP address field, and the application type occupies 1 byte; the length of the address field is used for expressing the number of the IP addresses in the application fixed IP address field; in the method of applying for the fixed IP address field, the number 0 can be used to represent the continuity of the IP addresses in the IP address field, the number greater than or equal to 1 represents the number of the IP addresses in the fixed IP address field, and the method of applying for the fixed IP address field occupies 1 byte; the starting IP address and the ending IP address occupy 6 bytes; when the IP addresses in the fixed IP address field are applied to be discontinuous, a part for recording the discontinuous IP addresses is also included between the starting IP address and the ending IP address.
By adding the IP address application content in the IP address request message, when theDHCP server 10 allocates an IP address to theDHCP client 40, an IP address is selected from the IP address application content for allocation, so that when a plurality ofDHCP clients 40 are connected to one port, a fixed IP address is allocated to theDHCP client 40 at the port.
Step S303, theDHCP server 10 allocates an IP address to theDHCP client 40 in a fixed IP address field configuration mode according to the identification information in the received IP address request message.
After receiving the IP address request packet, theDHCP server 10 parses the IP address request packet, and searches whether the IP address request packet includes identification information, and specifically, may check whether the IP address request packet includes a preset Option.
When the preset OPtion is included, the method for judging the IP address configuration mode of the destination port according to the content of the preset OPtion specifically includes: when the Option content only includes the MAC address and the port number of theaccess switch 30, determining that the IP address configuration mode of the destination port is a fixed IP address configuration mode; when the Option content includes the MAC address, the port number, and the IP address application content of theaccess switch 30, it is determined that the IP address configuration mode of the destination port is the fixed IP address segment configuration mode.
In this embodiment, a comparison table of ports and IP addresses of theaccess switch 30 is created in advance in theDHCP server 10, please refer to fig. 5 for a comparison purpose, and the comparison table is used for maintaining the assignment of the IP addresses of theaccess switch 30 and the corresponding ports, where the comparison table includes: the MAC address of theaccess switch 30, the port of theaccess switch 30, and the usage of the IP address recorded under each port.
In this step, the specific step of allocating an IP address to theDHCP client 40 using a fixed IP address segment configuration mode includes:
and sequentially searching the distribution use condition of each IP address in the fixed IP address field in the IP address application content.
When the IP address is searched and allocated for use, the next applied IP address is continuously selected from the applied fixed IP address field to detect the allocation use condition until the last IP address in the applied fixed IP address field, if the IP address applied last is allocated for use, a prompt of IP address allocation failure is returned, and the IP address is not allocated any more.
If there is an IP address not allocated for use in the fixed IP address field, allocating the IP address not allocated for use to theDHCP client 40, and looking up whether the destination port has a record corresponding to the IP address in the lookup table, and if there is no record corresponding to the IP address, adding a record corresponding to the IP address under the destination port of the lookup table.
In this embodiment, if the IP address configuration mode is the fixed IP address mode, an IP address may be allocated to theDHCP client 40 in the following manner.
And searching whether the destination port in the comparison table has a corresponding IP address record.
If an IP address record exists, checking whether the recorded IP address is already allocated for use, and if the recorded IP address is not allocated for use, allocating the IP address to theDHCP client 40; and
if no IP record exists, an idle IP address is allocated to theDHCP client 40, and the destination port and the record table entry of the IP address are added in the comparison table.
In this embodiment, the method further includes the step of updating the lookup table by theDHCP server 10.
And traversing the comparison table to obtain the distribution service condition of each IP address in the comparison table.
And when the IP address is not allocated for use, deleting the corresponding table entry of the IP address which is not allocated for use in the comparison table.
In the table, as theDHCP client 40 connected to the port goes down, the IP address previously allocated to the off-line DHCP client 40 is not actually used any more, and the IP address can be recovered by using a timing check so that the IP address can be used after theDHCP client 40 is replaced. The look-up table can be periodically checked and updated by using a timer in the present embodiment.
According to the IP address allocation method, under the condition that a plurality of DHCP client sides 40 are connected under one port, when the DHCP client sides 40 are in failure, the original IP addresses can be allocated after new DHCP client sides 40 are replaced, the workload of maintenance personnel is reduced, and plug and play of equipment is achieved. Meanwhile, the method adopts the existing functions of the standard protocol, only part of software operation is needed to be added, new hardware is not needed to be added, and the problem of compatibility is not caused.
The embodiment of the present application further provides an IP address allocation method, which is different from the above embodiments in that the scheme of the present application is described from theDHCP server 10 side. It is understood that the specific steps involved in the IP address assignment method to be described next have been described in detail in the corresponding steps of the above embodiment, and the details of the specific respective steps can be described with reference to the above embodiment, and only the IP address assignment method on theDHCP server 10 side will be described briefly below.
Referring to fig. 6, in the present embodiment, the IP address allocation method includes:
step S601, receiving an IP address request message sent by theDHCP client 40, and searching whether the IP address request message includes identification information corresponding to a fixed IP address segment configuration mode, where the identification information includes an MAC address of theaccess switch 30, a port number of a destination port, and an IP address application content.
Step S602, if yes, the fixed IP address segment configuration mode is adopted to allocate an IP address to theDHCP client 40.
In this embodiment, step S602 includes:
sequentially searching the distribution use condition of each IP address in the applied fixed IP address field;
when the fixed IP address field has an IP address that is not allocated for use, the IP address that is not allocated for use is allocated to theDHCP client 40, and whether the destination port has a record of the IP address in a comparison table of an access switch port and an IP address is searched for, and when there is no record of the IP address, the record of the IP address is added under the destination port of the comparison table.
In this embodiment, the method may further include a step of updating the lookup table, where the step includes:
traversing the comparison table to obtain the distribution use condition of each IP address in the comparison table;
and when the IP address is not allocated for use, deleting the corresponding table entry of the IP address which is not allocated for use in the comparison table.
The embodiment of the present application further provides an IP address allocation method, which is different from the above embodiments in that the present application is described from theaccess switch 30 side. It is understood that the specific steps involved in the IP address assignment method to be described next have been described in detail in the corresponding steps of the above embodiment, and the detailed contents of the specific steps can be described with reference to the above embodiment, and only the IP address assignment method on theaccess switch 30 side is briefly described below.
Referring to fig. 7, in the present embodiment, the IP address allocation method includes:
step S701, determining whether the destination port receiving the IP address request packet sent by theDHCP client 40 is a port in which a fixed IP address segment allocation mode is pre-configured.
Step S702, if yes, add identification information for identifying the fixed IP address segment configuration mode in the IP address request message, and send the processed IP address request message to theDHCP server 10, so that theDHCP server 10 allocates an IP address to theDHCP client 40 using the fixed IP address segment configuration mode according to the identification information in the received IP address request message.
In this embodiment, step S702 may include:
adding the MAC address of theaccess switch 30 and the port number of the destination port in the IP address request packet according to a preset Option requirement;
packaging the IP address request message according to a fixed IP address end configuration mode preset by the destination port;
adding an IP address application content in the encapsulated IP address request message, and sending the IP address request message to theDHCP server 10 after the IP address application content is added and the IP address request message is encapsulated again, wherein the IP address application content is used for applying for an IP address in a fixed IP address section, and the identification information comprises an MAC address of theaccess switch 30, a port number of a destination port and the IP address application content.
The embodiment of the present application further provides an IP address allocation apparatus, and the IP address allocation apparatus describes the scheme of the present application from theDHCP server 10 side. It is to be understood that the specific functions of the respective functional blocks involved in the IP address assignment device to be described next have been described in detail in the corresponding steps of the above embodiments, and the detailed contents of the specific respective functional blocks can be described with reference to the above embodiments, and only the IP address assignment device will be described briefly below.
Referring to fig. 8, the IPaddress allocating apparatus 110 provided in this embodiment may include:
the searchingmodule 111 is configured to receive an IP address request packet sent by theDHCP client 40, and search whether the IP address request packet includes identification information corresponding to a fixed IP address segment configuration mode, where the identification information includes an MAC address of theaccess switch 30, a port number of a destination port, and an IP address application content.
The allocatingmodule 112 is configured to, when the identification information corresponding to the fixed IP address field configuration mode is included, allocate an IP address to the DHCP client using the fixed IP address field configuration mode.
In this embodiment, the allocatingmodule 112 is specifically configured to:
sequentially searching the distribution use condition of each IP address in the applied fixed IP address field;
when the fixed IP address field has an IP address that is not allocated for use, the IP address that is not allocated for use is allocated to theDHCP client 40, and whether the destination port has a record of the IP address in a comparison table of an access switch port and an IP address is searched for, and when there is no record of the IP address, the record of the IP address is added under the destination port of the comparison table.
Referring to fig. 9, the IPaddress allocating apparatus 110 may further include an obtainingmodule 113 and a deletingmodule 114.
An obtainingmodule 113, configured to traverse the comparison table, and obtain an allocation usage of each IP address in the comparison table.
And the deletingmodule 114 is configured to delete the entry corresponding to the IP address that is not allocated for use in the lookup table when the IP address is not allocated for use.
To sum up, the embodiment of the present application provides an IP address allocation method and apparatus, where an access switch determines whether a destination port receiving an IP address request packet sent by a DHCP client is a port with a pre-configured fixed IP address segment allocation mode; if so, adding identification information for identifying the configuration mode of the fixed IP address field in an IP address request message, and sending the processed IP address request message to a DHCP server; and the DHCP server allocates an IP address for the DHCP client by adopting a fixed IP address field configuration mode according to the identification information in the received IP address request message. According to the method, when the equipment connected with the port configured with the fixed IP address field distribution mode is in fault and other equipment is adopted to replace the fault equipment on the port, the newly accessed equipment can be accessed into the network by adopting the fixed IP address configured for the port, so that the plug and play of the newly accessed equipment can be realized, the redeployment caused by the fault of the terminal equipment in the network can be reduced, and the workload of operation and maintenance personnel can be reduced.
In the embodiments provided in the present application, it should be understood that the disclosed method and apparatus can be implemented in other ways. The method and apparatus embodiments described above are merely illustrative, for example, the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of methods, apparatus, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.