Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does DHCP work?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how DHCP works. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

DHCP (Dynamic Host Configuration Protocol), a dynamic host configuration protocol, is an application layer protocol. When we set the client host ip address to dynamic acquisition mode, the DHCP server will assign IP to the client according to the DHCP protocol, so that the client can use this IP to access the Internet.

First, the realization principle of DHCP

1. What is DHCP?

DHCP (Dynamic Host Configuration Protocol, dynamic Host configuration Protocol) is a local area network protocol that uses UDP protocol to work. It is a popular Client/Server protocol, which is generally used to specify relevant configuration information for hosts, routers, etc. DHCP service has been widely used in enterprises and families. It can automatically assign ip addresses and other related information, and the whole process is transparent to customers.

two。 Benefits of deploying DHCP services

Reduce the workload of administrators to avoid typing errors may avoid ip address conflicts when the network changes the ip address segment, there is no need to reconfigure each user's ip address to improve the utilization of ip address to facilitate client configuration

3. DHCP allocation method

Automatic allocation (Automatic Allocation), the DHCP server assigns a permanent IP address to the host, which can be permanently used once the DHCP client successfully leases the IP address from the DHCP server for the first time. Dynamic allocation method (Dynamic Allocation), the DHCP server assigns an IP address with a time limit to the host. When the time expires or the host explicitly indicates to give up the address, the address can be used by other hosts. Manual assignment (Manual Allocation), the IP address of the client is specified by the network administrator, and the DHCP server only tells the client host the specified IP address.

4. DHCP working process

When the DHCP client starts, it searches for the existence of a DHCP server on the network. If found, a request is sent to the DHCP server. When the DHCP server receives the request, it selects the parameters configured by TCP/IP for the DHCP client and sends these parameters to the client. If conflict detection settings are configured, the DHCP server uses Ping to test the connectivity of each available address in the scope before providing the address in the lease to the client. This ensures that each IP address provided to the customer is not used by another non-TCP/IP computer using manual DHCP configuration.

DHCP works differently depending on whether the client logs in to the network for the first time.

DHCP work when logging in for the first time consists of four steps:

(1) the first step is to find a DHCP server

When the DHCP client logs in to the network for the first time, the computer finds that there is no IP address setting on the local computer, and will send DHCP   discover discovery information to find the DHCP server by broadcast, that is, send a specific broadcast message to 255.255.255.255. Every host on the network that has the TCP/IP protocol installed will receive this broadcast message, but only the DHCP server will respond.

(2) the second step is to assign IP addresses.

The DHCP server that receives the DHCP   discover discovery information on the network responds by selecting one of the unassigned IP address pools to assign to the DHCP client and sending a DHCP offer supply information to the DHCP client containing the assigned IP address and other settings.

(3) step 3: accept the IP address

After receiving the DHCP offer provided information, the DHCP client selects the first received provided information and then broadcasts a DHCP   request request containing the content of requesting the IP address from the DHCP server it selected.

(4) confirmation of IP address assignment in step 4

When the DHCP server receives the DHCP request request information answered by the DHCP client, it sends a DHCP   ack confirmation message to the DHCP client containing the IP address and other settings it provides, telling the DHCP client that it can use the IP address it provides. The DHCP client then binds its TCP/IP protocol to the network card, and in addition, except for the DHCP server selected by the DHCP client, the DHCP server will retrieve the IP address that has been provided.

Log in again:

In the future, each time the DHCP client logs back into the network, it does not need to send DHCP discover discovery information, but directly sends the DHCP request request information containing the previously assigned IP address. When the DHCP server receives this message, it tries to keep the DHCP client using the original IP address and answers a DHCP   ack confirmation message. If this IP address can no longer be assigned to the original DHCP client, the DHCP server answers a DHCP   nack denial message to the DHCP client. When the original DHCP client receives this DHCP nack denial message, it must resend the DHCP discover discovery information to request a new IP address.

If the IP address in the client DHCP request is not used on the server side, the DHCP server replies DHCP ACK to continue using IP. If the IP address in the client DHCP request is already used on the server side, the DHCP server replies DHCP NACK to tell the client that IP has been used. After replying to NACK, restart the process of DHCP's first login to update the lease:

The IP address leased by the DHCP server to the DHCP client usually has a lease term, and when the lease period expires, the DHCP server will take back the leased IP address. If the DHCP client wants to extend its IP lease, it must renew its IP lease. When the DHCP client starts and when the duration of the IP lease reaches 50% of the lease, the DHCP client automatically sends information to the DHCP server to update its IP lease.

Second, several common methods of building DHCP server

1. Provide services using DHCP function modules built into broadband routers such as TPLinK

This method is very simple, first of all, log in to the router, find the location of the DHCP function setting, and set it directly.

After setting up and saving the restart, the computers in the network can automatically obtain the iP address and other information.

two。 Office network environment uses layer 3 switch to build DHCP service

Take Huawei switch as an example: configure DHCP service on layer 3 switch:

