第一步 安装 DHCP
[root@localhost ~]# yum install dhcp dhcp-devel
DHCP文件简介
/etc/dhcp/dhcpd.conf #主配置文件,除了括号那栏,其它都要结尾 ; 这样的分号
/var/lib/dhcpd/dhcpd.leases #IP地址租约在这里
第二步 配置 DHCP
- 主文件配置
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
# 设定租约期限
default-lease-time 259200;
max-lease-time 518400;
# 设定领域名称与DNS
option domain-name "dhcp.google";
option domain-name-servers 192.168.100.1; #DNS服务器
ddns-update-style interim; #鸟哥说这是DHCP加入新功能要用的
# 动态IP分配的设定
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.249 192.168.100.253;
option broadcast-address 192.168.100.255;
option routers 192.168.100.1; #网关
}
# 给BOSS等设定静态IP
host google-inside {
hardware ethernet 00:1D:7D:70:91:AB; #这个网卡址址是我的(连接的是:号)
fixed-address 192.168.100.252;
option broadcast-address 192.168.100.255;
option routers 192.168.100.1;
}
- dhcpd配置
[root@localhost ~]# vi /etc/rc.d/init.d/dhcpd
configtest() {
[ -x $exec ] || return 5
[ -f $config ] || return 6
$exec -q -t -cf $config
RETVAL=$?
if [ $RETVAL -eq 1 ]; then
$exec -t -cf $config
else
echo "Syntax: OK" >&2
fi
return $RETVAL
}
INTERFACES="eth0" #加入这一句
rh_status() {
status -p $pidfile $exec
}
第三步 启动 DHCP
[root@localhost ~]# service dhcpd start
[root@localhost ~]# netstat -utl | grep bootps
udp 0 0 *:bootps *:*
看到上面的结果,证明成功了
第四步 测试
- windows 客户端太简单就不说了
- linux 客户端
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
这样就可以了