# mkdir /mnt/cdrom/ # mount /dev/cdrom /mnt/cdrom # cd /mnt/cdrom/Packages/ # ls dhcp* dhcp-4.2.5-27.el7.centos.x86_64.rpm dhcp-common-4.2.5-27.el7.centos.x86_64.rpm dhcp-libs-4.2.5-27.el7.centos.x86_64.rpm # rpm -Uvh dhcp-4.2.5-27.el7.centos.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:dhcp-12:4.2.5-27.el7.centos ################################# [100%]
# rpm -qc dhcp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd6.conf /etc/openldap/schema/dhcp.schema /etc/sysconfig/dhcpd /var/lib/dhcpd/dhcpd.leases /var/lib/dhcpd/dhcpd6.leases # cd /etc/dhcp/ # cp dhcpd.conf dhcpd.conf.origin # cat /etc/dhcp/dhcpd.conf ## DHCP Server Configuration file.# see /usr/share/doc/dhcp*/dhcpd.conf.example# see dhcpd.conf(5) man page# 查看示例文件 # vi /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
VLAN1的地址租约是3天,VLAN2的地址租约是8天
[root@zzsrv1 dhcp]# echo 3*24*60*60 | bc 259200 [root@zzsrv1 dhcp]# echo 8*24*60*60 | bc 691200
背景知识:
default-lease-time time; Time should be the length in seconds that will be assigned to a lease if the client requesting the lease does not ask for a specific expiration time. This is used for both DHCPv4 and DHCPv6 leases (it is also known as the "valid lifetime" in DHCPv6). The default is 43200 seconds. max-lease-time time; Time should be the maximum length in seconds that will be assigned to a lease. If not defined, the default maximum lease time is 86400. The only exception to this is that Dynamic BOOTP lease lengths, which are not specified by the client, are not limited by this maximum. |
# vi /etc/dhcp/dhcpd.conf
option domain-name "bigcloud.local"; option domain-name-servers 192.168.188.11, 192.168.188.12; default-lease-time 691200; max-lease-time 691200; subnet 192.168.188.0 netmask 255.255.255.0 { range 192.168.188.100 192.168.188.159; range 192.168.188.170 192.168.188.253; default-lease-time 259200; max-lease-time 259200; option routers 192.168.188.2; } subnet 192.168.189.0 netmask 255.255.255.0 { range 192.168.189.100 192.168.189.253; option routers 192.168.189.2; } host printer1 { hardware ethernet 00:12:34:56:78:90; fixed-address 192.168.188.111; } |
启动服务
# service dhcpd start
Redirecting to /bin/systemctl start dhcpd.service
查看日志
Internet Systems Consortium DHCP Server 4.2.5 Copyright 2004-2013 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Wrote 0 deleted host decls to leases file. Wrote 0 new dynamic host decls to leases file. Wrote 0 leases to leases file. Listening on LPF/eno16777728/00:0c:29:a4:2e:39/192.168.188.0/24 Sending on LPF/eno16777728/00:0c:29:a4:2e:39/192.168.188.0/24 Sending on Socket/fallback/fallback-net |
配置DHCPD为自动 启动, 这在CentOS 7上的新的变化 了
# chkconfig dhcpd on Note: Forwarding request to ‘systemctl enable dhcpd.service‘. ln -s ‘/usr/lib/systemd/system/dhcpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/dhcpd.service‘ # systemctl enable dhcpd # systemctl is-enabled dhcpd enabled
在一台Windows客户机上进行测试
当客户机租用IP地址时,会在日志中看到
DHCPINFORM from 192.168.188.100 via eno16777728: not authoritative for subnet 192.168.188.0 DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728 |
# tail /var/lib/dhcpd/dhcpd.leases
本文出自 “刘琼@天道酬勤” 博客,请务必保留此出处http://lqiong.blog.51cto.com/8170814/1559058
原文地址:http://lqiong.blog.51cto.com/8170814/1559058