System-view (enters global mode) [Huawei] sysname SW1 (device naming) [SW1] dhcp enable (using DHCP feature) [SW1] ip pool 10 (create global address pool Enter global address pool view at the same time) [SW1-ip-pool-10] network 192.168.10.0 mask 24 (configure IP address range that can be dynamically assigned by global address pool) [SW1-ip-pool-10] dns-list 8.8.8.8 (configure DNS) [SW1-ip-pool-10] gateway-list 192.168.10.1 (configure gateway) [SW1-ip-pool-10] excluded-ip-address 192.168.10. 201 192.168.10.254 (keep unassigned addresses) [SW1-ip-pool-10] lease day 7 (IP lease term) [SW1-ip-pool-10] dis this (query current mode configuration) # ip pool 10gateway-list 192.168.10.1 (gateway) network 192.168.10.0 mask 255.255.255.0 (IP address range) excluded-ip-address 192.168.10.201 192.168.10.254 ( Reserved IP address range) lease day 7 hour 0 minute 0 (IP lease cycle) dns-list 8.8.8.8 [SW1-ip-pool-10] quit (exit [SW1] ip pool 20 [SW1-ip-pool-20] network 192.168.20.0 mask 24 [SW1-ip-pool-20] dns-list 8.8.8 [SW1-ip-pool-20] gateway-list 192.168.20.1 [SW1-ip-pool-20] excluded-ip -address 192.168.20.201 192.168.20.254 [SW1-ip-pool-20] lease day 7 [SW1-ip-pool-20] Q Murray-[SW1] vlan batch 10 20 (batch creation of vlan) [SW1] interface GigabitEthernet0 / 0 port 1 (enter port 1) [SW1-GigabitEthernet0 ] port link-type access (configure port 1 type) [SW1-GigabitEthernet0/0/1] port default vlan 10 (configure port 1 vlan) [SW1-GigabitEthernet0/0/1] quit (exit) [SW1] interface GigabitEthernet0/0/2 [SW1-GigabitEthernet0/0/2] port link-type access [SW1-GigabitEthernet0/0/2] port default vlan 20 [SW1-GigabitEthernet0/0/2] quit (configure clients under the VLANIF10 interface to obtain from the global address pool IP address) [SW1] interface Vlanif10 (create vlanif 10) [SW1-Vlanif10] ip address 192.168.10.1 24 (configure IP address) [SW1-Vlanif10] dhcp select global (call global address pool in vlanif 10 mode) [SW1-Vlanif10] display this (query current configuration parameters) # interface Vlanif10ip address 192.168.10.1 255.255.255.0dhcp select global#Return [SW1-Vlanif10] people [SW1-Vlanif10] interface Vlanif20 [SW1-Vlanif20] ip address 192 .168.20.1 24 [SW1-Vlanif20] dhcp select global [SW1-Vlanif20] quitSW1] display ip pool (View IP address pool configuration) [SW1] quitsave (Save configuration Write device)

3. Building DHCP Services in Windows system

Take 2008server as an example:

2008ser steps to build a DHCP server:

Step 1: install the Windows Server 2008 system as the server side; the client can install other Windows systems.

Step 2: enter the 2008ser system and set the IP manually (static IP is not set, and cannot continue later)

Step 3: open the server manager: click "start menu Program"-> Administrative tools-> Server Manager in the system

Step 4: enter the server manager, click "roles" on the left, and then click "add roles" on the right

Step 5: go to the next step of adding role guides by default

Step 6: server role interface, check DHCP server

Step 7: after checking the DHCP server, click the "next" button, and the DHCP server introduction window will pop up on the screen. The next step is the default.

Step 8: select the network connection binding and check the IP address; the installer will automatically check whether your server has a static IP address, and step 2 will be detected if it is set up.

Step 9: next to "IPv4DNS Settings", you need to enter your parent domain name and the IP address of the DNS server, this domain will be used for all the scopes we created on this DHCP server; when DHCP updates the IP address information, the corresponding DNS update will synchronize the computer name with the association of the IP address.

Step 10: whether to set the WINS server address parameter, the default "applications on this network do not need WINS" option; (if necessary, correctly set the IP address of the target WINS server.)

Step 11: in the next "DHCP scope" window, click "add" on the right. We can set the scope of the DHCP server according to the IP address allocation of the local local area network, select the "activate this scope" option, and click "OK" to finish adding.

Step 12: DHCPv6 stateless mode, select disable mode; support for next-generation IP address specification IPv6 has been added by default in Windows Server 2008, but IPv6 is rarely used in the current network situation, so you can choose to disable DHCPv6 stateless mode for this server.

Step 13: in the "confirm" interface, click install after confirmation to start the automatic installation. The progress bar is complete and the DHCP installation is complete.

Finally, if the client in the local area network is set to obtain the IP address automatically, the IP automatically assigned by DHCP can be obtained.

4. Build DHCP service under Linux system

Take ubuntu system as an example:

The network topology diagram is as follows: the configuration steps are as follows:

Step 1: install isc-dhcp-server

Adopt the command: apt-get install isc-dhcp-server:

Step 1: configure isc-dhcp-server

First, set up the "ubuntu copy" as the DHCP server:

Step 3: enter the super user and edit the file / etc/default/isc-dhcp-server file:

Enter the name of the network card enp0s3 at INTERFACES= "":

Step 4: open the file and find that there are many examples that have been commented out. Choose an example, and the modified results are as follows:

Modify the local IP address, subnet mask, default gateway, DNS, etc.:

Restart the network card, restart the network, and turn on the DHCP service:

Step 5: Linux client configuration (virtual machine gets IP from virtual machine):

The network connection is set to obtain the IP address automatically:

Enter the dhclient command on the command line to reassign the IP address, and we find that the IP address has been successfully assigned. Figure 1 is the unassigned IP address, and figure 2 is the IP address 192.168.137.101 assigned by the DHCP server 192.168.137.2:

Through the analysis of wireshark grabbing packets, we can see that IP address 192.168.137.101 is indeed provided by DHCP server 192.168.137.2, and we can see the request-ack process between them:

Thank you for reading! This is the end of the article on "how DHCP works". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report