LINUX in the DHCP configuration

A, DHCP eight packets

Dhcp discover ; dhcp offer ; dhcp request ; dhcp ack ;
Dhcp NAK ; dhcp Release; dhcp Decline ; dhcp Inform

1) DHCP discover: a client requests an address, the DHCP server does not know the position, so DHCP client broadcasts a request packet transmitted within the local network, i.e. discover packet, the network aimed at discovering DHCP server All receive the discover of the DHCP server will send a response packet, DHCP client thus can know the location of existing network DHCP server.
2) DHCP offer: Discover the DHCP server receives the message, it will look for a suitable IP address in the address configured in the pool, plus the corresponding period of the lease and other configuration information (such as gateway, DNS servers, etc.), construction offer a message sent to the user, informing the user of this server can provide IP addresses. <Just tell client can provide, is pre-allocated, but also through the ARP client detects whether the IP repeat>
3) Request the DHCP:
the DHCP client may receive a lot of Offer, these must be chosen in a response. Client server usually choose the first response message Offer as their target servers, and to respond to a Request message broadcast server selected notifications. After the DHCP client successfully obtained an IP address, the address you used the last 1/2 of the lease, the DHCP server will send a unicast Request packet renewed leases, if the DHCP ACK packet is not received in the past three lease / 4:00, send broadcast messages Request to renew the lease.
4) DHCP ACK:
the server receives the DHCP Request message, the user carries the MAC Request message to find the lease has no corresponding record, if the response transmits an ACK packet to notify the user can use the IP address assigned .
5) DHCP NAK:
If the DHCP server receives a Request packet did not find a corresponding lease record or for some reason can not be assigned IP addresses correctly, sends NAK messages in response, notifies the user can not assign the appropriate IP address.
6) DHCP Release:
When users no longer need to use the assigned IP address, it will automatically send a message to the DHCP server Release, users no longer need to tell the server to assign IP addresses, DHCP server will release the lease be bound.
7) DHCP Decline:
After the DHCP client receives the DHCP server response ACK packet, the address conflict detection discovery server-assigned address conflict or for other reasons can not be used, then send Decline message notification server assigned IP address unavailable.
8) DHCP Inform:
After the DHCP client if required to obtain more detailed configuration information from a DHCP server, then send an Inform message request to the server, the server receives the message, according to the lease will look to find the appropriate configuration after the information, it sends an ACK packet to respond to DHCP clients. <Rarely used>

Second, the Linux DHCP arranged
 off the firewall and SELinux
 
. 1 .. Software installation yum install dhcp -y
port DHCP server: 67 DHCP Client Port: 68
2. Sample files
/usr/share/doc/dhcp*/dhcpd.conf.example Vim
vim /etc/dhcp/dhcpd.conf

ddns-update-style interim; // dns dynamic update mode
ignore client-updates; // this option is not allowed clients to update DNS records. Of course, it could allow, but there will be no problem.

Subnet configuration section #
# and the subnet mask statement
subnet 192.168.40.0 netmask 255.255.255.0 {# address range specified
    range dynamic-bootp 192.168.40.130 192.168.40.254; # assigned gateway option routers 192.168.40.1; # specify a mask
    option subnet-mask 255.255.255.0; # specify the DNS
    Option-name-Domain Servers 114.114.114.114; # default lease
    default-lease-time 21600; # maximum lease
    max-lease Time-43200;
    }
case a: a single network configuration
will The client, the host dhcp option to cancel
[root @ localhost Desktop] # vim /etc/dhcp/dhcpd.conf
the DDNS Interim-Update-style;
the ignore-the Updates client;
Subnet 192.168.40.0 Netmask 255.255.255.0 {
the option Routers 192.168.40.1;
Subnet mask 255.255.255.0-Option;
Option-name-Domain Servers 114.114.114.114;
Dynamic BOOTP 192.168.40.200 192.168.40.254-Range;
default-Lease Time-60;
max-Lease Time-60;
}
systemctl the restart dhcpd
acquired client ip address

Case II: fixed IP configuration

[root@localhost 桌面]# vim /etc/dhcp/dhcpd.conf
host boss {
  hardware ethernet 00:0c:29:17:b4:32;
  fixed-address 192.168.221.250;
}
host ns2 {
  hardware ethernet 00:0c:29:7f:32:10;
  fixed-address 192.168.40.249;
}

Case 3: multi-segment configuration

Add multiple NICs in a virtual machine

Lsof -i: 67 to view the information specified port

Published 18 original articles · won praise 7 · views 544

Guess you like

Origin blog.csdn.net/weixin_44029504/article/details/102707102