第十六天学习linux

14.1 动态主机地址管理协议
动态主机配置协议(DHCP)是一种基于UDP协议且仅限于在局域网内部使用的网络协议,主要用于大型的局域网环境或者存在较多移动办公设备的局域网环境中,其主要用途是为局域网内部的设备或网络供应商自动分配IP地址等参数。

简单来说,DHCP协议就是让局域网中的主机自动获得网络参数的服务。
14.2 部署dhcpd服务程序
dhcpd是Linux系统中用于提供DHCP协议的服务程序。尽管DHCP协议的功能十分强大,但是dhcpd服务程序的配置步骤却十分简单,这也在很大程度上降低了在Linux中实现动态主机管理服务的门槛。

在确认Yum软件仓库配置妥当之后,安装dhcpd服务程序:

[root@linuxprobe ~]# 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!
查看dhcpd服务程序的配置文件内容。

[root@linuxprobe ~]# cat /etc/dhcp/dhcpd.conf

DHCP Server Configuration file.

see /usr/share/doc/dhcp*/dhcpd.conf.example

see dhcpd.conf(5) man page

14.3 自动管理IP地址
DHCP协议的设计初衷是为了更高效地集中管理局域网内的IP地址资源。DHCP服务器会自动把IP地址、子网掩码、网关、DNS地址等网络信息分配给有需要的客户端,而且当客户端的租约时间到期后还可以自动回收所分配的IP地址,以便交给新加入的客户端。
前文讲到,作用域一般是个完整的IP地址段,而地址池中的IP地址才是真正供客户端使用的,因此地址池应该小于或等于作用域的IP地址范围。另外,由于VMware Workstation虚拟机软件自带DHCP服务,为了避免与自己配置的dhcpd服务程序产生冲突,应该先按照图14-3和图14-4所示将虚拟机软件自带的DHCP功能关闭。
14.4 分配固定IP地址
在DHCP协议中有个术语是“预约”,它用来确保局域网中特定的设备总是获取到固定的IP地址。换句话说,就是dhcpd服务程序会把某个IP地址私藏下来,只将其用于相匹配的特定设备。
如果不方便查看主机的MAC地址,该怎么办呢?比如,要给老板使用的主机绑定IP地址,总不能随便就去查看老板的主机信息吧。针对这种情况,刘遄老师告诉大家一个很好的办法。我们首先启动dhcpd服务程序,为老板的主机分配一个IP地址,这样就会在DHCP服务器本地的日志文件中保存这次的IP地址分配记录。然后查看日志文件,就可以获悉主机的MAC地址了(即下面加粗的内容)。

[root@linuxprobe ~]# 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

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页