1.环境需求:
网段:192.168.84.0/24 网关:192.168.84.10 DNS:61.235.70.252
每个IP默认租约:2天 最长为5天
分配范围:192.168.84.100-192.168.84.200 其他保留
为主机MAC 00-0C-29-25-3B-55  固定分配:192.168.84.88
 
2.配置/etc/dhcpd.conf
由于默认/etc/dhcpd.conf 为空的,可以参考/usr/share/doc/dhcp*/dhcpd.conf.sample 范本。
可以直接复制成/etc/dhcpd.conf
[root@server ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
配置文件如下:
[root@server ~]# cat /etc/dhcpd.conf 
 
  
  1. ddns-update-style none;    #不要更新DDNS  
  2. ignore client-updates;    #忽略客户端更新 
  3. subnet 192.168.84.0 netmask 255.255.255.0 {        #网段设置 
  4. # --- default gateway  
  5.         option routers                  192.168.84.10;        #网关  
  6.         option subnet-mask              255.255.255.0;        #子网掩码 
  7.         option nis-domain               "Server.org";        #NIS的参数(可注释)  
  8.         option domain-name              "Server.org";        #/etc/resolvconf 搜索域  
  9.         option domain-name-servers      61.235.70.252;    #DNS 
  10.         option time-offset              -18000; # Eastern Standard Time  
  11. #       option ntp-servers              192.168.84.10;  
  12. #       option netbios-name-servers     192.168.84.10;  
  13. # --- Selects point-to-point node (default is hybrid). Don't change this unless  
  14. # -- you understand Netbios very well  
  15. #       option netbios-node-type 2; 
  16.         range dynamic-bootp 192.168.84.100 192.168.84.200;  
  17.         default-lease-time 172800;        #默认租约2天,以秒为单位  
  18.         max-lease-time 432000;        #最长租约5天,以秒为单位 
  19.         # we want the nameserver to appear at a fixed address  
  20.         host ns {                            #固定分配  
  21.                 hardware ethernet 00:0C:29:25:3B:55;        #固定分配电脑的MAC  
  22.                 fixed-address 192.168.84.88;            #要固定分的IP  
  23.         }  
  24. }  
完成配置之后,就启动DHCP服务
[root@server ~]# /etc/init.d/dhcpd start
 
3.测试客户机分配情况
p_w_picpath
固定分配的电脑 MAC为: 00-0C-29-25-3B-55
p_w_picpath 
 
4.查看租约信息
[root@server ~]# cat /var/lib/dhcpd/dhcpd.leases
lease 192.168.84.128 {
  starts 3 2011/01/05 02:09:04;
  ends 3 2011/01/05 02:10:39;
  tstp 3 2011/01/05 02:10:39;
  binding state free;
  hardware ethernet 00:0c:29:25:3b:55;
  uid "\001\000\014)%;U";
}
lease 192.168.84.200 {
  starts 3 2011/01/05 02:20:41;
  ends 5 2011/01/07 02:20:41;
  tstp 5 2011/01/07 02:20:41;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:25:3b:54;
  uid "\001\000\014)%;T";
  client-hostname "lyy-b8a4287ba95";
}
 
经过以上配置,一个简单的DCHP实例就完成了
解决早期版本linux多网卡同时监听DHCP,导致分配出错问题。
[root@server ~]# cat /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS="eth1"        #修改成要监听的网段