一、原理

DHCP 是 Dynamic Host Configuration Protocol(动态主机配置协议)缩写,它的前身是 BOOTP。BOOTP 原本是用于无磁盘主机连接的网络上面的:网络主机使用 BOOT ROM 而不是磁盘启动并连接上网络,BOOTP则可以自动地为那些主机设定 TCP/IP 环境。但 BOOTP 有一个缺点:您在设定前须事先获得客户端的硬件地址,而且,与 IP 的对应是静态的。换而言之,BOOTP 非常缺乏 "动态性" ,若在有限的 IP 资源环境中,BOOTP 的一对一对应会造成非常严重的资源浪费。DHCP 可以说是 BOOTP 的增强版本,它分为两个部份:一个是服务器端,而另一个是客户端。所有的 IP 网络设定数据都由 DHCP 服务器集中管理,并负责处理客户端的 DHCP 要求;而客户端则会使用从服务器分配下来的IP环境数据。比较起 BOOTP ,DHCP 透过 "租约" 的概念,有效且动态的分配客户端的 TCP/IP 设定,而且,作为兼容考虑,DHCP 也完全照顾了 BOOTP Client 的需求。DHCP 的分配形式 首先,必须至少有一台 DHCP 工作在网络上面,它会监听网络的 DHCP 请求,并与客户端磋商 TCP/IP的设定环境。

它提供三种 IP 定位方式: Manual Allocation 人工分配,获得的IP也叫静态地址,网络管理员为某些少数特定的在网计算机或者网络设备绑定固定IP地址,且地址不会过期。同一个路由器一般可以通过设置来划分静态地址和动态地址的IP段,比如一般家用TP-LINK路由器,常见的是从192.168.1.100~192.168.1.254,这样如果你的电脑是自动获得IP的话,一般就是192.168.1.100,下一台电脑就会由DHCP自动分到为192.168.1.101。而192.168.1.2~192.168.1.99为手动配置IP段。

Automatic Allocation 自动分配,其情形是:一旦 DHCP 客户端第一次成功的从 DHCP 服务器端租用到 IP 地址之后,就永远使用这个地址。

Dynamic Allocation 动态分配,当 DHCP客户端 第一次从 DHCP 服务器端租用到 IP 地址之后,并非永久的使用该地址,只要租约到期,客户端就得释放(release)这个 IP 地址,以给其它工作站使用。当然,客户端可以比其它主机更优先的更新(renew)租约,或是租用其它的 IP 地址。动态分配显然比手动 分配更加灵活,尤其是当您的实际 IP 地址不足的时候,例如:您是一家 ISP ,只能提供 200 个IP地址用来给拨接客户,但并不意味着您的客户最多只能有 200 个。因为要知道,您的客户们不可能全部同一时间上网的,除了他们各自的行为习惯的不同,也有可能是电话线路的限制。这样,您就可以将这 200 个地址,轮流的租用给拨接上来的客户使用了。这也是为什么当您查看 IP 地址的时候,会因每次拨接而不同的原因了(除非您申请的是一个固定 IP ,通常的 ISP 都可以满足这样的要求,这或许要另外收费)。当然,ISP 不一定使用 DHCP 来分配地址,但这个概念和使用 IP Pool 的原理是一样的。DHCP 除了能动态的设定 IP 地址之外,还可以将一些 IP 保留下来给一些特殊用途的机器使用,它可以按照硬件地址来固定的分配 IP 地址,这样可以给您更大的设计空间。同时,DHCP 还可以帮客户端指定 router、netmask、DNS Server、WINS Server、等等项目,您在客户端上面,除了将 DHCP 选项打勾之外,几乎无需做任何的 IP 环境设定。 DHCP SERVER与CLIENT的标准交互过程:

p_w_picpath

1、CLIENT首先发出广播的DHCPDISCOVER报文,广播的目的是让DHCP SERVER能够收到这个请求报文。在这个报文中,CLIENT可以在“选项”字段中加入“request paramter list”选项,表明自己想要获得的各种参数,而且四个IP地址字段都必须为0。

