一. 资料参考与准备
1)所需软件:dhcpd-x.x.x.rpm
可以从网上或者光盘获取。
2)资料收集:
DHCP资料:
DHCP stands for "Dynamic Host Configuration Protocol"
DHCP''s purpose is to enable individual computers on an IP network to extract their
configurations from a server (the ''DHCP server'') or servers, in particular, servers that
have no exact information about the individual computers until they request the information.
The overall purpose of this is to reduce the work necessary to administer a large IP
network. The most significant piece of information distributed in this manner is the IP
address.
dhcpd.leases 文件
是DHCP客户计算机租约的数据库文件,默认是在/var/lib/dhcpd/目录下。文件内容包含租约声明,每一次租约被获取、更新、释放,它的值都会被记录到文件末尾。相当一大部分资料都说要手动建立这个文件,可是我今天配置过城中发现并不是,再看下/etc/init.d/dhcpd 这个启动脚本里边的其中内容:
if [ ! -f /var/lib/dhcpd/dhcpd.leases ] ; then
mkdir -p /var/lib/dhcpd
touch /var/lib/dhcpd/dhcpd.leases
[ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon /var/lib/dhcp/dhcpd.leases
>/dev/null 2>&1
fi
表明此服务的启动运行完全有能力自动生成此文件。(除非是版本问题,因为我现在用的都是最新的)
DHCP主配置文件关键词汇解释:
#默认租约时间
default-lease-time
#最大租约时间
max-leases-time
#子网掩码选项
option subnet-mask
#广播地址
option broadcast-adress
#路由器地址
option routers
#指明时间服务器的IP地址
Option time-servers
#DNS服务器地址
option domain-name-servers
#域名
option domain-name “doit.com.cn”;
#子网掩码声明
subnet 0.0.0.0 netmask 255.255.255.255{
#范围
range 0.0.0.0 0.0.0.255
用于给一组声明提供的一些参数。
allow和deny语句
allow和deny语句用来控制DHCPD对客户计算机的请求。
unknown-clients关键字
allow unknown-clients;
deny unknown-clients;
allow unknown-clients;允许DHCPD可以动态的分配IP给位置的客户计算机。
而deny unknown-clients;则是不允许。默认为allow unknown-clients。
bootp关键字
allow bootp;
deny bootp;
指明DHCPD是否响应BOOTP的查询,默认是允许的
二、安装配置全过程:
#rpm -ivh dhcp*.rpm (安装软件)
#cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcpd.conf(复制配置文件)
#vi /etc/dhcpd.conf (修改配置文件)
############################################################################################
ddns-update-style interim;
ignore client-updates;
subnet 10.45.63.0 netmask 255.255.255.0 {
# --- default gateway
option routers 10.45.63.185;
option subnet-mask 255.255.255.0;
option nis-domain "xuanfei.org";
option domain-name "xuanfei.org";
option domain-name-servers 202.96.128.86;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 10.45.63.185;
# option netbios-name-servers 10.45.63.185;
# --- 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 10.45.63.1 10.45.63.255;
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 10.45.63.189;
}
}
############################################################################################
以上的配置可是实现DHCP的服务
其发给DHCP客户端的参数是:
子网掩码:255.255.255.0
广播地址:10.45.63.255
网络地址:10.45.63.0
默认网关:10.45.63.185
DNS服务器:202.96.128.86
要为一台单独的计算机分配固定的IP地址,可以在/etc/dhcpd.conf文件中加上一条:
host doit{
#doit计算机网卡的硬件地址。
Hardware Ethernet 12:34:56:78:AB:CD;
#固定的IP地址
fixed-adress 10.45.63.189;
}
#也可连写为一行:host Jephe {hardware ethernet 12:34:56:78:AB:CD;fixed-address
10.45.63.189;}
你也可为某台机器指定不同的网关地址,名服务器等:host Jephe {hardware ethernet
12:34:56:78:AB:CD;fixed-address 10.45.63.189;option routers 10.45.63.185;}
三、启用与测试
启动DHCPD服务的方法为:
#/etc/init.d/dhcpd start
停止DHCPD服务的方法为:
#/etc/init.d/dhcpd stop
重新启动DHCPD服务的方法为:
#/etc/init.d/dhcpd restart
将DHCPD守护进程设置在运行级别35启用:
# chkconfig --level 35 dhcpd on
测试dhcp
linux下:
#dhclient
windows下:
打开一台windows xp客户端TCP/IP属性,选择“自动获得IP地址”和“自动获得DNS 服务器地址”或者在
命令提示符下分别键入ipconfig /release、 ipconfig /renew 最后在命令提示符下键入ipconfig /all, 就会发现客户端通过广播成功从服务器租得IP地址信息
当一台终端计算机动态获得IP地址后,在/var/lib/dhcpd/dhcpd.leases文件中建立一条类似下面的记录。记录内容为:
lease 10.45.63.185 {
starts 1 2007/05/28 17:19:21;
ends 1 2007/05/28 23:19:21;
tstp 1 2007/05/28 23:19:21;
binding state active;
next binding state free;
hardware ethernet 00:66:e7:4a:71:35;
uid "\001\000\026\346Ja4";
client-hostname "win_xuanfei";
}
四、小结:
在较为大型的网络中为确保证网络的稳定性、健壮性,可采用2台DHCP服务器偕同工作,实现DHCP服务
器的冗余。但多台DHCP服务器的IP地址资源必须合理的调配,建议不要重复分配IP地址!
上面的配置文献是最基本的配置,在实际的应用还要考虑到IP地址分配和策略的问题!在以后的无盘
工作站,无人职守安装系统等各领域都是在先前工作中起着重要的作用,是不可以忽视的一门技术。
资料参考地址:http://www.dhcp.org/
http://www.dhcp-handbook.com/dhcp_faq.html