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--
One: how DHCP works
1. What is DHCP protocol?
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.
Messages in 2.DHCP Protocol
There are several types of DHCP messages:
DHCP DISCOVER: the packet sent by the client to start the DHCP process, which is the beginning of the DHCP protocol
DHCP OFFER: the response made by the server after receiving the DHCP DISCOVER, including 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 issued 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 a 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 that it is forbidden
Use this IP address.
The workflow of DHCP:
The composition of 3.DHCP protocol package
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 ip address here when sending the request
Yiaddr: the server will put the ip address that you want 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, which may be the ip of a route in multiple route hops (the siaddr is also marked as nextserver ip address in the wireshark grab packet below)
Chaddr: mac address of the client
Giaddr: if you need to issue DHCP addresses across subnets, enter the ip address of the passing router here
Sname: server primary domain name
Options: a part that can be freely added to store the client's request information from the server and the server's reply information
Two: DHCP client
1. What is a DHCP client?
DHCP clients are generally independent PC hosts 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.DHCP automatic state machine
4 steps for DHCP to obtain ip address: discover > offer > request > ack (nak)
Steps for DHCP to refresh the lease: request > ack (nak)
DHCP steps to release ip: release
No rebooting, init reboot status was found in the code of wnr2000v5 1.0.0.8. Therefore, the state of DHCP client usually starts with init, and the complete state machine is shown below (red represents the status transition of the client):
Three: DHCP server
1. What is DHCP SERVER?
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.
two。 Two tenancy schedules
Static lease table: corresponds to a static lease storage file from which the server runtime reads the static lease table.
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 principles
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 status 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 a 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:
A.server attempts to assign to the IP that client assigned last time, and before that, check to see if the IP is in use.
When there is a request ip in the b.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.
C.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 now in the init_reboot,selecting,renewing/rebinding based on whether it contains request ip and server ip, and perform an DHCPACK reply according to the following rules:
a. If client is in selecting state, verify that request ip and server ip match those in the server.
b. If client is in init_reboot state, verify that request ip conforms to the lease record.
c. If client is in renewing/rebinding state, verify that client ip address conforms to the lease record.
DHNAK:
a. The requested IP is a static IP, but the MAC address cannot correspond to it.
b. 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.
Four: analyze the working mode of DHCP
1. When a machine joins a new network, it only knows its own MAC address. How can it get IP? This step is called DHCP Discover. The new machine sends a broadcast packet with an IP address of 0.0.0.0 with a destination IP of 255.255.255.255. The broadcast package encapsulates UDP,UDP and encapsulates BOOTP. The content of the radio newspaper is like this:
two。 If a network administrator configures DHCP Server in the network, he is equivalent to the administrator of these IP. He immediately knows that a "newcomer" has come and will rent it an IP address, a process we call DHCP Offer. The format of DHCP Offer is as follows:
3. If there is more than one DHCP Server, the new machine will receive multiple IP addresses, it will select one of the DHCP Offer, usually the first to arrive, and will send a DHCP Request broadcast packet to the network, including the MAC address of the client, the IP address in the accepted lease, the DHCP service address that provides the lease, and so on.
After 4.DHCP Server receives the client's DHCP request, it broadcasts a DHCPACK message packet back to the client indicating that the client's choice has been received.
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.