A DHCP Server Installation Package
1 yum -y install dhcp
2. Corresponding Port
IPv4 udp67 and udp68
IPv6 udp546 and udp547
3. File Path
Service name: DHCPD
- Main configuration file:/etc/DHCP/DHCPD. conf
- Template File:/usr/share/doc/DHCP */DHCPD. conf. Example
Iv. configuration file 4.1 common configuration items
1 option domain-name # Set the DNS domain 2 3 option domain-name-servers # Set the DNS server address 4 5 default-lease-time # Set the default lease time, in seconds 6 7 max-lease-time # sets the maximum lease time, in seconds 8 9 ddns-Update-style # sets the DNS update mode, generally, 10 11 authoritative # is not used to identify the authoritative server. The valid identifier 12 13 log-facility local7 # is sent to the local7 Log service.
5. modify configuration items on the server side of instance 5.1
Note: To make the configuration clear, you can delete unnecessary subnet items and only retain the items to be configured. If you do not need to configure DHCP for a specific host, you can also delete the host items.
1 option domain-name-servers 61.153.177.198, 223.5.5.5; # global DNS configuration 2 3 default-lease-time 7200; # global minimum lease time 4 5 max-lease-time 14400; # global maximum lease time 6 7 subnet 192.168.10.0 netmask 255.255.255.0 {# Set CIDR Block 8 9 Range 192.168.10.11 192.168.10.254; # Set the allocable address pool 10 11 option domain-name-servers 61.153.177.198, 223.5.5.5 # It can be configured globally and globally. It can also be configured under subnet. It only takes effect for a specific subnet 12 13 option routers 192.168.10.2; # Set the gateway 14 15 option broadcast-address 192.168.10.255; # broadcast 16 17}
5.2 restart the dncp service on the server
1 [[email protected] DHCP] service DHCPD restart # centos6. * series commands 2 3 [[email protected] DHCP] systemctl restart DHCPD # centos7 series commands
5.3 set the client to DHCP for retrieval
1 TYPE=Ethernet 2 3 BOOTPROTO=dhcp 4 5 DEFROUTE=yes 6 7 NAME=eth0 8 9 ONBOOT=yes
5.4 restart the client NETWORK SERVICE
1 [[email protected] ~]systemctl restart network
5.5 check and verify the client
[[Email protected] ~] # Ifconfig
Eth0: Flags = 4163 <up, broadcast, running, multicast> MTU 1500
Inet 192.168.10.11 netmask 255.255.255.0 broadcast 192.168.10.255
......
5.6 view lease information of a service
1 [[email protected] dhcp]# cat /var/lib/dhcpd/dhcpd.leases 2 3 # The format of this file is documented in the dhcpd.leases(5) manual page. 4 5 # This lease file was written by isc-dhcp-4.2.5 6 7 server-duid "\000\001\000\001\037S(\244\000\014)\371Xn"; 8 9 lease 192.168.10.11 { 10 11 starts 5 2016/08/26 16:25:24; 12 13 ends 5 2016/08/26 18:25:24; 14 15 cltt 5 2016/08/26 16:25:24; 16 17 binding state active; 18 19 next binding state free; 20 21 rewind binding state free; 22 23 hardware ethernet 00:50:56:36:ad:b9; 24 25 client-hostname "imxhy"; 26 27 }
Appendix:
Obtain the DHCP Client address:
1 tail -n +4 /var/lib/dhcpd/dhcpd.leases | less | grep -v ‘server-duid‘ | awk ‘BEGIN{RS=ORS="}"}{print $2,$25,$29"\n"}‘ | sed ‘s/}//g‘ | sed ‘s/;//g‘ | sed ‘s/"//g‘ | sort -n | column -t
002. DHCP Configuration