CN111427662B - IP address allocation method of virtual machine, terminal equipment and DHCP server - Google Patents

IP address allocation method of virtual machine, terminal equipment and DHCP server Download PDF

Info

Publication number
CN111427662B
CN111427662B CN202010211872.8A CN202010211872A CN111427662B CN 111427662 B CN111427662 B CN 111427662B CN 202010211872 A CN202010211872 A CN 202010211872A CN 111427662 B CN111427662 B CN 111427662B
Authority
CN
China
Prior art keywords
address
virtual machine
mac address
virtual
configuration information
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202010211872.8A
Other languages
Chinese (zh)
Other versions
CN111427662A (en
Inventor
胡营
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sangfor Technologies Co Ltd
Original Assignee
Sangfor Technologies Co Ltd
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 Sangfor Technologies Co Ltd filed Critical Sangfor Technologies Co Ltd
Priority to CN202010211872.8A priority Critical patent/CN111427662B/en
Publication of CN111427662A publication Critical patent/CN111427662A/en
Application granted granted Critical
Publication of CN111427662B publication Critical patent/CN111427662B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects

Abstract

The invention discloses a method for distributing IP addresses of virtual machines, which comprises the following steps: after a virtual machine is started, configuration information of the virtual machine in a host is obtained, wherein when the host creates the virtual machine, an MAC address of the virtual machine is obtained, an IP address is allocated to the virtual machine, and the allocated IP address and the MAC address are associated and stored in the configuration information; acquiring the association relation between the MAC address and the IP address of the virtual machine according to the configuration information; and writing the MAC address and the IP address into a virtual network card of the virtual machine. The invention also discloses a terminal device and a DHCP server. According to the invention, under the condition that the DHCP client is not installed, the mapping relation between the DUID, IAID, MAC address and the IP address is not required to be maintained, and the association of the MAC address and the IP address can be realized only by writing the MAC address and the IP address into the configuration information of the virtual machine, so that the realization logic of the virtual private cloud can be effectively reduced, and the method has the advantages of simplicity in realization and high efficiency.

Description

IP address allocation method of virtual machine, terminal equipment and DHCP server
Technical Field
The present invention relates to the field of information processing technologies, and in particular, to a method for allocating an IP address of a virtual machine, a terminal device, and a DHCP server.
Background
The virtual private cloud can manage the IP address (Internet Protocol Address ) and MAC address (Media Access Control Address, media access address) of the virtual machine, but in the prior art, the virtual private cloud needs to store the mapping relationship between the DUID (DHCP Unique Identifier ), IAID (Interface Unique Identifier interface identifier), MAC address and IP address of the virtual machine, and then issues the IP address to the virtual machine through a DHCP (Dynamic Host Configuration Protocol ) server, so that the IP address can be obtained, which has a problem of complex implementation.
The foregoing is provided merely for the purpose of facilitating understanding of the technical solutions of the present invention and is not intended to represent an admission that the foregoing is prior art.
Disclosure of Invention
The embodiment of the invention mainly aims to provide a method for distributing IP addresses of virtual machines, which aims to solve the technical problems that in the prior art, an IP address can be obtained only by issuing the IP address to the virtual machines through a DHCP server, and the implementation is complex.
In order to solve the above problems, an embodiment of the present invention provides a method for allocating IP addresses of virtual machines, including the following contents:
after a virtual machine is started, configuration information of the virtual machine in a host is obtained, wherein when the host creates the virtual machine, an MAC address of the virtual machine is obtained, an IP address is allocated to the virtual machine, and the allocated IP address and the MAC address are associated and stored in the configuration information;
acquiring the association relation between the MAC address and the IP address of the virtual machine according to the configuration information;
and writing the MAC address and the IP address into a virtual network card of the virtual machine.
The step of obtaining the configuration information of the virtual machine in the host comprises the following steps:
and running a preset reading plug-in to acquire configuration information of the virtual machine in the host through the reading plug-in.
The method for distributing the IP addresses of the virtual machines further comprises the following steps:
after the virtual machine is started, judging whether a reading plug-in is installed in the virtual machine or not;
when a reading plug-in is installed, the reading plug-in is operated to execute the step of acquiring the configuration information of the virtual machine in the host;
when the reading plug-in is not installed, sending an acquisition request of an IP address to a DHCP server, so that the DHCP server returns the IP address to the virtual machine according to the acquisition request;
and writing the IP address returned by the DHCP server and the MAC address association of the virtual machine into a virtual network card of the virtual machine.
After the step of writing the MAC address and the IP address into the virtual network card of the virtual machine, the method for allocating the IP address of the virtual machine further includes:
after the configuration information is detected to be updated, acquiring an IP address in the updated configuration information;
deleting the IP address and the MAC address of the virtual network card when the IP address in the updated configuration information is different from the IP address of the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
After the step of writing the MAC address and the IP address into the virtual network card of the virtual machine, the method for allocating the IP address of the virtual machine further includes:
after receiving the update information of the IP address sent by the host, acquiring the updated IP address in the configuration information;
deleting the IP address and the MAC address written in the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
The method for distributing the IP addresses of the virtual machines comprises the following steps:
after receiving an acquisition request of an IP address sent by a virtual machine, a DHCP server acquires a corresponding identification code according to the acquisition request;
acquiring an IP address associated with the MAC address of the virtual machine according to the identification code;
and when the IP address associated with the MAC address is acquired, returning the IP address to the virtual machine.
After the step of obtaining the IP address associated with the MAC address of the virtual machine according to the identification code, the method further includes:
when the IP address associated with the MAC address is not acquired, distributing the IP address in an idle state to the virtual machine;
and returning the IP address to the virtual machine.
After the step of assigning the IP address in the idle state to the virtual machine, the method further includes:
updating the state of the IP address to be a non-idle state, and establishing the association relation between the IP address and the MAC address.
In addition, in order to solve the above-mentioned problem, an embodiment of the present invention further provides a terminal device, where the terminal device includes a processor, a memory, and an allocation program of an IP address of a virtual machine stored on the memory and executable on the processor, and the allocation program of the IP address of the virtual machine implements the steps of the allocation method of the IP address of the virtual machine as described above when executed by the processor.
The embodiment of the invention also provides a DHCP server, which comprises a processor, a memory and an allocation program of the IP address of the virtual machine, wherein the allocation program of the IP address of the virtual machine is stored on the memory and can run on the processor, and the allocation program of the IP address of the virtual machine realizes the steps of the allocation method of the IP address of the virtual machine when being executed by the processor.
According to the method for distributing the IP addresses of the virtual machines, provided by the embodiment of the invention, the configuration information of the virtual machines on the host is obtained, the MAC addresses and the associated IP addresses of the virtual machines in the configuration information are read, the MAC addresses and the IP addresses are written into the virtual network card, a DHCP client is not required to be installed, the mapping relation between DUID, IAID, MAC addresses and the IP addresses is not required to be maintained, the association between the MAC addresses and the IP addresses can be realized only by writing the MAC addresses and the IP addresses into the configuration information of the virtual machines, the realization logic of the virtual private cloud can be effectively reduced, and the method has the advantages of simplicity in realization and high efficiency.
Drawings
FIG. 1 is a schematic diagram of a terminal structure of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a method for assigning IP addresses of virtual machines according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of a method for assigning IP addresses of virtual machines according to the present invention;
FIG. 4 is a flowchart illustrating a third embodiment of a method for assigning IP addresses of virtual machines according to the present invention;
fig. 5 is a flowchart of a fourth embodiment of a method for assigning IP addresses to virtual machines according to the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the detailed description is presented by way of example only and is not intended to limit the invention.
The main solutions of the embodiments of the present invention are: after a virtual machine is started, configuration information of the virtual machine in a host is obtained, wherein when the host creates the virtual machine, an MAC address of the virtual machine is obtained, an IP address is allocated to the virtual machine, and the allocated IP address and the MAC address are associated and stored in the configuration information; acquiring the association relation between the MAC address and the IP address of the virtual machine according to the configuration information; and writing the MAC address and the IP address into a virtual network card of the virtual machine.
In the prior art, the IP address can be obtained only by sending the IP address to the virtual machine through the DHCP server, so that the technical problem of complex realization exists.
The embodiment of the invention provides a solution, by acquiring the configuration information of the virtual machine on the host, reading the MAC address and the associated IP address of the virtual machine in the configuration information, writing the MAC address and the IP address into the virtual network card, and the embodiment of the invention can realize the association of the MAC address and the IP address by writing the MAC address and the IP address into the configuration information of the virtual machine without installing a DHCP client or maintaining the mapping relation between the DUID, IAID, MAC address and the IP address, thereby effectively reducing the realization logic of the virtual private cloud and having the advantages of simple realization and high efficiency.
As shown in fig. 1, fig. 1 is a schematic diagram of a terminal structure of a hardware running environment according to an embodiment of the present invention.
The execution body of the embodiment of the invention can be a desktop computer, a portable computer and other non-movable or movable terminal equipment.
As shown in fig. 1, the terminal device may include: a processor 1001, such as a CPU, a communication bus 1002, a memory 1003, and a network communication interface 1004. Wherein the communication bus 1002 is used to enable connected communication between the components. The memory 1003 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1003 may alternatively be a storage device separate from the aforementioned processor 1001. The network communication interface 1004 may include a standard wired interface, a wireless interface.
It will be appreciated by those skilled in the art that the structure of the terminal device shown in fig. 1 does not constitute a limitation of the terminal, and may include more or less components than illustrated, or may combine certain components, or may be arranged in different components.
As shown in fig. 1, a memory 1003 as a kind of computer storage medium may include an operating system and an allocation program of IP addresses of virtual machines, and a processor 1001 may be used to call the allocation program of IP addresses of virtual machines stored in the memory 1003 and perform the steps of:
after a virtual machine is started, configuration information of the virtual machine in a host is obtained, wherein when the host creates the virtual machine, an MAC address of the virtual machine is obtained, an IP address is allocated to the virtual machine, and the allocated IP address and the MAC address are associated and stored in the configuration information;
acquiring the association relation between the MAC address and the IP address of the virtual machine according to the configuration information;
and writing the MAC address and the IP address into a virtual network card of the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
and running a preset reading plug-in to acquire configuration information of the virtual machine in the host through the reading plug-in.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
after the virtual machine is started, judging whether a reading plug-in is installed in the virtual machine or not;
when a reading plug-in is installed, the reading plug-in is operated to execute the step of acquiring the configuration information of the virtual machine in the host;
when the reading plug-in is not installed, sending an acquisition request of an IP address to a DHCP server, so that the DHCP server returns the IP address to the virtual machine according to the acquisition request;
and writing the IP address returned by the DHCP server and the MAC address association of the virtual machine into a virtual network card of the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
after the configuration information is detected to be updated, acquiring an IP address in the updated configuration information;
deleting the IP address and the MAC address of the virtual network card when the IP address in the updated configuration information is different from the IP address of the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
after receiving the update information of the IP address sent by the host, acquiring the updated IP address in the configuration information;
deleting the IP address and the MAC address written in the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
after receiving an acquisition request of an IP address sent by a virtual machine, a DHCP server acquires a corresponding identification code according to the acquisition request;
acquiring an IP address associated with the MAC address of the virtual machine according to the identification code;
and when the IP address associated with the MAC address is acquired, returning the IP address to the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
when the IP address associated with the MAC address is not acquired, distributing the IP address in an idle state to the virtual machine;
and returning the IP address to the virtual machine.
Further, the processor 1001 may be configured to call an allocation program of an IP address of the virtual machine stored in the memory 1003, and perform the following steps:
updating the state of the IP address to be a non-idle state, and establishing the association relation between the IP address and the MAC address.
Based on the above-mentioned structure of the terminal, a first embodiment of the present invention is provided, referring to fig. 2, fig. 2 is a flow chart of a first embodiment of a method for assigning an IP address of a virtual machine according to the present invention, where the method for assigning an IP address of a virtual machine includes the following steps:
step S10, after a virtual machine is started, configuration information of the virtual machine in a host is obtained, wherein when the host creates the virtual machine, an MAC address of the virtual machine is obtained, an IP address is allocated to the virtual machine, and the allocated IP address and the MAC address are associated and stored in the configuration information;
step S20, acquiring the association relationship between the MAC address and the IP address of the virtual machine according to the configuration information;
currently, the IP address of a virtual machine is generally managed through a VPC (Virtual Private Cloud ), which needs to be guaranteed to be only allocated to the virtual machine, and this needs to maintain the binding relationship between the virtual machine and the IP address. The network address of the virtual machine is the MAC address on the network card of the virtual machine, and the binding relation between the virtual machine and the IP address is the binding relation between the MAC address and the IP address. The VPC is configured with a DHCP server, and IP addresses are distributed through the DHCP server.
The binding relation between the MAC address and the IP address needs to install a DHCP client on the virtual machine, wherein the DHCP client obtains the IP address from the DHCP server through the DUID and the IAID as device marks, and therefore one-to-one mapping between the MAC address and the DUID and the IAID is achieved. A set of mapping tables of MAC addresses and DUIDs, IAIDs are stored on the VPC. After receiving information of creating a virtual machine by a host, the VPC firstly issues a binding record of an IP address and an MAC address; after the host creates the virtual machine, the VPC may acquire the DUID corresponding to the virtual machine from the DHCP client, and then issue a binding record of the IP address, the DUID, and the IAID, so that the virtual machine can be allocated to an IP address. Meanwhile, a set of mapping relations between the MAC address and the IP address and the DUID and IAID are established on the VPC. When the DUID of the virtual machine changes, the relation between the MAC address and the DUID needs to be updated in real time, and the problems of complex realization and high maintenance difficulty are solved.
In this embodiment, when the host creates the virtual machine, a new virtual network card is configured for the virtual machine, and the MAC address of the virtual network card is generated according to a random algorithm. The virtual machine may use the MAC address to exchange packets during communication.
The MAC address may be used to define the location of the devices in the network and is typically unique, i.e., each device has a proprietary MAC address, one for each network card device. The MAC address consists of 48 bits long, consisting of 12 bits of 16-ary digits.
After acquiring the MAC address of the virtual machine, the host needs to apply for an idle IP address from the IP pool of the VPC (Virtual Private Cloud ), allocate the acquired IP address to the virtual machine, and store the IP address and the MAC address in the configuration information of the virtual machine.
Alternatively, the IP address may be an IPv6 address. The IPv6 address has a length of 128 bits, expressed in hexadecimal.
The VPC may be a block of logical isolation area built by the cloud server, where virtual network environments may be configured, address ranges may be selected, subnets created, IP addresses assigned, routing tables configured, gateways, and so on.
Optionally, when receiving an application instruction for creating a virtual machine by the host, the VPC presets an IP address in an idle state from the IP pool to the virtual machine, and stores a binding relationship between the MAC address and the IP address in a database of the VPC.
In this embodiment, the execution body is a virtual machine. After the virtual machine is started, configuration information can be obtained from the host, and the MAC address in the configuration information and the IP address associated with the MAC address can be read.
Optionally, obtaining configuration information of the virtual machine in the host includes:
and running a preset reading plug-in to acquire configuration information of the virtual machine in the host through the reading plug-in.
The preset read plug-in may be VMtools in VMware. The reading plug-in is a service for loading the virtual machine, can read configuration information of the virtual machine in the host, and can read a MAC address in the configuration information and an IP address associated with the MAC address.
And step S30, writing the MAC address and the IP address into a virtual network card of the virtual machine.
After the virtual machine reads the MAC address and the IP address in the configuration information, the MAC address and the IP address are written into the virtual network card of the virtual machine, so that the virtual machine can perform network communication.
Optionally, after the step of writing the MAC address and the IP address into the virtual network card of the virtual machine, the method further includes:
after the configuration information is detected to be updated, acquiring an IP address in the updated configuration information;
deleting the IP address and the MAC address of the virtual network card when the IP address in the updated configuration information is different from the IP address of the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
The virtual machine can detect whether the configuration information of the virtual machine in the host is updated in real time or at regular time, acquire the updated configuration information after detecting the update of the configuration information, and read the IP address in the updated configuration information.
The virtual machine can compare the IP address in the updated configuration information with the IP address written in the virtual network card of the virtual machine, and delete the IP address and the MAC address of the virtual network card when the IP address in the updated configuration information is different from the IP address in the virtual network card. The virtual machine can rewrite the IP address and the MAC address in the updated configuration information into a virtual network card of the virtual machine. Note that the MAC address of the virtual machine is fixed.
The virtual machine can detect the update condition of the configuration information of the virtual machine in the host, after the configuration information is updated, the configuration in the virtual machine is updated, and the configuration information is kept consistent with the configuration information of the virtual machine in the host in time, so that the beneficial effects of delaying communication or communication faults can be effectively avoided.
Optionally, after the step of writing the MAC address and the IP address into the virtual network card of the virtual machine, the method further includes:
after receiving the update information of the IP address sent by the host, acquiring the updated IP address in the configuration information;
deleting the IP address and the MAC address written in the virtual network card;
and writing the MAC address and the updated IP address into the virtual network card.
After modifying the IP address, the host may send update information of the IP address to the virtual machine, where the update information of the IP address may include the updated IP address and an update hint. The virtual machine can acquire the updated IP address in the configuration information according to the update information, delete the IP address and the MAC address written in the virtual network card, and write the MAC address and the updated IP address in the virtual network card in an associated manner.
After the virtual machine receives the update information of the IP address sent by the host, the updated IP address is written into the virtual network card, and the available network card is used for network communication in time, so that the beneficial effects of communication faults can be effectively avoided.
In this embodiment, by acquiring configuration information of a virtual machine on a host, reading an MAC address and an associated IP address of the virtual machine in the configuration information, writing the MAC address and the IP address into a virtual network card, without installing a DHCP client or maintaining a mapping relationship between a DUID, IAID, MAC address and an IP address, association between the MAC address and the IP address can be achieved by writing the MAC address and the IP address into the configuration information of the virtual machine, and thus, the implementation logic of the virtual private cloud can be effectively reduced, and the method has the advantages of simple implementation and high efficiency.
Referring to fig. 3, fig. 3 is a flowchart of a second embodiment of a method for allocating an IP address of a virtual machine according to the present invention, based on the first embodiment, the method for allocating an IP address of a virtual machine further includes:
step S40, judging whether a reading plug-in is installed in the virtual machine after the virtual machine is started;
step S50, when a reading plug-in is installed, the reading plug-in is operated to execute the step of acquiring the configuration information of the virtual machine in the host;
after the virtual machine is started, the virtual machine judges whether a reading plug-in is installed in the virtual machine. When the reading plug-in is installed in the virtual machine, the reading plug-in is operated to read configuration information of the virtual machine in the host, an MAC address in the configuration information and an IP address associated with the MAC address are obtained, and the MAC address and the IP address are written into a virtual network card of the virtual machine.
Step S60, when the reading plug-in is not installed, sending an acquisition request of an IP address to a DHCP server so that the DHCP server returns the IP address to the virtual machine according to the acquisition request;
when the reading and disassembling part is not installed, a DHCP client is arranged on the virtual machine, and an acquisition request of an IP address is sent to the DHCP server through the DHCP client, wherein the acquisition request can comprise a DUID of the DHCP client. The DUID is an identification code of the DHCP client and is generated according to the MAC address of the virtual machine. After receiving the acquisition request of the DHCP client, the DHCP server analyzes the DUID in the acquisition request, analyzes the MAC address of the virtual machine in the DUID, searches the IP address associated with the MAC address, and returns the IP address to the DHCP client. It will be appreciated that when a virtual machine is created, it applies for an available IP address on the VPC and stores the binding between the MAC address and the IP address of the virtual machine on the VPC.
And step S70, the IP address returned by the DHCP server and the MAC address of the virtual machine are written into a virtual network card of the virtual machine in an associated mode.
After receiving the IP address returned by the DHCP server, the DHCP client side of the virtual machine writes the IP address and the MAC address into a virtual network card of the virtual machine in an associated mode.
In this embodiment, if the virtual machine is installed with a reading plug-in, the reading plug-in reads the MAC address and the IP address in the configuration information of the virtual machine; if the virtual machine is not provided with the reading plug-in, acquiring an IP address by sending an acquisition request to the DHCP server; the method can meet the requirement of the virtual machine on IP address allocation under different environments, and has the beneficial effect of wide applicability.
Referring to fig. 4, fig. 4 is a flowchart of a third embodiment of a method for allocating an IP address of a virtual machine according to the present invention, where the method for allocating an IP address of a virtual machine further includes:
step S80, after receiving an acquisition request of an IP address sent by a virtual machine, a DHCP server acquires a corresponding identification code according to the acquisition request;
step S90, acquiring the IP address associated with the MAC address of the virtual machine according to the identification code;
in this embodiment, the execution subject is a DHCP server. DHCP is a network protocol of a local area network that automatically assigns IP addresses to internal networks or network server providers by working with the UDP protocol, and to users or internal network administrators as a means of centrally managing all computers.
After receiving the acquisition request of the IP address sent by the virtual machine, the DHCP server analyzes the identification code in the acquisition request and analyzes the MAC address of the virtual machine according to the identification code. After the DHCP server obtains the MAC address of the virtual machine, the binding relationship between the MAC address and the IP address stored in advance in the VPC may be queried, where the binding relationship may be a one-to-one association relationship between the MAC address and the IP address.
Alternatively, the binding relationship of the MAC address and the IP address may be stored in a mapping relationship table of the MAC address and the IP address of the VPC.
And step S100, when the IP address associated with the MAC address is acquired, returning the IP address to the virtual machine.
After finding that the binding relation exists between the MAC address and the IP address, the DHCP server acquires the IP address associated with the MAC address and returns the IP address associated with the MAC address to the virtual machine.
In this embodiment, the DHCP server obtains the corresponding identification code according to the received obtaining request, obtains the IP address associated with the MAC address of the virtual machine according to the identification code, returns the IP address to the virtual machine, and only needs to maintain the binding relationship between the MAC address and the IP address on the VPC, and returns the allocated IP address to the virtual machine for use by searching the binding relationship between the MAC address and the IP address.
Referring to fig. 5, fig. 5 is a flowchart of a fourth embodiment of a method for assigning IP addresses to virtual machines according to the present invention, based on the third embodiment, after step S100, the method further includes:
step S110, when the IP address associated with the MAC address is not acquired, the IP address in an idle state is allocated to the virtual machine;
and step S120, returning the IP address to the virtual machine.
The VPC is provided with an IP pool for storing IP addresses. The states of the IP address on the VPC may include both idle and non-idle states. The IP address in the idle state can be distributed to the virtual network card of the new virtual machine; the IP address in the non-idle state is the IP address to which the MAC address is bound.
After the IP address is bound with the MAC address, the IP address can only be used by the virtual machine corresponding to the bound MAC address and cannot be used by the virtual network cards of other virtual machines, so that communication faults are prevented.
When the DHCP server does not query the IP address associated with the MAC address on the VPC, an IP address in an idle state may be sequentially or randomly allocated to the virtual machine in the IP pool of the VPC, and the IP address is returned to the virtual machine, so that the virtual machine writes into the virtual network card after receiving the IP address, and performs network operation.
Optionally, after the step of returning the IP address to the virtual machine, the method further includes:
updating the state of the IP address to be a non-idle state, and establishing the association relation between the IP address and the MAC address.
Because the IP address is allocated to the virtual machine, in order to prevent communication failure caused by continuous allocation to other virtual machines, the state of the IP address needs to be updated to a non-idle state, and the binding relation between the IP address and the MAC address of the virtual machine is stored in the VPC, so that the binding relation between the MAC address and the IP address on the VPC can be effectively maintained, and the VPC can be ensured to be orderly carried out.
Optionally, the virtual machine may release the IP address on the virtual machine network card according to the user setting, so that the VPC recovers the released IP address. After recovering the IP address, the VPC deletes the mapping table of the MAC address and the IP address stored in the database, and updates the state of the recovered IP address to the idle state.
Further, when the host deletes the virtual machine or the VPC receives the instruction for deleting the virtual machine, the VPC may delete the binding relationship between the MAC address and the IP address, recover the IP address, and update the state of the IP address from the non-idle state to the idle state.
In this embodiment, when the DHCP server does not acquire the IP address associated with the MAC address, the IP address in the idle state is allocated to the virtual machine, and the IP address is returned to the virtual machine, so that the IP address in the idle state is timely allocated to the virtual machine, which can ensure that the allocated IP address can only be used by the virtual machine, and has the advantages of high allocation efficiency and prevention of communication collision.
In addition, the embodiment of the invention also provides a terminal device, which comprises a processor, a memory and an allocation program of the IP address of the virtual machine, wherein the allocation program of the IP address of the virtual machine is stored on the memory and can run on the processor, and the content of the embodiment of the allocation method of the IP address of the virtual machine is realized when the allocation program of the IP address of the virtual machine is executed by the processor.
The embodiment of the invention also provides a DHCP server, which comprises a processor, a memory and an allocation program of the IP address of the virtual machine, wherein the allocation program of the IP address of the virtual machine is stored on the memory and can run on the processor, and the content of the embodiment of the allocation method of the IP address of the virtual machine is realized when the allocation program of the IP address of the virtual machine is executed by the processor.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
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 one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a computer readable storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.

Claims (3)

1. The method for distributing the IP addresses of the virtual machines is characterized by comprising the following steps of:
after a virtual machine is started, judging whether a reading plug-in is installed in the virtual machine, wherein the reading plug-in is used for reading configuration information of the virtual machine and reading an MAC address in the configuration information and an IP address associated with the MAC address, and the IP address is an IPv6 address;
when a reading plug-in is installed, the reading plug-in is operated to acquire configuration information of the virtual machine in a host, wherein when the virtual machine is created, the host acquires an MAC address of the virtual machine and distributes an IP address for the virtual machine, and the distributed IP address and the MAC address are associated and stored in the configuration information; acquiring the association relation between the MAC address and the IP address of the virtual machine according to the configuration information; writing the MAC address and the IP address into a virtual network card of the virtual machine;
when the reading plug-in is not installed, sending an acquisition request of an IP address to a DHCP server so that the DHCP server returns the IP address to the virtual machine according to the acquisition request, wherein a DHCP client is arranged on the virtual machine, the acquisition request of the IP address is sent to the DHCP server through the DHCP client, after receiving the acquisition request of the IP address, the DHCP server analyzes an identification code in the acquisition request of the IP address, analyzes an MAC address of the virtual machine in the identification code, searches an IP address associated with the MAC address, and returns the IP address to the DHCP client; writing the IP address returned by the DHCP server and the MAC address of the virtual machine into a virtual network card of the virtual machine in an associated manner, wherein the identification code is a unique identifier;
after the step of writing the MAC address and the IP address into the virtual network card of the virtual machine, the method for allocating the IP address of the virtual machine further includes:
after receiving the update information of the IP address sent by the host, acquiring the updated IP address in the configuration information;
deleting the IP address and the MAC address written in the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
2. The method for assigning an IP address to a virtual machine according to claim 1, wherein after the step of writing the MAC address and the IP address into a virtual network card of the virtual machine, the method for assigning an IP address to a virtual machine further comprises:
after the configuration information is detected to be updated, acquiring an IP address in the updated configuration information;
deleting the IP address and the MAC address of the virtual network card when the IP address in the updated configuration information is different from the IP address of the virtual network card;
and writing the IP address in the configuration information updated by the MAC address into a virtual network card of the virtual machine.
3. A terminal device, characterized in that it comprises a processor, a memory and an allocation program of IP addresses of virtual machines stored on the memory and executable on the processor, the allocation program of IP addresses of virtual machines implementing the steps of the allocation method of IP addresses of virtual machines according to claim 1 or 2 when executed by the processor.
CN202010211872.8A 2020-03-23 2020-03-23 IP address allocation method of virtual machine, terminal equipment and DHCP server Active CN111427662B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010211872.8A CN111427662B (en) 2020-03-23 2020-03-23 IP address allocation method of virtual machine, terminal equipment and DHCP server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010211872.8A CN111427662B (en) 2020-03-23 2020-03-23 IP address allocation method of virtual machine, terminal equipment and DHCP server

Publications (2)

Publication Number Publication Date
CN111427662A CN111427662A (en) 2020-07-17
CN111427662B true CN111427662B (en) 2024-04-09

Family

ID=71549000

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010211872.8A Active CN111427662B (en) 2020-03-23 2020-03-23 IP address allocation method of virtual machine, terminal equipment and DHCP server

Country Status (1)

Country Link
CN (1) CN111427662B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113592458B (en) * 2021-08-05 2024-01-12 百融云创科技股份有限公司 Number allocation method and device
CN116527639A (en) * 2022-01-24 2023-08-01 华为云计算技术有限公司 Address space recommending method and device and related equipment
CN114500452B (en) * 2022-01-27 2024-03-22 洛阳市众信佳智能网络科技有限公司 Method, device and equipment for determining virtual system IP address in bridge mode
CN114928591A (en) * 2022-05-31 2022-08-19 济南浪潮数据技术有限公司 Method, device and medium for adding IP address of virtual machine

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106911779A (en) * 2017-02-27 2017-06-30 郑州云海信息技术有限公司 A kind of cloud platform virtual machine obtains IP method and devices
CN107357630A (en) * 2017-07-13 2017-11-17 郑州云海信息技术有限公司 A kind of method, apparatus and storage medium for realizing that virtual machine is synchronous
CN107357634A (en) * 2017-07-19 2017-11-17 郑州云海信息技术有限公司 A kind of parameter configuration management method and device
CN107707687A (en) * 2017-10-10 2018-02-16 郑州云海信息技术有限公司 A kind of method and apparatus of virtual machine IP address configuration

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106911779A (en) * 2017-02-27 2017-06-30 郑州云海信息技术有限公司 A kind of cloud platform virtual machine obtains IP method and devices
CN107357630A (en) * 2017-07-13 2017-11-17 郑州云海信息技术有限公司 A kind of method, apparatus and storage medium for realizing that virtual machine is synchronous
CN107357634A (en) * 2017-07-19 2017-11-17 郑州云海信息技术有限公司 A kind of parameter configuration management method and device
CN107707687A (en) * 2017-10-10 2018-02-16 郑州云海信息技术有限公司 A kind of method and apparatus of virtual machine IP address configuration

Also Published As

Publication number Publication date
CN111427662A (en) 2020-07-17

Similar Documents

Publication Publication Date Title
CN111427662B (en) IP address allocation method of virtual machine, terminal equipment and DHCP server
US8769040B2 (en) Service providing system, a virtual machine server, a service providing method, and a program thereof
JP3643330B2 (en) Method and system for automatically assigning a boot server to a PXE client on a network via a DHCP server
US7873711B2 (en) Method, system and program product for managing assignment of MAC addresses in a virtual machine environment
CN109981493B (en) Method and device for configuring virtual machine network
WO2006095184B1 (en) Data processing system
CN106254571B (en) Client IP address allocation method and device
CN101094129A (en) Method for accessing domain name, and client terminal
US8677508B2 (en) Confidential information leakage prevention system, confidential information leakage prevention method and confidential information leakage prevention program
WO2009097776A1 (en) System, device and method for achieving service upgrade
US7958220B2 (en) Apparatus, method and system for acquiring IPV6 address
CN111857973A (en) Application resource access method and device
CN106878052B (en) User migration method and device
US7181567B2 (en) Hitless restart of access control module
WO2016202016A1 (en) Device management method, apparatus and system
CN111327509A (en) Information updating method and device
CN103841200A (en) Method and device for controlling software licensing
EP2200395A1 (en) Managing method, system and device for an appearance packet
CN111565176B (en) Intelligent disguising host method, system, device and readable storage medium
CN113114571A (en) Data packet processing method and device, electronic equipment and storage medium
CN113507415A (en) Table item processing method and device
JP2002135254A (en) Communication processor and its program-recording medium
CN110677378B (en) Control method of MAC address, intelligent terminal and storage medium
KR101361513B1 (en) Computer and control method thereof
JP2002300166A (en) Method for automatically setting ip address and computer name

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant