stay TCP/IP In the network , Each interface needs a IP Address 、 Subnet mask and broadcast address ( IPv6 There is no ), Simply put, you need network configuration information . If you want to access the external network, you can use DNS Get external address , Then it is forwarded indirectly through the route . But in “ Home network ”( This network ) Want to communicate , You need to know your own information and the information of others . You can configure your own information , Others' information can be accessed through ARP inquiry .
Of course , How do you know your own information , You need to ask the network administrator , perhaps DHCP I know .
DHCP( Dynamic host setup protocol ,Dynamic Host Configuration Protocol,RFC[2131])
title: remind
If you understand ARP Will be better
Want to know more about ARP You can ask Google
Some of the concepts
dhcp Hierarchical structure
dhcp It is an application located in the application layer , Is based on BOOTP (BootStrap agreement ), Use its 68( Server side ) and 67 ( client ) These two ports
dhcp There are three ways to configure :
1. Manual configuration
2. Automatic configuration
For example, stateless address automatic configuration (SLAAC)
3. Dynamic allocation
Address pool and lease
When DHCP The client requests to assign a IP Address , The server selects an address from the available address pool as a response . This address pool is created DHCP Is a given allocable IP Address .
The address assigned to the client is only valid for a period of time , This period of time is called Rental period
The client can request an extension of the lease period when the address is about to expire , This title is renewed
DHCP The server will store the lease information in persistent storage , It is usually in nonvolatile memory or disk to prevent loss .
DHCP and BOOTP The message format
DHCP Expanded BOOTP( He is DHCP The predecessor ).DHCP The definition of message format adopts extension BOOTP(bootstrap protocal) The way
- Message type : Used to identify the type of message , There are two values: :
- request (1)
- The reply (2)
- Hardware type : be based on ARP Value used , The most common is 1( Ethernet Ethernet)
- Hardware address length : The length used to store the hardware address , Ethernet is MAC Address length (6)
- Skip steps : It is used to save the relay times during message transmission . The message sender is set to 0, And increment after each relay
- Business ID: A random number randomly selected by the client , The server needs to copy it to the corresponding , Used to reply (ACK) Match the request
- Number of seconds : Set by the client , It is the number of seconds after the first attempt to re apply for an address
- Usually the client can reapply for an address
- sign : The client can set this bit to indicate that it is unable or unwilling to handle unicast IP The datagram , But it can handle broadcast datagrams , Notify the server and relay agent , Broadcast address can be used in response .
- Yours IP: Provided by the server , It means to distribute IP
- Next server IP Address : The boot process for the client .
- gateway ( relay )Ip Address : from DHCP or BOOTP Repeaters provide , forward DHCP Return your address when you send a message .
- Client hardware address field : Save the unique identifier of the client . Usually client MAC Address .
- Server name and boot file name : You don't need to fill in every time , Indicates the server name or boot file path .
- magic cookie: Used to indicate the following option yes BOOTP still DHCP [RFC 1497 , Vendor Information "Magic Cookie"]
- Options : Carry some extra data . Here are some common options
name | value |
---|---|
Options include padding | 0 |
Subnet mask | 1 |
Router address | 3 |
Domain name server | 6 |
domain name | 15 |
Requested IP Address | 50 |
Address lease term | 51 |
DHCP Message type | 53 |
Server identifier | 54 |
Parameter request list | 55 |
DHCP Error message | 56 |
Lease renewal time | 58 |
Lease rebinding time | 59 |
Client identifier | 61 |
Domain search list | 119 |
end | 255 |
DHCP Message type is more important , This option is 1 Byte long options ,DHCP Messages will definitely use it , It has the following possible values
name | value | RFC |
---|---|---|
DHCPDISCOVER | 1 | RFC3203 |
DHCPOFFER | 2 | RFC3203 |
DHCPREQUEST | 3 | RFC3203 |
DHCPDECLINE | 4 | RFC3203 |
DHCPACK | 5 | RFC3203 |
DHCPNAK | 6 | RFC3203 |
DHCPRELEASE | 7 | RFC3203 |
DHCPINFORM | 8 | RFC3203 |
DHCPORCERENEW | 9 | RFC3203 |
DHCPLEASEQUERY | 10 | RFC4388 |
DHCPLEASEUNASSIGNED | 11 | RFC4388 |
DHCPLEASEUNKNOWN | 12 | RFC4388 |
DHCPLEASEACTIVE | 13 | RFC4388 |
DHCP How it works
Common applications DHCP The way
The following figure shows the network topology of the test
Will use PC2 apply IP
PC2:
dhcp
Grab the line Router1 -> Switch1 In the package , give the result as follows :
Two DHCP Server received Discover
Just through ARP Check if there is IP Conflict , When no conflict is found, a offer
, Indicates that the application request has been processed , Then the client sends a Request
Say that you have accepted DHCP Server requests ( This is to ensure multiple DHCP Provided by the server IP)
, As shown in the figure below ( It's filtered out ARP), Another one DHCP Also sent a offer
Whose client accepts offer
Just to that DHCP The server sends Request
, after DHCP The server will return a ACK
.
You can also see a lot in the above figure ARP My bag .
First ,12-14( The first picture ) There are two bags DHCP The server solves the problem that will not happen in this network to the greatest extent IP Collision . When not received, there is the same IP Emitted ARP package , Will go to DHCP The client sends offer
.
Then the customer opportunity sends ACD(IPv4 Address conflict detection ) To inform this website that you are using this IP Address , To make sure that others won't use .
TCP/IP The picture in the detailed explanation is particularly clear :
dhcp The renewal of
First , Will get IP Release
The picture below is Release
message
Seconds elapsed To get to this IP To IP Release the number of seconds elapsed , In other types of messages, this field is 0
Only Release
The message will carry this field
Option 53 , Express DHCP Message type , The value is 7 It means a Release.
The client has released the IP
modify DHCP Server's lease Make the client every 30S Renewal required :
As shown in the figure above , After that, the customer opportunity every 30S Apply once ( Here is 32S)
The client sends... To the server Request , The server receives and sends a ACK
dhcp The client Recapture
Just go through the acquisition process again
Reference and tools used
Reference resources :
TCP/ IP Detailed explanation Volume one
Tools :
gns3
Wireshark