2、由于DHCPDISCOVER报文是广播,那么所有的DHCP SERVER都能够收到,所有的DHCP SERVER都会响应一个DHCPOFFER报文,其中“你的IP地址”字段就是DHCP SERVER能够提供给CLIENT使用的IP地址,而且DHCP SERVER会把自己的IP地址放在“选项”字段中以便CLIENT区分不同的DHCP SERVER,发出此报文后,在DHCP SERVER上就会存在一个已分配IP地址的记录。

3、CLIENT能够收到所有的DHCPOFFER报文,但CLIEN只能处理其中的一个,一般的原则是CLIENT接收、处理最先收到的那个DHCPOFFER报文。CLIENT会再发出一个广播的DHCPREQUEST报文,在“选项”字段中会加入选中的DHCP SERVER的IP地址和用户想要的IP地址,之所以广播是因为要通知所有的DHCP SERVER进行相应的处理。

4、DHCP SERVER收到DHCPREQUEST报文,判断“选项”字段中的DHCP SERVER的IP地址是否与自己的地址相同,不相同,则不做任何处理,如果自己发出过DHCPOFFER报文,则清除相应IP地址记录;当“选项”字段中的DHCP SERVER的IP地址是与自己的IP地址相同时,DHCP SERVER就会响应一个DHCPACK报文,其内容同DHCPOFFER类似,并在“选项”字段中增加了IP地址使用租期选项。

5、CLIENT收到DHCPACK报文后(经过上面的处理后,有且只有一个DHCPACK报文),会检查DHCP SERVER分配给自己的IP地址是否能够使用,如在以太网类型的网络中,CLIENT会发出免费的ARP请求来确定DHCP SERVER分配的IP地址是否已经被别人使用,如果可以使用,则CLIENT成功获得IP地址,并根据IP地址使用租期自动启动续延过程。

6、如果CLIENT发现DHCP SERVER分配的IP地址已经被别人使用,则CLIENT会发出DHCPDECLINE报文通知DHCP SERVER禁用这个IP地址以免引起IP地址冲突。然后CLIENT又开始新的DHCP过程,从第1步开始。

7、当CLIENT成功获取IP地址后,会根据IP地址使用租期自动启动续延过程,在使用租期过去50%时刻处,向DHCP SERVER发送单播DHCPREQUEST报文续延租期,如果成功即收到DHCP SERVER的DHCPACK报文,则租期相应向前延长,如果失败即没有收到DHCPACK报文,则CLIENT继续使用这个IP地址。在使用租期过去87.5%时刻处,向DHCP SERVER发送广播DHCPREQUEST报文续延租期,如果成功即收到DHCP SERVER的DHCPACK报文,则租期相应向前延长;如果失败即没有收到DHCPACK报文,则CLIENT继续使用这个IP地址。在使用租期到期时,CLIENT应自动放弃使用这个IP地址,并开始新的DHCP过程,从第1步开始。

8、CLIENT在成功获取IP地址后,随时可以通过发送DHCPRELEASE报文释放自己的IP地址,DHCP SERVER收到DHCPRELEASE报文后,会回收相应的IP地址重新分配。当存在DHCP RELAY时,所有的DHCP报文都会经过DHCP RELAY进行转发,整个DHCP交互过程同上面类型,只是在报文封装时,稍有不同。

由上面的叙述可以看出,DHCP SERVER的行为完全由CLIENT来驱动,DHCP SERVER无法控制CLIENT的行为。因此DHCP协议的安全性比较差。

二、拓扑

p_w_picpath

三、应用举例

首先应安装dhcp服务器

[root@localhost ~]# mkdir /mnt/cdrom  //建立光盘挂载目录

[root@localhost ~]# mount /dev/cdrom  /mnt/cdrom //挂载光盘

[root@localhost ~]# cd /mnt/cdrom/Server/   //进入服务目录

