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

1.测试环境:Centos 6.9

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

工作原理:

工作原理

2.安装软件:

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

查看安装和安装dhcp

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

查看安装和配置文件
安装文件
关于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 实现中继代理的功能,具体命令格式

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”

IPv4转发

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

IPv4转发

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

启动DHCP中继代理服务
dhcrelay 192.168.1.251

启动中继代理

service dhcrelay start chkconfig --level 35 dhcrelay on

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,440评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,814评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,427评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,710评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,625评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,014评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,511评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,162评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,311评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,262评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,278评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,989评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,583评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,664评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,904评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,274评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,856评论 2 339

推荐阅读更多精彩内容