Summary of the principle of DHCP service under Linux

Source: Internet
Author: User
Tags ack reserved wrapper

Linux ipv6 dhcp client

DHCP service DHCP under Linux (full name Dynamic Host Config protocol): dynamically hosted Configuration Protocol


DHCP works at the OSI application layer and can help the computer obtain the configuration information from the specified DHCP server protocol. (mainly include: IP address, subnet mask, gateway and DNS, etc.).


linux dhcp server configuration pdf 

How DHCP works:
The client transmits the broadcast packet to all the main clauses within the entire physical network segment, such as a DHCP server within the LAN, that responds to the client's IP parameter requirements, so the DHCP server and the client should be within the same physical network segment.
The process of connecting between a client and a DHCP server is as follows:

linux gui dhcp server


?



1) Client: Use broadcast packet to send search DNCP server package
2) server-side: Provides lease selection related to client network
3) Client: Determine the network parameter lease provided by the selected DHCP server and report it to the server
4) server-side: Record this lease and return the packet information to the client

Linux enable dhcp command line


In simple terms, DHCP works:
(1) Client looking for server: Broadcast sending Discover packet, looking for DHCP server
(2) Server response Request: Single advertisement send offer package, respond to client. Provide client network-related leases to select the server after receiving the client's request, the client's MAC address and its own set of data to do a bit of work:
A) Look in the server's login file to find the IP that the user has used before, and if it is not currently used, this IP is provided to the client
b) Provide this IP to the client if an additional fixed IP is provided for the MAC in the configuration file and the IP is not used
c) If the above two conditions are not met, the IP parameters that are not currently used are randomly taken to the client and logged to the leases file.
(3) client sends IP request: Broadcast request packet, select a server to provide the network parameter lease return server. In addition, the customer is given the opportunity to send a broadcast packet to all hosts within the LAN, informing them that they have accepted the server's lease.
(4) The server confirms the lease: Unicast ACK packet, the server confirms the lease relationship with the client and logs it to the server's leases file.


linux interfaces dhcp

Next, there are several concepts of DHCP:
DHCP CLIENT:DHCP clients that request IP addresses through the DHCP protocol. A DHCP client is an interface-level concept, and if a host has multiple Ethernet interfaces, each interface on that host can be configured as a DHCP client. Each VLAN interface on the switch can also be configured as a DHCP client.
The DHCP SERVER:DHCP server is responsible for providing IP addresses to DHCP clients, and is responsible for managing assigned IP addresses.
DHCP Relay:dhcp repeater, the DHCP client requests the IP address across the network segment, realizes the DHCP message forwarding function.
DHCP SECURITY:DHCP security features to enable the management of legitimate User IP address tables
DHCP snooping:dhcp Monitoring, recording user information requested to IP address through a two-tier device



DHCP work can be broadly divided into several stages:



?



I. Discovery phase:
That is, the DHCP client is looking for a DHCP server process that corresponds to the client sending DHCP Discovery because the DHCP client is unknown to DHCP clients, so DHCP clients emit DHCP The discovery message is a broadcast packet with a source address of 0.0.0.0 The destination address is 255.255.255.255. All TCP/IP-enabled hosts on the network receive the DHCP discovery message, but only DHCP server responds to the message.
If more than one DHCP server is present in the network, multiple DHCP servers will reply to the DHCP discovery message.
If there is no DHCP Server in the same VLAN, and the vlanif is configured with DHCP relay functionality, the vlanif is DHCP relay, which modifies the source IP address of the DHCP message to the IP address of the vlanif. The destination address is the IP address of the DHCP server that is configured for DHCP relay. While modifying the DHCP message, giaddress is the IP address of the vlanif. and sends DHCP discovery to the DHCP server side as unicast.



Second, DHCP server provides phase:
DHCP server provides phase, that is, DHCP server in response to DHCP discovery The DHCP offer stage
DHCP server received DHCP After discovery the message, the subnet of the IP address requested by the message is parsed. And remove an available IP address from the subnet that matches it in the dhcpd.conf file (select an IP address from the available address segment, first send an ICMP message to ping the IP address, and if you receive an ICMP packet of that IP address, discard the IP address, Re-select the IP address to continue the ICMP message test until you find a network of no one to use the IP address to prevent the dynamic allocation of IP addresses and other devices in the network IP address conflict, this IP address collision detection mechanism, configurable), set in the DHCP The Yiaddress field in the discovery message represents the IP address assigned to the client and sets the option for the subnet configuration for that lease, such as the default leases lease, maximum lease period, router, and so on.
DHCP chooses an IP address from the address pool to select from the following priority:
    1) The corresponding relationship of the IP Mac that currently exists
    2) client's previous IP address
    3) Read the value of the requested IP address option in the discovery message, if present and IP addresses available
    4) Select the IP address from the configured subnet:
