轻松搭建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

相关推荐

  • 服务器中挖矿木马病毒如何解决(kswapd0进程使cpu爆满)

    现象:系统cpu持续使用过高,造成无法远程连接 分析过程:一开始机器不能远程登录,但又能够ping通,登录信息也没有修改过,判断可能远程登录服务故障,后登录机器top发现,cpu使用率百分百,这很不正常,上面只运行了一个网站与数据库,发现异常进程kswapd0,查找资料后发现其是挖矿程序 解决方案:排查kswapd0进程 top 执行命令 netstat -…

    2022年12月13日
    1.2K00
  • DM工作笔记-DATEADD(指定日期添加n个时间段)函数和其他时间函数

    达梦官方文档已经说得很清楚了,在此仅记录下笔记,方便以后进行查阅。 DATEADD对应的相关文档如下: 这里说明下CREATE_TIME是TIMESTAMP类型。 如下例子: 运行截图如下: 现在有个需求,让CREATE_TIME添加,2秒,2分钟,2小时,2年。 对应的SQL如下: 运行截图如下: 如果再有这样的一个需求,离现在(当前时刻)2小时外的数据是…

    2023年12月27日
    1.3K00
  • 如何使用VNC进行远程桌面控制

    VNC是一款很实用的可以实现远程桌面控制的小工具,我遇到的有两种情况比较常见,一是有时候时候可能你会外出或离开自己办公室(但可以访问到办公司的网络),而很多资料都保存在办公室的台式机上,这时如果突然有问题需要用到那些资料,你又不方便立刻回去,这时你就可以考虑借助笔记本电脑通过VNC远程控制自己的台式机桌面进行操作,处理一些紧急问题;还有一种情况就是你外出或离…

    2024年5月13日
    61200
  • centos7 shell 支持中文显示

    其实很简单,让 shell 支持 utf8 即可。先使用locale命令看一下设置情况: LC_ALL没有设置,需要赋值en_US.UTF-8,很简单: 最后,不要忘了source一下bash_profile,让其生效。

    2023年3月14日
    63100
  • 安装linux/Centos系统出现An Unknown Error Has Occurred报错原因和解决方法

    今天在给一个客户重装系统的时候出现: An Unknown Error Has OccurredThis program has encountered an unknown error. You may report the buy below or quit the program. This program has encountered an unk…

    2024年1月22日
    1.0K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信