DHCP:Dynamic Host Configuration Protocol前身是bootp
lease:租约
续租:租约到一半的时候就要申请续租
广播:第一个响应的服务器
广播申请,广播响应
广播回复确认
IP:
MASK:
GATEWAY:
DNS:
Client----->DHCPDISCOVER
DHCPOFER<--------Server
Client----->DHCPREQUEST
DHCPACK<-----Server
以上都广播报文
续租:
Client----->DHCPREQUEST
DHCPACK<-------Server
以上为单播
DHCP不能跨网段进行
需要配置路由器的DHCP-RELAY,DHCP中继
DHCP分配的网段要在某一个网卡的地址在同一网段内
[root@salt-master ~]# yum install dhcp
[root@salt-master ~]# rpm -ql dhcp
/etc/dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/portreserve/dhcpd
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcpd6
/etc/rc.d/init.d/dhcrelay
/etc/rc.d/init.d/dhcrelay6
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcpd6
/etc/sysconfig/dhcrelay
/etc/sysconfig/dhcrelay6
/usr/bin/omshell
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.1.1
/usr/share/doc/dhcp-4.1.1/3.0b1-lease-convert
/usr/share/doc/dhcp-4.1.1/IANA-arp-parameters
/usr/share/doc/dhcp-4.1.1/README.ldap
/usr/share/doc/dhcp-4.1.1/api+protocol
/usr/share/doc/dhcp-4.1.1/dhclient-tz-exithook.sh
/usr/share/doc/dhcp-4.1.1/dhcpd-conf-to-ldap
/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
/usr/share/doc/dhcp-4.1.1/dhcpd6.conf.sample
/usr/share/doc/dhcp-4.1.1/draft-ietf-dhc-ldap-schema-01.txt
/usr/share/doc/dhcp-4.1.1/ms2isc
/usr/share/doc/dhcp-4.1.1/ms2isc/Registry.perlmodule
/usr/share/doc/dhcp-4.1.1/ms2isc/ms2isc.pl
/usr/share/doc/dhcp-4.1.1/ms2isc/readme.txt
/usr/share/doc/dhcp-4.1.1/sethostname.sh
/usr/share/doc/dhcp-4.1.1/solaris.init
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.lease
[root@salt-master ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp: overwrite `/etc/dhcp/dhcpd.conf'? y
DHCP-Server:UDP/67
DHCP-Client:UDP/68
[root@salt-master ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "uplooking.com";
option domain-name-servers 192.168.1.200;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range 192.168.1.220 192.168.1.223;
default-lease-time 21600;
max-lease-time 43200;
}
各行详细解释
Default-lease-time 21600; 默认租约时间
Max-lease-time 43200; 最大租约时间
Option domain-name "123.com"; 域名服务器的名称
Option domaini-servers 192.168.0.1 默认域名服务的ip地址
Sub 后从“{”开始 到最后一个“}”结束表示子网属性。其主要配置只对大括号里的内容有效。一个配置文件可以有多个子网属性。
Sub 192.168.0.0 netmask 255.255.255.0 ; (意思是我所分配的ip地址所在的网段
为192.168.0.0 子网掩码为255.255.255.0 )
Range 192.168.0.5 192.168.0.100; (分配的ip地址范围为192.168.0.5到
192.168.0.100)
Option subnet-mask 255.255.255.0 ; (分配ip地址的子网掩码为 255.255.255.0
Option routers 192.168.0.3; (分给客户机的网关为192.168.0.3)主:图中的option router 应改成option routers 在这图片不再更改了。此网管不能包含在之前range的范围
有时候我们需要为某一个机器配置固定的ip地址,而下面的配置选项满足了这一要求:
Host server01 {
Hardware ethernet b0:c0:12:f2:a3:a4;
Fixed-address 192.168.0.100;
}
具体含义和简单意思是“我们给客户机mac地址为b0;c0;12;f2;a3;a4所配置的ip地址为192.168.0.100”。
[root@salt-master ~]# /etc/init.d/dhcpd start
Starting dhcpd: [ OK ]
[root@salt-master ~]# netstat -anutlp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 2085/dhcpd
找一台服务器由于多个dhcp的存在他可能不会选则自己的服务器或者你想给服务器指定IP地址
[root@salt-master ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "uplooking.com";
option domain-name-servers 192.168.1.200;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range 192.168.1.223 192.168.1.224;
default-lease-time 21600;
max-lease-time 43200;
host ns2 {
hardware ethernet 00:0C:29:38:1E:F7;
fixed-address 192.168.1.201;
}
}
添加host选项
注意这个地址一定部在range的范围之内
另外有专用的话等级比自动分配要高
客户端
[root@salt-master ~]# dhclient -h
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Usage: dhclient [-4|-6] [-SNTP1dvrx] [-nw] [-p
[-cf config-file] [-lf lease-file][-pf pid-file] [-e VAR=val]
[-I
[-H
[-V
[-R
[-sf script-file] [interface]
客户端直接
dhclient命令就可以用了手动获取dhcp分配地址
dhclient -d选项工作在前台