DHCP

术语

作用域:一个完整的IP地址段,DHCP协议根据作用域来管理网络的分布、分配IP地址及其他配置参数

超级作用域:用于管理处于同一个物理网络中的多个逻辑子网段。超级作用域中包含了可以统一管理的作用域列表

排除范围:把作用域中的某些IP地址排除,确保这些IP地址不会分配给DHCP客户端

地址池:在定义了DHCP的作用域并应用了排除范围后,剩余的用来动态分配给DHCP客户端的IP地址范围

租约:DHCP客户端能够使用动态分配的IP地址的时间

预约:保证网络中的特定设备总是获取到相同的IP地址

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
yum install dhcp Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. rhel | 4.1 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: dhcp x86_64 12:4.2.5-27.el7 rhel 506 k Transaction Summary =============================================================================== Install 1 Package Total download size: 506 k Installed size: 1.4 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 12:dhcp-4.2.5-27.el7.x86_64 1/1 Verifying : 12:dhcp-4.2.5-27.el7.x86_64 1/1 Installed: dhcp.x86_64 12:4.2.5-27.el7 Complete! cat /etc/dhcp/dhcpd.conf # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page

dhcpd参数

参数作用
ddns-update-style-[类型]定义DNS服务动态更新的类型,类型包括none(不支持动态更新)、interim(互动更新模式)与ad-hoc(特殊更新模式)
`[allowignore]_client-updates`允许/忽略客户端更新DNS记录
default-lease-time_[21600]默认超时时间
max-lease-time_[43200]最大超时时间
option_domain-name-servers_[8.8.8.8]定义DNS服务器地址
option_domain-name_["domain.org"]定义DNS域名
range定义用于分配的IP地址池
option_subnet-mask定义客户端的子网掩码
option-routers定义客户端的网关地址
broadcase-address[广播地址]定义客户端的广播地址
ntp-server[IP地址]定义客户端的网络时间服务器(NTP)
nis-servers[IP地址]定义客户端的NIS域服务器的地址
Hardware[网卡物理地址]指定网卡接口的类型与MAC地址
server-name[主机名]向DHCP客户端通知DHCP服务器的主机名
fixed-address[IP地址]将某个固定的IP地址分配给指定主机
time-offset[偏移误差]指定客户端与格林尼治时间的偏移差

机房网络信息

参数名称
默认租约时间21600秒
最大租约时间43200秒
IP地址范围192.168.10.50~192.168.10.150
子网掩码255.255.255.0
网关地址192.168.10.1
DNS服务器地址192.168.10.1
搜索域linuxprobe.com

 1  2  3  4  5  6  7  8  9 10 11 12
vim /etc/dhcp/dhcpd.conf ddns-update-style none; ignore client-updates; subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.50 192.168.10.150; option subnet-mask 255.255.255.0; option routers 192.168.10.1; option domain-name "linuxprobe.com"; option domain-name-servers 192.168.10.1; default-lease-time 21600; max-lease-time 43200; }

dhcpd参数

参数作用
ddns-update-style_none;设置DNS服务不自动进行动态更新
ignore_client-updates;忽略客户端更新DNS记录
subnet-192.168.10.0-netmask-255.255.255.0-{作用域为192.168.10.0/24网段
range-192.168.10.50-192.168.10.150;IP地址池为192.168.10.50-150(约100个IP地址)
option_subnet-mask_255.255.255.0;定义客户端默认的子网掩码
option-routers-192.168.10.1;定义客户端的网关地址
option-domain-name-"linuxprobe.com";定义默认的搜索域
option_domain-name-servers_192.168.10.1;定义客户端的DNS地址
default-lease-time_21600;定义默认租约时间(单位:秒)
max-lease-time_43200;定义最大预约时间(单位:秒)
}结束符

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
systemctl start dhcpd systemctl enable dhcpd ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service' #分配固定ip tail -f /var/log/messages Mar 30 05:33:17 localhost dhcpd: Copyright 2004-2013 Internet Systems Consortium. Mar 30 05:33:17 localhost dhcpd: All rights reserved. Mar 30 05:33:17 localhost dhcpd: For info, please visit https://www.isc.org/ software/dhcp/ Mar 30 05:33:17 localhost dhcpd: Not searching LDAP since ldap-server, ldap- port and ldap-base-dn were not specified in the config file Mar 30 05:33:17 localhost dhcpd: Wrote 0 leases to leases file. Mar 30 05:33:17 localhost dhcpd: Listening on LPF/eno16777728/00:0c:29:c4:a4: 09/192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on LPF/eno16777728/00:0c:29:c4:a4:09/ 192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on Socket/fallback/fallback-net Mar 30 05:33:26 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 via eno16777728 Mar 30 05:33:27 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6: 12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 (WIN- APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6: 12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPREQUEST for 192.168.10.50 (192.168.10.10) from 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPACK on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 vim /etc/dhcp/dhcpd.conf 1 ddns-update-style none; 2 ignore client-updates; 3 subnet 192.168.10.0 netmask 255.255.255.0 { 4 range 192.168.10.50 192.168.10.150; 5 option subnet-mask 255.255.255.0; 6 option routers 192.168.10.1; 7 option domain-name "linuxprobe.com"; 8 option domain-name-servers 192.168.10.1; 9 default-lease-time 21600; 10 max-lease-time 43200; 11 host linuxprobe { 12 hardware ethernet 00:0c:29:27:c6:12; 13 fixed-address 192.168.10.88; 14 } 15 } systemctl restart dhcpd

浙ICP备11005866号-12