1.DHCP简介:
DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。
2.DHCP服务器简介:
DHCP服务器指的是由服务器控制一段IP地址范围,客户端登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。
3.安装DHCP软件
[root@localhost Server]# rpm -ivh dhcp-3.0.5-21.el5.x86_64.rpm
[root@localhost Server]# yum install dhcp -y
4.安装后DHCP生成的软件文件路径(部分)
[root@localhost Server]# rpm -ql dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcrelay
/usr/bin/omshell
/usr/sbin/dhcpd(启动脚本)
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-3.0.5/api+protocol
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample(重点文件)
/var/lib/dhcpd/dhcpd.leases (租约文件)
5.配置文件说明
说明:CentOS 5.X以前的配置文件路径 是/etc/dhcpd.conf 新版的配置文件路径 是/etc/dhcp/dhcpd.conf
[root@localhost Server]#cat /etc/dhcpd.conf
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample (说明配置文件的模版路径 )
[root@localhost Server]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
[root@localhost Server]# cat /etc/dhcpd.conf
#这部分是全局设置
option domain-name"zzhz.com"; #设置"域名"体现在/etc/resolv.conf中的search
option domain-name-servers IP1, IP2; # DNS设置,会修改客户端的/etc/resolv.conf
default-lease-time 259200; 租约时间
max-lease-time 518400; 最大租约时间
ddns-update-style none; #也有这个值 interim;
ignore client-updates;
#subnet :指定子网作用域(动态IP)
subnet 192.168.0.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.0.128 192.168.0.254;#地址范围 有使用这个range dynamic-BOOTP
option routers 192.168.0.1; #网关
option subnet-mask 255.255.255.0; #子网掩码
option nis-domain "domain.org";
option broadcast-address 192.168.0.255;#广播地址
option time-offset -18000; #时区时间
option ntp-servers 192.168.1.1;
option netbios-name-servers 192.168.1.1;
option netbios-node-type 2;
# 固定IP地址设置
host win7 {
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
6.重启服务和语法检查
[root@localhost Server]# service dhcpd restart
启动 dhcpd: [确定]
[root@localhost Server]# service dhcpd configtest
Syntax: OK
7.防火墙设置
iptables -I INPUT 1 -p tcp tcp --dport 67 -j ACCEPT
iptables -I INPUT 1 -p tcp tcp --dport 68 -j ACCEPT
iptables -I INPUT 1 -p tcp udp --dport 67 -j ACCEPT
iptables -I INPUT 1 -p tcp udp --dport 68 -j ACCEPT
8.一些文件说明:
tailf /var/log/messages 服务器端:显示客户端请求IP过程
Aug 21 16:13:45 localhost dhcpd: Sending on LPF/eth0/00:0c:29:52:2f:a0/192.168.80/24
Aug 21 16:13:45 localhost dhcpd: Sending on Socket/fallback/fallback-net
Aug 21 16:13:50 localhost dhcpd: DHCPREQUEST for 192.168.80.200 from 00:0c:29:b8:d1:2a via eth0
Aug 21 16:13:50 localhost dhcpd: DHCPACK on 192.168.80.200 to 00:0c:29:b8:d1:2a via eth0
Aug 21 16:14:02 localhost dhcpd: DHCPREQUEST for 192.168.80.200 from 00:0c:29:b8:d1:2a via eth0
Aug 21 16:14:02 localhost dhcpd: DHCPACK on 192.168.80.200 to 00:0c:29:b8:d1:2a via eth0
Aug 21 16:15:31 localhost dhcpd: DHCPDISCOVER from 00:0c:29:f4:21:01 via eth0
Aug 21 16:15:31 localhost dhcpd: DHCPOFFER on 192.168.80.199 to 00:0c:29:f4:21:01 via eth0
Aug 21 16:15:32 localhost dhcpd: DHCPREQUEST for 192.168.80.199 (192.168.80.100) from 00:0c:29:f4:21:01 via eth0
Aug 21 16:15:32 localhost dhcpd: DHCPACK on 192.168.80.199 to 00:0c:29:f4:21:01 via eth0
服务器端:显示分配过的IP信息
cat /var/lib/dhcpd/dhcpd.leases
客户端:显示客户端请求到的IP信息
cat /var/lib//dhclient/dhclient-eth0.leases
服务器端:如果有我个网卡,设置其中一个接受客户端DHCP请求接口
[root@localhost Server]# cat /etc/sysconfig/dhcpd
DHCPDARGS="eht0"