服务器搭建二——DHCP服务搭建

1.测试环境:Centos 6.9

虚拟主机中安装
软件版本:dhcp-4.1.1-53.P1.el6.centos.x86_64

工作原理:

服务器搭建二——DHCP服务搭建_第1张图片
工作原理

2.安装软件:

yum list installed|grep dhcp查看是否安装
yum install -y dhcp安装dhcp(自动安装版本为4.1.1)

服务器搭建二——DHCP服务搭建_第2张图片
查看安装和安装dhcp

也可以使用rpm -qa|grep dhcp查看安装的情况
Whereis dhcp查看安装的文件在哪里 /etc/dhcp里面有我们需要的配置文件。
在/etc/rc.d/init.d/下面的dhcp的脚本 dhcp6 是针对于IPv6

服务器搭建二——DHCP服务搭建_第3张图片
查看安装和配置文件
服务器搭建二——DHCP服务搭建_第4张图片
安装文件
服务器搭建二——DHCP服务搭建_第5张图片
关于dhcp的文件

3.配置文件

查看配置文件如下图,发现默认里面什么都没有,可以参考dhcpd.conf.sample

默认配置文件

dhcpd.conf

# Sample configuration file for ISC dhcpd
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600; #默认租约时间
max-lease-time 7200;#最大租约时间
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none; # 动态DNS
# 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 10.152.187.0 netmask 255.255.255.0 {
}#subnet定义子网
# This is a very basic subnet declaration.
subnet 10.254.239.0 netmask 255.255.255.224 {
range 10.254.239.10 10.254.239.20; # 提供动态IP地址范围
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; #默认网关
}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
subnet 10.254.239.32 netmask 255.255.255.224 {
range dynamic-bootp 10.254.239.40 10.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
}
# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org; #域名服务器
option domain-name "internal.example.org";#域名选项
option routers 10.5.5.1;#默认网关
option broadcast-address 10.5.5.31;#广播地址选项
default-lease-time 600;
max-lease-time 7200;
}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
host passacaglia { #为客户端指定主机名称
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
}
# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.fugue.com;
}
# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.
class "foo" {
match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}
shared-network 224-29 {#把多个子网定义在一个超级作用域内
subnet 10.17.224.0 netmask 255.255.255.0 {
option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0 {
option routers rtr-29.example.org;
}
pool { # 地址池 未知客户端选择的地址范围
allow members of "foo";
range 10.17.224.10 10.17.224.250;
}
pool {#已知的客户端从下面的地址池选择IP
deny members of "foo";
range 10.0.29.10 10.0.29.230;
}#
}

特别说明

参考的配置文件是不能直接使用的,需要根据需要修改里面的IP地址,否则直接运行文件,dhcp服务是会报错的。具体配置文件的使用,需要根据手册,帮助文件来进行设置。

4.DDNS功能

动态域名服务:将用户的动态的IP地址映射到一个固定IP地址的域名解析服务上。现在有些路由器支持DDNS功能可以用来在自己家庭网络构建网站,而不用租用专用的网络空间商和IP地址

5.客户端租约数据库文件

dhcpd.lease里面存储是已经分发的IP地址
可以使用配置文件中的lease-file-name语句改变dhcpd.leases文件的位置和名称
格式:lease IP地址{statements......}

6.DHCP中继代理

使用命令dhcrelay 实现中继代理的功能,具体命令格式

服务器搭建二——DHCP服务搭建_第6张图片
dhcrelay命令格式

Server0 设置的是代理要访问到的DHCP服务器。

配置DHCP中继代理
vi /etc/sysconfig/dhcrealy

在里面输入:
INTERFACES="eth1" DHCPSERVERS="192.168.1.251"(IP地址根据自己的配置填写)
开启DHCP中继代理服务器的IPV4转发:
可以在两个地方开启:
vi /etc/sysctl.conf
将“net.ipv4.ip_forward = 0”改成“net.ipv4.ip_forward = 1”

服务器搭建二——DHCP服务搭建_第7张图片
IPv4转发

执行sysctl –p命令使刚开启的IPV4转发功能生效。

服务器搭建二——DHCP服务搭建_第8张图片
IPv4转发

② echo 1 > /proc/sys/net/ipv4/ip_forward

启动DHCP中继代理服务
dhcrelay 192.168.1.251

服务器搭建二——DHCP服务搭建_第9张图片
启动中继代理

service dhcrelay start chkconfig --level 35 dhcrelay on

说明:dhcp的配置文件如果没有配置好是无法启动服务的,因此应该首先写配置文件,然后在启动服务

你可能感兴趣的:(服务器搭建二——DHCP服务搭建)