[root@localhost Server]# rpm -ivh dhcp-3.0.5-21.el5.i386.rpm  //安装dhcp服务器
Preparing...                ########################################### [100%]
   1:dhcp                   ########################################### [100%]
[root@localhost Server]# vim /etc/dhcpd.conf   //编辑dhcp配置文件

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample 
#
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
~                                                                                    
:r /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample   //读取该目录下的配置样本文件

 

(1)单个作用域的配置

#
ddns-update-style interim;   //配置使用过渡性dhcp-dns互动更新模式
ignore client-updates; //忽略客户端更新

subnet 192.168.145.0 netmask 255.255.255.0 {  //设置子网声明

# --- default gateway
        option routers                  192.168.145.254; //网关
        option subnet-mask              255.255.255.0; //子网掩码

        option nis-domain               "domain.org";  //为客户设置NIS域
        option domain-name              "domain.org"; // 为客户设置域名
        option domain-name-servers      222.88.88.88;  //为客户设置域名服务器

        option time-offset              -18000; # Eastern Standard Time //设置偏移时间
#       option ntp-servers              192.168.1.1; //设置ntp服务器
#       option netbios-name-servers     192.168.1.1; //设置wins服务器
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#       option netbios-node-type 2;

        range dynamic-bootp 192.168.145.2 192.168.145.253; //地址池
       default-lease-time 21600; //地址租期
        max-lease-time 43200;
    //客户端最长的地址租期

        # we want the nameserver to appear at a fixed address
        host ns {       //可以指定ip地址和mac地址的绑定
                next-server marvin.redhat.com;
                hardware ethernet 12:34:56:78:AB:CD;
                fixed-address 207.175.42.254;
        }
}
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample 
#
-- 插入 --

[root@localhost ~]# service dhcpd start   //启动dhcp服务
启动 dhcpd:                                               [确定]
[root@localhost ~]#

测试   

   p_w_picpath        

(2)超级作用域的配置

当局域网中的主机太多超过254台时,一个子网已经不能满足需求。我们需要配置超级作用域。

这时候局域网中没有划分vlan。

1 #
  2 ddns-update-style interim;
  3 ignore client-updates;
  4 shared-network abc {  //超级作用域名称
  5 subnet 192.168.145.0 netmask 255.255.255.0 {
  6
  7 # --- default gateway
  8         option routers                  192.168.145.254;
  9         option subnet-mask              255.255.255.0;
10
11         option nis-domain               "domain.org";
12         option domain-name              "domain.org";
13         option domain-name-servers      222.88.88.88;
14
15         option time-offset              -18000; # Eastern Standard Time
16 #       option ntp-servers              192.168.1.1;
17 #       option netbios-name-servers     192.168.1.1;
18 # --- Selects point-to-point node (default is hybrid). Don't change this unless
19 # -- you understand Netbios very well
20 #       option netbios-node-type 2;
21
22         range dynamic-bootp 192.168.145.2 192.168.145.253;
23         default-lease-time 21600;
24         max-lease-time 43200;
25
26         # we want the nameserver to appear at a fixed address
27         host ns {
28                 next-server marvin.redhat.com;
29                 hardware ethernet 12:34:56:78:AB:CD;
30                 fixed-address 207.175.42.254;
31         }
32 }
 33 subnet 192.168.146.0 netmask 255.255.255.0 {
34
35         option routers                  192.168.146.254;
36         option subnet-mask              255.255.255.0;
37         option domain-name-servers      222.88.88.88,222.85.85.85; //首选dns,备用dns。
38         range dynamic-bootp 192.168.146.2 192.168.146.253;
39         default-lease-time 21600;
40         max-lease-time 43200;
41 }
42 }
43 # DHCP Server Configuration file.
44 #   see /usr/share/doc/dhcp*/dhcpd.conf.sample 
45 #

测试

dhcp服务器是把第一个作用域的地址分放完全后才会使用第二个作用域。由于资源限制,把每个地址池设置了一个地址以供测试。

