DHCP——dynamic host configuration protocol
动态主机配置协议(给其他客户端分配网络地址)
可自动分配入网参数
IP地址/子网掩码/广播地址
默认网关地址
DN服务器地址
?
获地址租约四次会话
C——>S????DHCP DISCOVER
S——>C????DHCP OFFER
C——>S????DHCP REQUEST
S<——C????DHCP ACK 或 DHCP NACK
?
客户端重启或租约使用时间达到百分之50
发送DHCP REQUSTT包,若续航成功可继续战胜当前的IP 地址,并重新计算租约时间 ,若续租失败也扔然使用当前的IP 地址
租约使用时间达到百分之87.5
发送DHCP DISCOVERY包,尝试获取新的IP地址租约,若世功则改用新地址,否则使用现有地址到租约过期后释放
?
租期————租约时间
允许客户机租用IP地址的时间期限,单位为秒
作用域
分配给客户机的IP地址所在的网段
地址池
用来动态分配的IP地址的范围
?
实验
服务器
[[email protected] ~]# yum install dhcp
主配置文件 /etc/dhcp/dhcpd.conf
样例/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
执行程序/usr/sbin/dhcpd
服务脚本 /etc/init.d/dhcpd
执行参数配置 /etc/sysconfig/dhcpd
?
[[email protected] ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
default-lease-time 600;????默认租期
max-lease-time 7200;????最大租期
option domain-name-servers IP,IP;????定义DNS服务器
?
subnet 192.168.100.0 netmask 255.255.255.0 {????????定义网络作用域
range 192.168.100.150 192.168.100.200;????range????定义地址池
option routers 192.168.100.100;????routers定义网关
option domain-name-servers 192.168.100.100;
}
?
注意????DHCP服务器至少要定义一个与本机网卡同一网段的subnet
?
客户端————地址为150
?
[[email protected] ~]# tail /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=‘eth0‘
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp????????改为DHCP为动态获取地址
?
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 192.168.100.100 0.0.0.0 UG 0 0 0 eth0
?
查看动态获取IP 详细过程信息
[[email protected] ~]# dhclient –d
?
查看已获取的IP租约
[[email protected] ~]# cat /var/lib/dhclient/dhclient-eth0.leases
lease {
interface "eth0";
fixed-address 192.168.100.150;
option subnet-mask 255.255.255.0;
option dhcp-lease-time 600;
option routers 192.168.100.100;
option dhcp-message-type 5;
option dhcp-server-identifier 192.168.100.100;
option domain-name-servers 192.168.100.100;
option domain-name "example.org";
renew 6 2016/08/20 03:56:40;
rebind 6 2016/08/20 04:01:06;
expire 6 2016/08/20 04:02:21;
}
lease {
interface "eth0";
fixed-address 192.168.100.150;
option subnet-mask 255.255.255.0;
option routers 192.168.100.100;
option dhcp-lease-time 600;
option dhcp-message-type 5;
option domain-name-servers 192.168.100.100;
option dhcp-server-identifier 192.168.100.100;
option domain-name "example.org";
renew 6 2016/08/20 03:56:57;
rebind 6 2016/08/20 04:01:48;
expire 6 2016/08/20 04:03:03;
}
?
服务器查看
[[email protected] ~]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1
?
server-duid "\000\001\000\001\037J\217o\000\014)q\004p";
?
lease 192.168.100.150 {
starts 6 2016/08/20 03:48:15;
ends 6 2016/08/20 03:58:15;
cltt 6 2016/08/20 03:48:15;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:34:74:19;
}
lease 192.168.100.150 {
starts 6 2016/08/20 03:52:21;
ends 6 2016/08/20 04:02:21;
cltt 6 2016/08/20 03:52:21;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:34:74:19;
}
lease 192.168.100.150 {
starts 6 2016/08/20 03:53:02;
ends 6 2016/08/20 04:03:02;
cltt 6 2016/08/20 03:53:02;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:34:74:19;
}
lease 192.168.100.150 {
starts 6 2016/08/20 03:56:56;
ends 6 2016/08/20 04:06:56;
cltt 6 2016/08/20 03:56:56;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:34:74:19;
}