DHCP (Dynamic Host Configuration Protocol) is commonly used in large local network environment, the main role is centralized management, assigning IP address, so that the host in the network environment to obtain the dynamic IP address, gateway address , DNS server address and other information, and can increase the usage of the address.
C/S mode
Server:dhcp Server (running DHCP Service) UDP service: 67
Client:dhcp Client (running DHCP program) UDP service: 68
UDP: Suitable for sending smaller data messages, and high timeliness requirements
workflow as shown:650) this.width=650; "Src=" http://s4.51cto.com/wyfs02/M01/80/4C/ Wkiom1c9ydbsmh2haajagj1vnr8087.png "title=" Untitled.png "alt=" Wkiom1c9ydbsmh2haajagj1vnr8087.png "/>
When the client gets a valid address, DHCP sends a 169.254.x.x as the local address
Installation configuration:
[[email protected] ~]# Yum install DHCP
Configuration file :
[Email protected] dhcp]# pwd/etc/dhcp[[email protected] dhcp]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample Dhcpd.conf
configuration file Description:
[[email protected] dhcp]# vim dhcpd.conf#log-facility local7; #日志/var/log/ boot.log #全局地址分配属性: Option starts #option domain-name #域名搜索列表, similar to the searchoption in/etc/resolv.conf #domain-name-servers # Name server address, multiple words separated by commas #option routers #网关 #option broadcasst-address # Broadcast Address #option subnet-mask #子网掩码 #default-lease-time #默认租约期限, generally this entry takes effect (in seconds) # max-lease-time #最大租约期限 (in seconds) #range START_IP END_IP #地址池 (You can specify more than one range in subnet, but multiple ranges define an IP range that cannot be duplicated) #子网配置: typically each scope is defined by a subnet #subnet network_addr netmask netmask {#range #option routers #}# Host configuration: Usually fixed for a specific MAC address assigned an address #host ' Host id ' {#hardware ethernet 08:00:07:26:c0:a5;# fixed-address ip;#}
service process:
[[email protected] ~]# /etc/init.d/dhcpd restartshutting down dhcpd: [ OK ]Starting dhcpd: [ OK ][[email protected] ~]# ps -ef |grep dhcpdhcpd 1952 1 0 03:53 ? 00:00:00 /usr/sbin/dhcpd -user dhcpd -group dhcpd
Service Port:
[[email protected] ~]# ss -lnupstate recv-q send-q Local Address:Port Peer Address:Port UNCONN 0 0 *:67 *:* users: (("DHCPD", 1952,7)) unconn 0 0 *:68 *:* users: (("Dhclient", 2066,6))
Demo
[[email protected] dhcp]# VIM dhcpd.conf# global variable option domain-name "Marvin"; option Domain-name-servers 114.114.114.114,8.8.8.8;option Routers 192.168.1.1;option broadcast-address 192.168.1.255;default-lease-time 600; Max-lease-time 7200;log-facility local7;subnet 192.168.1.0 netmask 255.255.255.0{range 192.168.1.201 192.168.1.240; Host sherry{# based on host MAC configuration fixed IP hardware Ethernet 00:0c:29:3c:e2:60; #sherry主机的mac地址 fixed-address 192.168.1.221; #给sherry主机分配固定ip}}
Log
service error:
[[email protected] /]# tail -f /var/log/messages may 19 06:24:47 marvin dhcpd: Dynamic and static leases present for 192.168.1.221.may 19 06:24:47 marvin dhcpd: remove host declaration sherry or remove 192.168.1.221may 19 06:24:47 marvin dhcpd: from The dynamic address pool for 192.168.1.0/24may 19 06:24:47 marvin dhcpd: DHCPREQUEST for 192.168.1.221 from 00:0c:29:3c:e2:60 via eth1may 19 06:24:47 marvin dhcpd: dhcpack on 192.168.1.221 to 00:0c:29:3c:e2:60 via eth1may 19 06:29:43 marvin dhcpd: dynamic and static leases present for 192.168.1.221.May 19 06:29:43 marvin Dhcpd: remove host declaration sherry or remove 192.168.1.221may 19 06:29:43 marvin dhcpd: from the dynamic address pool for 192.168.1.0/24may 19 06:29:43 Marvin dhcpd: dhcprequest for 192.168.1.221 from 00:0c:29:3c:e2:60 via eth1may 19 06:29:43 marvin dhcpd: dhcpack on 192.168.1.221 to 00:0c:29:3c:e2:60 via eth1
Service log:
[[email protected] /]# tail -f /var/log/boot.log may 19 06:24:47 Marvin dhcpd: dynamic and static leases present for 192.168.1.221.may 19 06:24:47 marvin dhcpd: remove host declaration sherry or remove 192.168.1.221May 19 06:24:47 marvin dhcpd: from the DYNAMIC ADDRESS POOL FOR 192.168.1.0/24MAY 19 06:24:47 MARVIN DHCPD: dhcprequest for 192.168.1.221 from 00:0c:29:3c:e2:60 via eth1may 19 06:24:47 marvin dhcpd: dhcpack on 192.168.1.221 to 00:0c:29:3c:e2:60 via eth1May 19 06:29:43 marvin dhcpd: Dynamic and static Leases present for 192.168.1.221.may 19 06:29:43 marvin dhcpd: remove host declaration&nBsp;sherry or remove 192.168.1.221may 19 06:29:43 marvin dhcpd: from the dynamic address pool for 192.168.1.0/24May 19 06:29:43 Marvin dhcpd: dhcprequest for 192.168.1.221 from 00:0c:29:3c:e2:60 via eth1may 19 06:29:43 marvin dhcpd: dhcpack on 192.168.1.221 to 00:0c:29:3c:e2:60 via eth1
DHCP Configuration fixed IP