range dynamic-bootp 192.168.145.2 192.168.145.2;

range dynamic-bootp 192.168.146.2 192.168.146.2;

客户端1

p_w_picpath

客户端2

p_w_picpath

(3)dhcp中继

当局网需要划分vlan时,我们希望vlan10区域得到192.168.10.0 网段地址,vlan20区域得到192.168.20.0网段地址。而服务器地址往往是静态的。

当然我们可以在每个vlan区域架设dhcp服务器。显然这是一种浪费。我们可以采取dhcp中继实现一台dhcp服务器实现我们的需求。

p_w_picpath

由于资源限制,此案例采用在虚拟机下实现。

e0.1  vm3区域  eth2

e0.2  vm2区域  eth1

e0.3  vm1区域  eth0

使用linux主机充当路由器,添加三块网卡。

路由器配置

添加网卡

p_w_picpath

重启主机(路由器)

p_w_picpath

p_w_picpath

p_w_picpath

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:91:2D:4B 
          inet addr:192.168.145.254  Bcast:192.168.145.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe91:2d4b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:318 errors:0 dropped:0 overruns:0 frame:0
          TX packets:270 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:26860 (26.2 KiB)  TX bytes:50162 (48.9 KiB)
          Interrupt:67 Base address:0x2000

eth1      Link encap:Ethernet  HWaddr 00:0C:29:91:2D:55 
          inet addr:192.168.20.254  Bcast:192.168.20.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe91:2d55/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:130 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:31062 (30.3 KiB)
          Interrupt:67 Base address:0x2080

eth2      Link encap:Ethernet  HWaddr 00:0C:29:91:2D:5F 
          inet addr:192.168.10.254  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe91:2d5f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:71 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:15995 (15.6 KiB)
          Interrupt:75 Base address:0x2400

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:760 (760.0 b)  TX bytes:760 (760.0 b)

root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.145.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth2
[root@localhost ~]# vim /etc/sysctl.conf 

1 # Kernel sysctl configuration file for Red Hat Linux
  2 #
  3 # For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
  4 # sysctl.conf(5) for more details.
  5
  6 # Controls IP packet forwarding
  7 net.ipv4.ip_forward = 1  //打开路由转发功能
  8
  9 # Controls source route verification
10 net.ipv4.conf.default.rp_filter = 1
11
12 # Do not accept source routing
13 net.ipv4.conf.default.accept_source_route = 0
14
15 # Controls the System Request debugging functi

由于dhcp中继依赖于dhcp服务器。我们需要安装dhcp服务器。

root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh dhcp-3.0.5-18.el5.i386.rpm
Preparing...                ########################################### [100%]
   1:dhcp                   ########################################### [100%]
[root@localhost Server]# vim /etc/sysconfig/dhcrelay //编辑dhcp中继配置文件

# Command line options here
 

INTERFACES="eth0 eth1 eth2"
DHCPSERVERS="192.168.145.100"

~
                                                                                    
~    

[root@localhost Server]# service dhcrelay start  //启动dhcrelay 服务
启动 dhcrelay:                                            [确定]
[root@localhost Server]# chkconfig  dhcrelay on //设置开机启动

服务器配置 

 

1 #
2 ddns-update-style interim;
3 ignore client-updates;
4 subnet 192.168.20.0 netmask 255.255.255.0 { //vlan20作用域
5
6 option routers 192.168.20.254;
7 option subnet-mask 255.255.255.0;
8
9 option domain-name "vlan20.com";
10 option domain-name-servers 222.88.88.88;
11
12 range dynamic-bootp 192.168.20.2 192.168.20.253;
13 default-lease-time 21600;
14 max-lease-time 43200;
15 host ns { // 主机记录不能相同
16 next-server marvin.redhat.com;
17 hardware ethernet 12:34:56:78:AB:CD;
18 fixed-address 207.175.42.254;
19 }
20 }
21 subnet 192.168.10.0 netmask 255.255.255.0 { //vlan10作用域
22
23 option routers 192.168.10.254;
24 option subnet-mask 255.255.255.0;
25
26 option domain-name "vlan10.com";
27 option domain-name-servers 222.88.88.88;
28
29 range dynamic-bootp 192.168.10.2 192.168.10.253;
30 default-lease-time 21600;
31 max-lease-time 43200;
32 host www {
33 next-server marvin.redhat.com;
34 hardware ethernet 12:34:56:78:AB:CD;
35 fixed-address 207.175.42.254;
36 }
37 }
38 subnet 192.168.145.0 netmask 255.255.255.0 { //本机所在作用域声明,同windows不同,空白作用域声明。
39
40 }
41 # DHCP Server Configuration file.
42 # see /usr/share/doc/dhcp*/dhcpd.conf.sample
43 #
-- 插入 -- 43,1 底端