DHCP The server resolves the DHCP discovery request IP to the subnet, first look at the DHCP discovery message giaddress whether there is DHCP Relay, if any, The IP address segment is available from the subnet described in Giaddress, and is assigned to IPS. If the giaddress does not have an IP address, the IP address is assigned from the network segment to which the IP address of the interface bound by the DHCP server belongs.



Third, the DHCP Client selection phase:
After the DHCP client receives a DHCP offer message for several DHCP server responses, select one of the DHCP servers as the target DHCP server. The selection policy is typically the DHCP Server that belongs to the DHCP offer message that selects the first response.
A DHCP request message is then broadcast, which contains information such as the IP address that is requested for the target DHCP. It is broadcast in order to notify other DHCP servers that they will choose the IP address provided by the DHCP server itself.



Iv. DHCP Server Confirmation phase:
When the DHCP server receives a DHCP request sent by the DHCP client, after confirming the IP address to be provided for the DHCP client, it wants the DHCP client to respond to a message containing the IP address and other option to tell the DHCP The client can use the IP address. The DHCP client can then bind the IP address to the NIC. In addition, other DHCP servers will reclaim the IP addresses that they previously provided to the DHCP client.



V. DHCP client re-login to the network:
When the DHCP client logs back in, sends a DHCP request message that contains the IP address information assigned by the previous DHCP server, and when the request is received by the DHCP server, it attempts to have the DHCP client continue to use the IP address. And answer an ACK message.
However, if the IP address cannot be assigned to the DHCP client again, DHCP replies to a NAK message, and when the DHCP client receives the NAK message, the DHCP discovery message is re-sent to retrieve the IP address.



VI. DHCP Client Update Lease:
The IP address that DHCP obtains has a lease, and after the lease expires, DHCP server reclaims the IP address, so if the DHCP client wants to continue using the IP address, the lease must be updated. The update is that when the current lease expires in half, the DHCP client sends a DHCP renew message to renew the lease.



DHCP Configuration under Linux:
The configuration files are placed in the/ETC/DHCP directory; The master configuration file is dhcpd.conf
Copy the/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample file to the configuration file directory and overwrite the dhcpd.conf file to get the master profile.


The main contents of the main configuration file are:
Option Domain-name "example.org"; Specify Domain name for domain
Option Domain-name-servers ns1.example.org, ns2.example.org; Specifies the IP address of the domain name resolution server (DNS).
Default-lease-time 600; Default lease time in S
Max-lease-time 7200; The maximum lease time, in S. Expired renewal, renewal direct send request package.
Log-facility Local7; The log device type is LOCAL7. General log device types include mail, crontab. This option allows you to find the logging path for the service
Subnet 10.5.5.0 netmask 255.255.255.224 {//Specifies the IP address of the distribution segment and the subnet mask, inside the brackets is a local configuration.
Range 10.5.5.26 10.5.5.30; Address pool ranges that can be used
Option Domain-name-servers ns1.internal.example.org; The domain name of the network segment, can be omitted
Option Domain-name "internal.example.org"; Network Segment DNS
Option routers 10.5.5.1; Specify the Gateway
Option Broadcast-address 10.5.5.31; Specify a broadcast address
Default-lease-time 600; Lease time
Max-lease-time 7200; Maximum lease time.
}
Host Passacaglia {//hostname
Hardware Ethernet 0:0:c0:5d:bd:95; MAC address of the host
FileName "Vmunix.passacaglia";
Server-name "toccata.fugue.com"; The file name and server name are not required.
Fixed-address fantasia.fugue.com; Fixed IP address
}//Reserved host, this option specifies the address that is specified by the host on which the internal MAC address is requested when requesting IP. If the specified IP is already allocated, the specified IP of the reserved host will not be available for use.


A local area network is best to have only one DHCP server, when there are multiple servers in a local area network, the client selects only the first offer to arrive.



Figure out the following questions:
1) How do I know which DNS server the client obtains an IP address from?
Windows directly view the network link details, there is a DHCP server, you can see the IP address of the server.
Under Linux view/var/lib/dhclient/dhclient.leases, this is a lease file, the server-side lease file is/var/lib/dhcpd/dhcpd.leases.
2) What is the order of the servers assigning IP?
Start assigning from small IP
3) Why does the client get a previously used IP after acquiring an IP, releasing and then acquiring the IP?
The client has a lease file that holds its own IP address, and the server side has a lease file that holds its assigned IP and its corresponding host Mac.
4) on which ports will the server provide DHCP services?
The DHCP service is provided by default on any port. DHCP service is actually provided on the network card with the same network segment as DHCP.
5) What if the lease expires and the server does not renew?
will look for DHCP services to other servers



Summary of the principle of DHCP service under Linux


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.