注:#为注释

rpm -q dhcp #查看dhcp是否安装

yum  install dhcp* -y #安装DHCP(挂载看上文)

拷贝文件

cat  /usr/share/doc/dhcp*/dhcpd.conf.sample  >> /etc/dhcp/dhcpd.conf

cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf


注意:
1.在RHEL5中DHCP的主配置文件是/etc/dhcpd.conf
2.在RHEL6中DHCP的主配置文件是/etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf #修改配置文件
#
# DHCP Server Configuration file.#DHCP服务配置文件
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample#参考/usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'

ddns-update-style interim;#配置DHCP和DNS为互动更新模式

ignore client-updates;#忽略客户端更新(防范dhcp攻击
#配置DHCP用于单一地址池
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.10 192.168.100.200;   #地址范围
  option domain-name-servers 202.106.0.20;#DNS为202.106.0.20
  option routers 192.168.100.4;#网关
  option broadcast-address 192.168.100.255;#广播地址
  default-lease-time 600;#默认租期为600s(单位为秒)
  max-lease-time 7200;#最大租期为7200s
  hardware ethernet 08:00:07:26:c0:a5;#硬件MAC地址
  fixed-address 192.168.100.2;#给它定义固定IP地址

}

#第二种方式:面对大环境,每个部门需要一个地址池。如:
shared-network school {
  subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.10 192.168.2.254;
 option routers 192.168.2.1;
  host pc1{
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address 192.168.2.2;}
}
  subnet 192.168.3.0 netmask 255.255.255.0 {
  range 192.168.3.10 192.168.3.254;
 option routers 192.168.3.1}

}

service dhcpd start #启动服务


ps -ef | grep dhcpd #ps命令检查dhcpd进程

cat /var/lib/dhcpd/dhcpd.leases 查询释放的地址

service iptables stop #关闭防火墙


以下是大环境需要多个DHCP,走中继

vim /etc/sysconfig/dhcpd  #指定接口
DHCPDARGS=eth0

vim /etc/sysconfig/dhcrelay#编辑DHCP中继服务器配置文件
# Command line options here
DHCRELAYARGS=""
INTERFACES="eth0" 接口
DHCPSERVERS="192.168.100.4"dhcp服务端地址
           
vim /etc/sysctl.conf#开启服务器的路由转发功能
net.ipv4.ip_forward = 1

service dhcrelay restart#启动DHCP中继服务