(一)安装dhcp软件包
yum install -y dhcp
service iptables stop //关闭防火墙
setenforce 0 //关闭安全linux
(二)修改配置文件
cd /etc/dhcp/
cp dhcpd.conf dhcpd.conf.back //备份主配置文件(以防万一嘛!)
cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample | grep -v "#" | grep -v "^$" > /etc/dhcp/dhcpd.conf
vi /etc/dhcp/dhcpd.conf //主配置文件
-----------全局配置部分-------------
ddns-update-style interim;
default-lease-time 600; //默认最小租约为600s
max-lease-time 7200; //默认最大租约为7200s
------------网段声明部分-------------
subnet 192.168.1.0 netmask 255.255.255.0 { //网段声明
option broadcast-address 192.168.1.255; //广播地址
range 192.168.1.100 192.168.1.200; //分配地址池
option routers 192.168.1.1; //网关
option subnet-mask 255.255.255.0; //掩码
option domain-name-servers 8.8.8.8, 9.9.9.9; //DNS服务器地址
ddns-update-style none; //禁用DNS动态更新
option domain-name "qq.com"; //默认搜索域
}
(三)启动服务并验证
service dhcpd start
ipconfig /release //释放地址租约
ipconfig /renew //重新获取地址租约
(四)host主机声明
vi /etc/dhcp/dhcpd.conf //主配置文件
host prtsvr {
hardware ethernet 00:50:56:C0:00:01; //绑定主机MAC地址
fixed-address 192.168.1.88; //分配给主机的IP地址
}
重启动服务并验证host主机声明
service dhcpd restart
ipconfig /release //释放地址租约
ipconfig /renew //重新获取地址租约