[root@localhost ~]# service dhcpd restart
关闭 dhcpd:                                               [确定]
启动 dhcpd:                                               [确定]

测试

vm2区域客户机测试

 360截图20120814174634842

vm3客户机测试

 360截图20120814174933201

这时候我们提出疑问,dhcp报文不是广播吗?路由器不是隔离广播吗?事实上,dhcp中继的实质就是把广播变成单播。

在服务器端和主机(路由器)进行抓包,首先安装抓包工具。

[root@localhost Server]# rpm -ivh wireshark-1.0.8-1.el5_3.1.i386.rpm
error: Failed dependencies:
    libsmi.so.2 is needed by wireshark-1.0.8-1.el5_3.1.i386 //依赖libsmi 模块

[root@localhost Server]# rpm -ivh libsmi-0.4.5-2.el5.i386.rpm
Preparing...                ########################################### [100%]
   1:libsmi                 ########################################### [100%]
[root@localhost Server]# rpm -ivh wireshark-1.0.8-1.el5_3.1.i386.rpm
Preparing...                ########################################### [100%]
   1:wireshark              ########################################### [100%]
[root@localhost Server]#

服务器端

[root@localhost Server]# tshark -ni eth0 -R "udp.port eq 67"
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
  54.439257 192.168.145.254 -> 192.168.145.100 DHCP DHCP Discover - Transaction ID 0x15203ca6
55.661221 192.168.145.100 -> 192.168.10.254 DHCP DHCP Offer    - Transaction ID 0x15203ca6
55.688553 192.168.145.254 -> 192.168.145.100 DHCP DHCP Request  - Transaction ID 0x15203ca6
57.905362 192.168.145.100 -> 192.168.10.254 DHCP DHCP ACK      - Transaction ID 0x15203ca6

vm3客户端

[root@localhost Server]# tshark -ni eth2 -R "udp.port eq 67"
Running as user "root" and group "root". This could be dangerous.
Capturing on eth2
  70.443453      0.0.0.0 -> 255.255.255.255 DHCP DHCP Discover - Transaction ID 0x15203ca6
71.668158 192.168.10.254 -> 192.168.10.253 DHCP DHCP Offer    - Transaction ID 0x15203ca6
71.694506      0.0.0.0 -> 255.255.255.255 DHCP DHCP Request  - Transaction ID 0x15203ca6
73.912807 192.168.10.254 -> 192.168.10.253 DHCP DHCP ACK      - Transaction ID 0x15203ca6

(4)按照客户机的类别分配IP地址

