In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What is DHCP?
DHCP, dynamic host configuration protocol, formerly known as BOOTP protocol, is a local area network protocol, using UDP protocol to work, commonly used 2 ports: 67 (DHCP server), 68 (DHCP client). DHCP is usually used in the local area network environment, the main function is to centrally manage and assign IP addresses, so that client can dynamically obtain IP addresses, Gateway addresses, DNS server addresses and other information, and can improve the utilization rate of addresses. To put it simply, DHCP is a protocol that automatically assigns information such as IP addresses to intranet machines without the need for account passwords. 2. There are several kinds of DHCP messages in DHCP protocol: DHCP DISCOVER: the packet sent by the client at the beginning of the DHCP process is the start of the DHCP protocol DHCP OFFER: the response made by the server after receiving the DHCP DISCOVER, it includes the IP (yiaddr) given to the client, the MAC address of the client, the expiration time of the lease, the identifier of the server and other information DHCP REQUEST: the response of the client to the DHCP OFFER sent by the server. It will also be used when renewing the lease. DHCP ACK: a successful acknowledgement message sent by the server after receiving a DHCP REQUEST from the client. When a connection is established, the client does not confirm that the IP and other information assigned to it can be used until it receives this message. DHCP NAK: the opposite message of DHCP ACK, indicating that the server has rejected the client's request. DHCP RELEASE: generally appear in the client shutdown, offline and other conditions. This message will cause the DHCP server to release the IP address of the client that sent the message DHCP INFORM: a message sent by the client requesting some information from the server: DHCP DECLINE: when the client finds that the IP address assigned by the server cannot be used (such as an IP address conflict), it will send this message informing the server to prohibit the use of the IP address. The process of DHCP requesting IP address is as follows: 1) the host sends DHCPDISCOVER broadcast packet to find the DHCP server on the network; 2) the DHCP server sends DHCPOFFER unicast packet to the host, including IP address, MAC address, domain name information and address lease period; 3) the host sends DHCPREQUEST broadcast packet to formally request the server to assign the provided IP address 4) the DHCP server sends DHCPACK unicast packets to the host. It needs to be stated that the DHCP client can receive DHCPOFFER packets from multiple DHCP servers, and then may accept any DHCPOFFER packet, but the client usually only accepts the first DHCPOFFER packet received. In addition, the address specified in the DHCP server DHCPOFFER [1] is not necessarily the final assigned address, which is usually retained by the DHCP server until the client makes a formal request. Formally requesting the DHCP server to assign an address DHCPREQUEST uses a broadcast packet so that all other DHCP servers that send DHCPOFFER packets can receive the packet, and then release the IP address that has been OFFER (pre-assigned) to the client. If the address sent to the DHCP client is already in use by another DHCP client, the client sends a DHCPDECLINE packet to the server to refuse to accept the assigned address information. During the negotiation process, if the address information in the REQUEST message sent by the DHCP client is incorrect, such as the client has migrated to a new subnet or the lease has expired, the DHCP server will send a DHCPNAK message to the DHCP client to ask the client to re-initiate the address request process. Workflow flow chart of DHCP:
3. Composition of DHCP protocol packet Xid: a randomly generated string in which two packets have the same xid indicating that they belong to the same session Ciaddr: the client will put its own ip address here when sending the request Yiaddr: the server will put the ip address that it wants to assign to the client here Siaddr: generally speaking, it is the ip address of the server. But be careful! According to the comments given by the openwrt source code, when the source address, siaddr, option > server_id fields of the message are inconsistent (some are forwarded across subnets), it is generally considered that the option > srever_id field is the real server ip,siaddr may be a router ipChaddr in multiple route redirects: client's mac address Giaddr: if cross-subnet DHCP address is required Then fill in here the ip address of the passing router Sname: server main domain name Options: the part that can be freely added for storing the client request information from the server and the server reply information DHCP client 1, DHCP principle 1, what is the DHCP client DHCP client is generally an independent PC host in the local area network. The DHCP DISCOVER package sent by the DHCP client is the beginning of the DHCP protocol. Most behaviors in DHCP, such as lease renewal, discovery, and release of IP addresses, are initiated by DHCP clients. 2. 4 steps for DHCP automatic state machine DHCP to obtain ip address: discover > offer > request > ack (nak) DHCP to refresh lease: request > ack (nak) DHCP to release ip: release as shown below:
DHCP SERVER
I. DHCPD principle
1. Brief introduction
DHCP SERVER refers to the server side, which reflects the function of dynamically allocating IP to the LAN side on the router. DHCP SERVER is responsible for receiving the DHCP request from the client and managing all the IP network setting data on the LAN side. Compared with BOOTP,DHCP through "lease" to achieve dynamic allocation of IP, to achieve IP time division multiplexing, so as to solve the problem of shortage of IP resources. There are three ways of address allocation, namely manual configuration (the administrator assigns an address to each specific computer), automatic configuration (the server assigns a permanent address to the computer connected to the network for the first time), dynamic configuration (the address is leased to the computer within a certain period of time, and the customer must renew or deactivate the address at the end of the lease), while for the router The frequently used method of address allocation is dynamic configuration. 2. Two static lease tables: corresponding to a static lease storage file, the server runtime reads the static lease table from the file. Dynamic lease table: corresponding to a periodic storage file, server periodically stores the lease table in this file, and the last stored lease table will be read at the beginning of the program. The lease table records all currently assigned leases, including statically linked ones. 3. Basic logic in principle, DHCP SERVER is always in the state of passively accepting requests. When there is a client request, the server will read and obtain the current state of the client and the information of the client, and search in the static lease table and dynamic lease table to find the corresponding table items, and then perform different responses according to the status of the client. When receiving the first request from the client, the DHCP server first looks up the static lease table; if there is a table entry of the request, it returns the static IP address of the customer; otherwise, it selects the available IP from the IP address pool to assign to the customer and adds information to the dynamic database. In addition, the server will periodically refresh the lease table to write to the file archive, and in the process will check the lease period of the dynamic lease table. Perform reply action: DHCPOFFER: static lease: first match the MAC address to see if the corresponding item can be found in the static lease table, and if it can be found, assign the IP to him. The IP in the static table cannot be used by other customers. Dynamic lease: 1.server attempts to assign to the IP that client assigned last time, and before that, check whether the IP is in use. When there is a request ip in the 2.discover, check whether the IP is within the address pool range, is in use, expires, is a static IP, and whether it already exists on the network. 3.discover does not contain request ip, so look for the smallest available IP allocation from the address pool. DHCPACK: identify which state the client is in the init_reboot,selecting,renewing/rebinding according to whether it contains request ip and server ip, and execute the DHCPACK reply according to the following rules: 1. If client is in selecting state, verify that request ip and server ip match those in the server. two。 If client is in init_reboot state, verify that request ip conforms to the lease record. 3. If client is in renewing/rebinding state, verify that client ip address conforms to the lease record. DHNAK: 1. The requested IP is a static IP, but the MAC address cannot correspond to it. two。 Validation failed in DHCPACK above. The server may also receive other packets: DHCPDECLINE:server will empty the relevant client hardware address in the lease table and keep this address for a period of time. DHCPRELEASE: clear the lease to reclaim IP. DHCPINFORM: reply to DHCPACK, the data contains information about server.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.