DHCP服务原理及配置

一、DHCP(Dynamic Host Configuration Protocol)动态主机配置协议
1、发展:
Bootp (引导协议)  无盘工作站技术需要(特点:动态分配,但一次性给予不收回)----》dhcp(基于udp动态分配,租约lease,收回)


注:RARP反向地址解析协议


2、c/s端进程
udp-server:67(dhcp)
udp-client:68号端口(dhclient)

过程:(4个数据包)
dhcp Discovery  广播
Dhcp Offer      响应
dhcp Request    请求
Dhcp Ack        确认<-->NAK

lease租约 续租:T*50%,75%,87.5%----有ip,单播交流
release释放
归还:到期,关机,手动释放

局域网内以广播形式实现
ARP与RARP协议交流
响应速度 
服务器与客户端要在同一个网段

3、
1)dhcp,dhcpd进程
2)主配置文件/etc/dhcpd.conf
  辅助配置/etc/sysconfig/dhcpd(DHCPDARGS=eth0)指定只监听eth0网卡
3)服务脚本/etc/init.d/dhcpd       service dhcpd configtest
4)样本文件 /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
cp dhcpd.conf.sample /etc/dhcpd.conf


4、/etc/dhcpd.conf
必须有一个subnet子网与服务器网卡在同一网段,可有多个subnet作用域
option
range 地址池 
host name   为某主机指定预留ip
hardware ethernet 某主机mac
fixed-address 不能是地址池内地址

5、客户端测试
udp 68---dhclient
dhclient -d eth0  调试用,-d前台显示过程
killall dhclient  然后 dhclient eth0

6、固定DNS
ifcfg-eth0 
PEERDNS=no


7、租约信息
/var/lib/dhcpd/dhcpd.leases当前所有主机在此获得ip信息



8、定义主机类别并分配ip
如class "vmware" {
match if substring (hardware, 1, 3) = 00:0c:29;
}

  class "microsoft-clients" {
match if substring (option vendor-class-identifier,0,4) = "MSFT"; //供应商类别标识
option routers 192.168.0.254;
option domain-name-servers 202.102.224.68, 202.102.227.68;
}

   pool {
allow members of "vmware";
range 192.168.0.91 192.168.0.110;
}
   pool {
deny members of "vmware";
allow-members of "microsoft-clients";
range 192.168.0.202 192.168.0.252;
}




二、dhcprelay中继(使用一个dhcp server,使用中继同时为多个网络分配ip)
/etc/init.d/dhcrelay

网络模型:
1)
dhcp server:
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.1;
option domain-name "a.com";
option subnet-mask 255.255.255.0;
range 192.168.100.11 192.168.100.20;
}

route add default gw 192.168.10.7
2)
dhcp relay:
echo 1 > /proc/sys/net/ipv4/ip_forward   //打开路由功能,实现不同网段信息交换
vim /etc/sysconfig/dhcrelay.conf
INTERFACES="eth0 eth1"
DHCPSERVERS="192.168.10.6"



注:
网络连接方式,relay要static,ipv4.ip_forward=1,dhcp server设置到中继网关,/etc/sysconfig/sysctl.conf


你可能感兴趣的:(linux,职场,DHCP,休闲)