轻松搭建DHCP服务器

DHCP(Dynamic Host Configuration Protocol)动态主机配置协议

DHCP(Dynamic Host Configuration Protocol),动态主机配置协议,是一个应用层协议。当我们将客户主机ip地址设置为动态获取方式时,DHCP服务器就会根据DHCP协议给客户端分配IP,使得客户机能够利用这个IP上网。
DHCP的前身是BOOTP协议(Bootstrap Protocol),BOOTP被创建出来为连接到网络中的设备自动分配地址,后来被DHCP取代了,DHCP比BOOTP更加复杂,功能更强大。

DHCP的实现

轻松搭建DHCP服务器

第一步:Client端在局域网内发起一个DHCP Discover包,目的是想发现能够给它提供IP的DHCP Server。
第二步:可用的DHCP Server接收到Discover包之后,通过发送DHCP Offer包给予Client端应答,意在告诉Client端它可以提供IP地址。
第三步:Client端接收到Offer包之后,发送DHCP Request包请求分配IP。
第四步:DHCP Server发送ACK数据包,确认信息

一、DHCP服务的配置
  • 安装好yum源
  • 在yum源中查找并安装DHCP服务
[root@foundation79 ~]# yum search dhcp

Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
============================== N/S matched: dhcp ===============================
dhcp-common.x86_64 : Common files used by ISC dhcp client and server
dhcp-libs.i686 : Shared libraries used by ISC dhcp client and server
dhcp-libs.x86_64 : Shared libraries used by ISC dhcp client and server
dhclient.x86_64 : Provides the ISC DHCP client daemon and dhclient-script
dhcp.x86_64 : Dynamic host configuration protocol software
dnsmasq.x86_64 : A lightweight DHCP/caching DNS server
  Name and summary matches only, use "search all" for everything.

yum 源安装dhcp:

[root@localhost ~]# yum install dhcp.x86_64 -y
Loaded plugins: langpacks
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_dvd                   506 k
Transaction Summary
=======================================================================================================================
Install  1 Package

Total download size: 506 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm                                                                    | 506 kB  00:00:00     
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!
2.更改DHCP配置文件

因为每台主机需要DHCp分配的IP范围和DNS不同,所以这些都需要用户在配置文件中进行添加。

[root@foundation79 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y

[root@foundation79 ~]# vim /etc/dhcp/dhcpd.conf
轻松搭建DHCP服务器

3.启动DHCP程序

[root@foundation79 ~]# systemctl start dhcpd
[root@foundation79 ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
重启网络:
[root@foundation79 ~]# systemctl restart network

重置server进行检测:

[root@foundation79 ~]# rht-vmctl reset server 
Are you sure you want to reset server? (y/n) y
Resetting server.
Powering off server..
Creating virtual machine disk overlay for rh124-server-vda
Creating virtual machine disk overlay for rh124-server-vdb
Starting server.

[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.188  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::5054:ff:fe00:4f0b  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:4f:0b  txqueuelen 1000  (Ethernet)
        RX packets 50  bytes 8215 (8.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 306  bytes 23261 (22.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看dhcp租约文件中的租约记录

[root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.2.5

server-duid "\000\001\000\001\"\226D\255RT\000\000O\012";

lease 172.25.254.188 {
  starts 2 2018/05/22 03:02:42;
  ends 2 2018/05/22 03:12:42;
  cltt 2 2018/05/22 03:02:42;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet  52:54:00:00:4f:0b;   #分配出的网卡地址与剩余ip
}

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/10405

(0)
凯影的头像凯影
上一篇 2023年12月5日 下午5:36
下一篇 2023年12月6日 下午3:58

相关推荐

  • CentOS 修改 SSH无操作自动断开时长及连接超时

    CentOS 修改 SSH无操作自动断开时长 当 SSH 连接到 CentOS 服务器时, 如果一段时间不操作, SSH 会自动断开。 这时, 可修改配置增加连接时长。 一、修改配置 在配置中找到 修改为 ClientAliveInterval 指定了服务器端向客户端发送消息的间隔,默认 0 不发送消息。ClientAliveInterval 30…

    2023年2月20日
    2.9K00
  • Windows server 2008 R2 服务报错14001解决方案

    错误 14001:因为应用程序的并行配置不正确 有关详细信息 请参阅应用程序事件日志 或使用命令行 sxstrace.exe 工具 今日通过服务管理器重新启动mysql服务时发现报错14001,解决方案如下: 打开左下角服务管理器,点击功能,然后添加功能,添加 Framework 3.51全部功能,这样就可以去服务管理器中启动服务了!!!

    2022年11月22日
    2.3K00
  • Linux 实用工具 Screen —— 再也不怕因为网络连接中断杀死任务了!

    不知道小伙伴们是否遇到过这样的场景: 有时候,我们本地通过 SSH 连接到远程服务器并不是很稳定,经常会断开连接。如果此时我们正在做类似更新系统、DD 系统、远程传输 / 下载文件等需要一定时间的操作,就会非常难受,好不容易传了半天的文件,中断了,又得重新来传一次,还得祈祷这次别传一半断开了。 今天我们介绍的这个工具 ——screen,就是为了来解决上面这些…

    2023年11月9日
    1.4K00
  • linux之运维性能命令

    在 Linux 系统中,有许多命令和工具可以帮助运维人员监控系统状态、性能以及定位问题。以下是一些常用的运维相关命令: top: 如前所述,实时显示进程的资源占用情况。 htop: 类似于 top,但提供了一个更为用户友好的界面,支持颜色显示和滚动。 vmstat: 报告有关系统进程、内存、分页、块 IO、陷阱和 CPU 活动的信息。 iostat: 用于监…

    2024年7月3日
    2.9K00
  • 如何清理windows server 2008 R2 中winsxs文件夹

    最近发现公司的一台服务器C盘只剩5G左右的空间,经过仔细查看发现C:\windows\winsxs 目录占了20多G的容量。此文件夹是更新系统补丁产生的不能直接删除,所以只能通过cleanmgr.exe工具进行清理C盘。 以下方法亲自验证清理成功: 一、在Windows Server 2008 R2,右击C盘,查看属性,发现界面中没有清理C盘的工具按钮,那如…

    2023年4月3日
    1.7K00

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信