首页 技术 正文
技术 2022年11月21日
0 收藏 390 点赞 3,196 浏览 2426 个字

一.基础知识:

1.DHCP简介:
DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。
2.DHCP服务器简介:
DHCP服务器指的是由服务器控制一段IP地址范围,客户端登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。

二.DHCP服务器的相关配置:

今天我们就来做一个DHCP服务器: 
Linux常见服务器——DHCP服务器的搭建 
我将虚拟机server作为dhcp服务器使用,利用destop进行测试 
为了方便,将server主机名更名为dhcp.server.com,将desktop主机名更名为dhcp.test.com 
下来,我们在dhcp.server.com这台主机上进行配置: 
1.查看server的ip 
Linux常见服务器——DHCP服务器的搭建 
2.查看DHCP服务的依赖包: 
Linux常见服务器——DHCP服务器的搭建 
3.安装DHCP服务: 
Linux常见服务器——DHCP服务器的搭建

4.进行配置:

(1)开启dhcp服务

systemctl start dhcpd

(2)更改配置文件

cp  /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf 
更改以下部分:

  7 option domain-name "server.com";
##域名:参见/etc/resolv.conf
8 option domain-name-servers 172.25.10.254;
##指定dns服务器,多台用逗号隔开。
30 subnet 172.25.10.0 netmask 255.255.255.0 {
##指定子网络及子网掩码
31 range 172.25.10.10 172.25.10.20;
##指定IP范围
32 option routers 172.25.10.254;
##指定默认网关
33 }
34#### 删除27,28行,34行及以后

下面是在dns.test.com上所做的配置:

(1)网络参数设置: 
编辑/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=dhcp
###关键部位为dhcp
ONBOOT=yes

(2)重启网络:

systemctl restart network
###在本次试验,我遇到了如下问题:执行该命令报错,无法通过DHCP服务器获得ip,解决思路为:DHCP通常是用于局域网内的一个通信协议,它主要通过客户端发送广播数据包给整个物理网段内的所有主机,若局域网内有DHCP服务器时,才会响应客户端的ip参数要求。所以DHCP服务器与客户端应该在同一个物理网段内。整个DHCP数据包在服务器与客户端间的交互情况如下图(1):
###所以我猜测是防火墙阻止了数据包的传送
###我采取的解决方法是:
两台虚拟机均执行命令:
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload
查看dhcp是否通行:
firewall-cmd --list-all
重启虚拟机后问题解决。

Linux常见服务器——DHCP服务器的搭建 
(图(1)DHCP数据包在服务器与客户端间的交互情况示意)

测试机通过DHCP服务器获得ip: 
Linux常见服务器——DHCP服务器的搭建
(3)将整个网络重启之后,如果执行的结果找到的正确的DHCP主机,那么以下几个文件可能会被修改。

#1.查看/etc/resolv.conf

Linux常见服务器——DHCP服务器的搭建

#2.查看路由

Linux常见服务器——DHCP服务器的搭建

#3.查看服务器记录的DHCP信息
cat /var/lib/dhcpd/dhcpd.leases

Linux常见服务器——DHCP服务器的搭建

三.一个配置例子

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages (‘none’, since DHCP v2 didn’t
# have support for DDNS.)
ddns-update-style none;

option domain-name-servers 192.168.19.254;

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

subnet 192.168.18.0 netmask 255.255.254.0 {
range 192.168.18.20 192.168.19.200;
option routers 192.168.19.254;
option domain-name-servers 192.168.19.254;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291