1.环境需求:
网段:192.168.84.0/24 网关:192.168.84.10 DNS:61.235.70.252
每个IP默认租约:2天 最长为5天
分配范围:192.168.84.100-192.168.84.200 其他保留
为主机MAC 00-0C-29-25-3B-55 固定分配:192.168.84.88
每个IP默认租约:2天 最长为5天
分配范围:192.168.84.100-192.168.84.200 其他保留
为主机MAC 00-0C-29-25-3B-55 固定分配:192.168.84.88
2.配置/etc/dhcpd.conf
由于默认/etc/dhcpd.conf 为空的,可以参考/usr/share/doc/dhcp*/dhcpd.conf.sample 范本。
可以直接复制成/etc/dhcpd.conf
可以直接复制成/etc/dhcpd.conf
[root@server ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
配置文件如下:
[root@server ~]# cat /etc/dhcpd.conf
- ddns-update-style none; #不要更新DDNS
- ignore client-updates; #忽略客户端更新
- subnet 192.168.84.0 netmask 255.255.255.0 { #网段设置
- # --- default gateway
- option routers 192.168.84.10; #网关
- option subnet-mask 255.255.255.0; #子网掩码
- option nis-domain "Server.org"; #NIS的参数(可注释)
- option domain-name "Server.org"; #/etc/resolvconf 搜索域
- option domain-name-servers 61.235.70.252; #DNS
- option time-offset -18000; # Eastern Standard Time
- # option ntp-servers 192.168.84.10;
- # option netbios-name-servers 192.168.84.10;
- # --- 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 192.168.84.100 192.168.84.200;
- default-lease-time 172800; #默认租约2天,以秒为单位
- max-lease-time 432000; #最长租约5天,以秒为单位
- # we want the nameserver to appear at a fixed address
- host ns { #固定分配
- hardware ethernet 00:0C:29:25:3B:55; #固定分配电脑的MAC
- fixed-address 192.168.84.88; #要固定分的IP
- }
- }
完成配置之后,就启动DHCP服务
[root@server ~]# /etc/init.d/dhcpd start
3.测试客户机分配情况
固定分配的电脑 MAC为: 00-0C-29-25-3B-55
4.查看租约信息
[root@server ~]# cat /var/lib/dhcpd/dhcpd.leases
lease 192.168.84.128 {
starts 3 2011/01/05 02:09:04;
ends 3 2011/01/05 02:10:39;
tstp 3 2011/01/05 02:10:39;
binding state free;
hardware ethernet 00:0c:29:25:3b:55;
uid "\001\000\014)%;U";
}
lease 192.168.84.200 {
starts 3 2011/01/05 02:20:41;
ends 5 2011/01/07 02:20:41;
tstp 5 2011/01/07 02:20:41;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:25:3b:54;
uid "\001\000\014)%;T";
client-hostname "lyy-b8a4287ba95";
}
lease 192.168.84.128 {
starts 3 2011/01/05 02:09:04;
ends 3 2011/01/05 02:10:39;
tstp 3 2011/01/05 02:10:39;
binding state free;
hardware ethernet 00:0c:29:25:3b:55;
uid "\001\000\014)%;U";
}
lease 192.168.84.200 {
starts 3 2011/01/05 02:20:41;
ends 5 2011/01/07 02:20:41;
tstp 5 2011/01/07 02:20:41;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:25:3b:54;
uid "\001\000\014)%;T";
client-hostname "lyy-b8a4287ba95";
}
经过以上配置,一个简单的DCHP实例就完成了
解决早期版本linux多网卡同时监听DHCP,导致分配出错问题。
[root@server ~]# cat /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS="eth1" #修改成要监听的网段
# Command line options here
DHCPDARGS="eth1" #修改成要监听的网段
转载于:https://blog.51cto.com/liyaoyi/847560