1 #
  2 ddns-update-style interim;
  3 ignore client-updates;
  1 #
  2 ddns-update-style interim;
  3 ignore client-updates;
  4 subnet 192.168.145.0 netmask 255.255.255.0 {
  5 class "microsoft" {
  6         match if substring (option vendor-class-identifier,0,4) = "MSFT";  //微软网卡
  7          option routers      192.168.145.252;
  8        }
  9       
10 class "vm" {  //根据MAC定义匹配虚拟机的类 (虚拟机的网卡类型)
11         match if substring (hardware,1,3) = 00:0c:29;
12          option routers      192.168.145.251;
13        }
14       
15     pool {
16         allow  members of "microsoft";
17         range dynamic-bootp 192.168.145.200  192.168.145.253;
18        
19      }
20         pool {
21         allow members of "vm";
22         range dynamic-bootp 192.168.145.2  192.168.145.99;
-- 插入 --                                                                             7,45         顶端

测试

微软:(采用xp)

p_w_picpath

由于基于微软的规则在前。所以虚拟机下的xp系统得到地址为所配置范围的一个。

虚拟机:(采用linux)

p_w_picpath 

dhcp服务器排错

当我把dns服务器后的引号“;”去掉后

[root@localhost ~]# service dhcpd restart
关闭 dhcpd:                                               [确定]
启动 dhcpd:                                               [失败]
 

1、[root@localhost ~]# grep dhcpd /var/log/messages

Aug 14 11:55:05 localhost dhcpd: Internet Systems Consortium DHCP Server V3.0.5-RedHat
Aug 14 11:55:05 localhost dhcpd: Copyright 2004-2006 Internet Systems Consortium.
Aug 14 11:55:05 localhost dhcpd: All rights reserved.
Aug 14 11:55:05 localhost dhcpd: For info, please visit http://www.isc.org/sw/dhcp/
Aug 14 11:55:05 localhost dhcpd: WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Aug 14 11:55:05 localhost dhcpd: Wrote 0 deleted host decls to leases file.
Aug 14 11:55:05 localhost dhcpd: Wrote 0 new dynamic host decls to leases file.
Aug 14 11:55:05 localhost dhcpd: Wrote 0 leases to leases file.
Aug 14 11:55:05 localhost dhcpd: Listening on LPF/eth0/00:0c:29:1b:e2:73/192.168.145/24
Aug 14 11:55:05 localhost dhcpd: Sending on   LPF/eth0/00:0c:29:1b:e2:73/192.168.145/24
Aug 14 11:55:05 localhost dhcpd: Sending on   Socket/fallback/fallback-net
Aug 14 11:55:06 localhost dhcpd: DHCPDISCOVER from 00:0c:29:91:2d:4b via eth0
Aug 14 11:55:07 localhost dhcpd: DHCPOFFER on 192.168.145.253 to 00:0c:29:91:2d:4b via eth0
Aug 14 11:55:07 localhost dhcpd: DHCPREQUEST for 192.168.145.253 (192.168.145.100) from 00:0c:29:91:2d:4b via eth0
Aug 14 11:55:07 localhost dhcpd: DHCPACK on 192.168.145.253 to 00:0c:29:91:2d:4b via eth0
Aug 14 11:56:15 localhost dhcpd: Internet Systems Consortium DHCP Server V3.0.5-RedHat
Aug 14 11:56:15 localhost dhcpd: Copyright 2004-2006 Internet Systems Consortium.
Aug 14 11:56:15 localhost dhcpd: All rights reserved.
Aug 14 11:56:15 localhost dhcpd: For info, please visit http://www.isc.org/sw/dhcp/
Aug 14 11:56:15 localhost dhcpd: WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Aug 14 11:56:15 localhost dhcpd: Wrote 0 deleted host decls to leases file.
Aug 14 11:56:15 localhost dhcpd: Wrote 0 new dynamic host decls to leases file.
Aug 14 11:56:15 localhost dhcpd: Wrote 1 leases to leases file.
Aug 14 11:56:15 localhost dhcpd: Listening on LPF/eth0/00:0c:29:1b:e2:73/192.168.145/24
Aug 14 11:56:15 localhost dhcpd: Sending on   LPF/eth0/00:0c:29:1b:e2:73/192.168.145/24
Aug 14 11:56:15 localhost dhcpd: Sending on   Socket/fallback/fallback-net
Aug 14 12:54:11 localhost dhcpd: Internet Systems Consortium DHCP Server V3.0.5-RedHat
Aug 14 12:54:11 localhost dhcpd: Copyright 2004-2006 Internet Systems Consortium.
Aug 14 12:54:11 localhost dhcpd: All rights reserved.
Aug 14 12:54:11 localhost dhcpd: For info, please visit http://www.isc.org/sw/dhcp/
Aug 14 12:54:11 localhost dhcpd: /etc/dhcpd.conf line 15: semicolon expected.
Aug 14 12:54:11 localhost dhcpd:     option
Aug 14 12:54:11 localhost dhcpd:         ^

Aug 14 12:54:11 localhost dhcpd: WARNING: Host declarations are global.  They are not limited to the scope you declared them in.
Aug 14 12:54:11 localhost dhcpd: Configuration file errors encountered -- exiting
Aug 14 12:54:11 localhost dhcpd:
Aug 14 12:54:11 localhost dhcpd: If you did not get this software from ftp.isc.org, please
Aug 14 12:54:11 localhost dhcpd: get the latest from ftp.isc.org and install that before
Aug 14 12:54:11 localhost dhcpd: requesting help.

2、[root@localhost ~]# service dhcpd configtest

Internet Systems Consortium DHCP Server V3.0.5-RedHat

Copyright 2004-2006 Internet Systems Consortium.

All rights reserved.

For info, please visit http://www.isc.org/sw/dhcp/

/etc/dhcpd.conf line 15: semicolon expected.

 

If you did not get this software from ftp.isc.org, please


get the latest from ftp.isc.org and install that before
requesting help.

If you did get this software from ftp.isc.org and have not
yet read the README, please read it before requesting help.
If you intend to request help from the dhcp-server@isc.org
mailing list, please read the section on the README about
submitting bug reports and requests for help.

Please do not under any circumstances send requests for
help directly to the authors of this software - please
send them to the appropriate mailing list as described in
the README file.

exiting.
[root@localhost ~]#

当配置文件丢失了

当然可以重新安装,但是又覆盖了原来的文件。可以采用下述方法。

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Server

[root@localhost Server]# ll dhcp*
-r--r--r-- 108 root root 886718 2009-07-16 dhcp-3.0.5-21.el5.i386.rpm
-r--r--r-- 125 root root 134127 2009-07-16 dhcp-devel-3.0.5-21.el5.i386.rpm
-r--r--r-- 108 root root 196554 2009-07-16 dhcpv6-1.0.10-17.el5.i386.rpm
-r--r--r-- 108 root root 125916 2009-07-16 dhcpv6-client-1.0.10-17.el5.i386.rpm
[root@localhost Server]# mkdir -pv /tmp/abc/

[root@localhost Server]# cp dhcp-3.0.5-21.el5.i386.rpm  /tmp/abc

[root@localhost Server]# cd /tmp/abc
[root@localhost abc]# ll
总计 872
-r--r--r-- 1 root root 886718 08-14 16:28 dhcp-3.0.5-21.el5.i386.rpm
[root@localhost abc]# rpm2cpio dhcp-3.0.5-21.el5.i386.rpm |cpio -id
4327 blocks
[root@localhost abc]# ll
总计 884
-r--r--r-- 1 root root 886718 08-14 16:28 dhcp-3.0.5-21.el5.i386.rpm
drwxr-xr-x 4 root root   4096 08-14 16:29 etc
drwxr-xr-x 5 root root   4096 08-14 16:29 usr
drwxr-xr-x 3 root root   4096 08-14 16:29 var

[root@localhost abc]# cp /tmp/abc/etc/dhcpd.conf  /etc/

注:linux系统和window系统dhcp服务不一样,提供地址是从地址池最后一个开始选。

每次修改dhcp配置文件必须重启dhcp服务                         

linux系统dhcp服务器排除地址

例如排除192.168.145.100 地址

range dynamic-bootp 192.168.145.2 192.168.145.99;

range dynamic-bootp 192.168.145.101 192.168.145.253; //地址池
default-lease-time 21600;
max-lease-time 43200;

    option

        ^

WARNING: Host declarations are global.  They are not limited to the scope you declared them in.

Configuration file errors encountered -- exiting