第3部分 创建一个真正的DHCP服务器--单个子网
时间:2007-06-20 来源:liufirst
(1) 配置对单个子网有效的服务器,并实验“类”
按照前面的样本,配置服务器,实现:IP地址范围为172.16.0.40-172.16.0.50,租约时长10分钟(600秒),网关172.16.0.254,子网掩码255.255.255.0,DNS服务器172.16.0.3。配置文件如下:
#option domain-name "example.org"; option domain-name-servers 172.16.0.3;
default-lease-time 600; max-lease-time 7200;
authoritative;
subnet 172.16.0.0 netmask 255.255.255.0 { range 172.16.0.40 172.16.0.50; option routers 172.16.0.254; } |
将这个文件写入/etc/dhcpd.conf,执行/etc/init.d/dhcdbd start(注意,原来的版本是dhcpd start),可以看到启动成功的提示。让客户端尝试获得地址,却得不到,查看服务器/var/state/dhcp/dhcpd.leases,租约文件没有建立,先建立这个租约文件:
touch /var/state/dhcp/dhcpd.leases
再重启服务端,提示成功,再看客户端,仍就无法与服务器联系,而服务器的/var/log/message中的信息也提示正常,但是没有更多的信息。会是什么原因呢,客户端没有启用防火墙,服务端启用了防火墙,看其配置,没有开放UDP 67端口,先将它开放,再看客户端,还是不行。
在网上找原因,大多数都要求:
通常是Linux DHCP服务器沒有办法接收來自255.255.255.255 的 DHCP 客户机的Request 封包造成的。一般是Linux DHCP服务器的网卡没有设置具有MULTICAST功能。为了让dhcpd(dhcp程序的守护进程)能够正常的和DHCP客户机沟通,dhcpd必须传送封包到255.255.255.255这个IP地址,但是有些Linux系统里255.255.255.255这个IP地址被用来做为监听区域子网域(local subnet)广播的 IP地址,所以需要在路由表(routing table)里加入255.255.255.255以激活MULTICAST功能; |
Route命令在putty远程登录的系统上不能识别,在本地却可以用。按上面的要求完成。查看客户端,依旧不能获得地址。重启服务器试一下。重启完成后,依旧不行。在服务器上查看/var/log/messages,仔细查找,找到这样一段:
** You must add a global ddns-update-style statement to /etc/dhcpd.conf to get the same behaviour as in 3.0.2pl11 and previous versions, add a line that says “ddns-update-style ad-hoc;” please read the dhcpd.conf manual page for more information. ** |
这段话说为了与前面的版本保持一致,必须在配置文件的顶部加上“ddns-update-style ad-hoc;”,看来还得加呀!在配置文件开头加上
ddns-update-style none; |
重启DHCP服务,客户端终于得到了地址。
/var/state/dhcp/dhcpd.leases文件也有了内容:
# All times in this file are in UTC (GMT), not your local timezone. This is # not a bug, so please don't ask about it. There is no portable way to # store leases in the local timezone, so please don't request this as a # feature. If this is inconvenient or confusing to you, we sincerely # apologize. Seriously, though - don't ask. # The format of this file is documented in the dhcpd.leases(5) manual page. # This lease file was written by isc-dhcp-V3.0.5
lease 172.16.0.50 { starts 3 2007/06/20 09:09:12; ends 3 2007/06/20 09:19:12; binding state active; next binding state free; hardware ethernet 00:15:58:db:24:86; uid "\001\000\025X\333$\206"; client-hostname "Admin"; } lease 172.16.0.50 { starts 3 2007/06/20 09:14:11; ends 3 2007/06/20 09:24:11; binding state active; next binding state free; hardware ethernet 00:15:58:db:24:86; …… |
除了注释语句外,解释一下:
lease 172.16.0.50 { #指定是哪个IP地址租约的内容,括号中的内容是分配给客户端的 starts 3 2007/06/20 09:09:12; # 按“周 年 月 日 时 分 秒”写的开始UTC时间 ends 3 2007/06/20 09:19:12; # 按“周 年 月 日 时 分 秒”写的结束UTC时间 binding state active; # 与失败恢复协议有关,如果有热备机,则是backup,没有,则是active或free next binding state free; # 租约过期后的状态 hardware ethernet 00:15:58:db:24:86; # 硬件地址 uid "\001\000\025X\333$\206"; # 不是必须的,如果客户端发送,就记录 client-hostname "Admin"; # 客户端发送的主机名,如果不发送,就不记 }
|
另外,租约文件里面对一个IP地址每一次申请和续约都有记录。
进行第二步,查看客户端的“类”,在配置文件顶部增加一句:
set vendor-string = option vendor-class-identifier; |
重启DHCP服务后,查看租约文件,并没有相应的记录,messages文件也没有出错提示,问题出在哪里呢?网上搜索发现了一些同样的问题,但是没有结果。
On Monday 04 September 2006 13:32, Laurent CARON wrote:
> Hi,
>
> I'm basically trying to set-up the following thing.
>
> A DHCP server serving my computers on one range (say: 192.168.0.10 -
> 192.168.0.100), and i'd like to give IP addresses in the range
> (192.168.0.110 - 192.168.0.200) to my IP phones (Polycom IP600).
>
> I already tried to get the vendor string by adding
> set vendor-string = option vendor-class-identifier;
> in the dhcpd.conf but without success (nothing useful appears in the
> leases file for that phone).
>
> Do you know a good way to achieve my goal ?
>
> Thanks
>
> Laurent
I also have a need for this. I have a bunch of boards that I need
to feed a BOOTP like response to with a file to loaded as kernel,
but currently I have to give it a specific MAC address. It would
be really useful to have an option in a DHCP server which allowed
a wildcard in the MAC address so that I could take all boards from
a particular series (typically a manufacturer) and send the same
file to any of them that I attach. But I have yet to find a
BOOTP or DHCP server which does this.
David
|
这个问题看来暂时要等等。