网络服务-DHCP

1.DHCP简介

DHCP(Dynamtic Host Configuraton Protocol,动态主机配置协议)是一个工作在应用层的局域网网络协议,数据传输时使用UDP不可靠谱传输协议工作,通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配网络资源,使网络环境中的主机能动态的获得IP地址、Gatway地址、DNS服务器地址等信息,能够提升地址的使用率。

2.DHCP工作原理(租约四部曲+续租)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.DHCP 服务搭建

在这里插入图片描述在这里插入图片描述

4.DHCP实验部署

在这里插入图片描述
具体实验操作:
1.修改配置文件dhcpd.conf ,将其中前几个不用的subnet注释掉;
2.设置一个subnet要分配的网段和子网掩码,声明可用的IP地址,其余用不到的可以暂时不设置;
3.保留最小租约时间和最大租约时间;

[root@oracle dhcp]# vim dhcpd.conf
# 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;

# 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 {
#}

# 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;
#  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 192.168.197.0 netmask 255.255.255.0 {
  range 192.168.197.20 192.168.197.200;
#  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;
}

4.启动服务,service dhcpd start
5.查看是否启动成功

[root@oracle dhcp]# service dhcpd start
Starting dhcpd:                                            [  OK  ]
[root@oracle dhcp]# netstat -tluna     
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:55647               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 192.168.197.134:22          192.168.197.1:58794         ESTABLISHED 
tcp        0      0 192.168.197.134:22          192.168.197.1:60712         ESTABLISHED 
tcp        0      0 192.168.197.134:22          192.168.197.135:63025       ESTABLISHED 
tcp        0      0 :::51618                    :::*                        LISTEN      
tcp        0      0 :::33060                    :::*                        LISTEN      
tcp        0      0 :::3306                     :::*                        LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
udp        0      0 127.0.0.1:1001              0.0.0.0:*                               
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               
udp        0      0 0.0.0.0:24840               0.0.0.0:*                               
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               
udp        0      0 0.0.0.0:838                 0.0.0.0:*                               
udp        0      0 :::111                      :::*                                    
udp        0      0 :::36291                    :::*                                    
udp        0      0 :::838                      :::*    

6.验证,将局域网内的另外一台主机B,ip获取方式改成DHCP
在这里插入图片描述
7.重启另一台主机B的网卡,service network restart (该命令会重启所有网卡,如果怕影响别的网卡服务,可以使用下面这条语句,只启动特定的网卡)

[root@135 ~]# ifdown eth0;ifup eth0

验证主机B,通过DHCP服务来获取IP的新ip地址(之前是静态设置的ip135,现在变成了129)

[root@135 Desktop]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C1:E2:78  
          inet addr:192.168.197.129  Bcast:192.168.197.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec1:e278/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12562 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12696 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1132479 (1.0 MiB)  TX bytes:1389920 (1.3 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5784 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5784 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:522236 (509.9 KiB)  TX bytes:522236 (509.9 KiB)

8.回到搭建有DHCP服务的主机A上,查看DHCP的服务日志/var/log/messages,进一步了解,DHCP的工作原理(即租约四部曲)。

[root@oracle dhcp]# tail -10 /var/log/messages
Jun 23 06:56:49 oracle dhcpd: Wrote 0 leases to leases file.
Jun 23 06:56:49 oracle dhcpd: Listening on LPF/eth0/00:0c:29:64:b4:6d/192.168.197.0/24
Jun 23 06:56:49 oracle dhcpd: Sending on   LPF/eth0/00:0c:29:64:b4:6d/192.168.197.0/24
Jun 23 06:56:49 oracle dhcpd: Sending on   Socket/fallback/fallback-net
Jun 23 07:00:31 oracle dhcpd: DHCPDISCOVER from 00:0c:29:c1:e2:78 via eth0
Jun 23 07:00:31 oracle dhcpd: ns1.example.org: temporary name server failure
Jun 23 07:00:31 oracle dhcpd: ns2.example.org: temporary name server failure
Jun 23 07:00:31 oracle dhcpd: DHCPOFFER on 192.168.197.129 to 00:0c:29:c1:e2:78 (135) via eth0
Jun 23 07:00:31 oracle dhcpd: DHCPREQUEST for 192.168.197.129 (192.168.197.134) from 00:0c:29:c1:e2:78 (135) via eth0
Jun 23 07:00:31 oracle dhcpd: DHCPACK on 192.168.197.129 to 00:0c:29:c1:e2:78 (135) via eth0

获取请求:MAC地址为00:0c:29:c1:e2:78的主机发出来的

Jun 23 07:00:31 oracle dhcpd: DHCPDISCOVER from 00:0c:29:c1:e2:78 via eth0

向客户机B发送OFFER

Jun 23 07:00:31 oracle dhcpd: DHCPOFFER on 192.168.197.129 to 00:0c:29:c1:e2:78 (135) via eth0

收到来自客户机B的确认IP消息DHCPREQUEST

Jun 23 07:00:31 oracle dhcpd: DHCPREQUEST for 192.168.197.129 (192.168.197.134) from 00:0c:29:c1:e2:78 (135) via eth0

发送给客户机B的最终租约确认

Jun 23 07:00:31 oracle dhcpd: DHCPACK on 192.168.197.129 to 00:0c:29:c1:e2:78 (135) via eth0

4.2.DHCP的地址保留实验(固定地址分配)

目的:使得客户机B每次利用DHCP服务获取的IP地址是一样的,保持不变的IP
在这里插入图片描述
修改配置文件:/etc/dhcp/dhcpd.conf
在这里插入图片描述
重启DHCPD服务service dhcpd restart

[root@oracle dhcp]# service dhcpd restart
Shutting down dhcpd:                                       [  OK  ]
Starting dhcpd:                                            [  OK  ]

在客户机上执行 :ifdown eth0;ifup eth0 重启eth0网卡,检查IP地址
在这里插入图片描述

4.3超级作用域(同一局域网)

当局域网的主机台数超过一个网段的台数时,多于255了,需要在不改变为B类网段的情况下,添加主机台数,和之前的局域网主机能够通信。在生产环境中只需要利用路由器(路由器有DHCP的功能)的单臂路由的功能,在原来的基础上,添加另一个IP地址,就可以通过路由器,让不同网段的局域网主机进行通信。
下面为模拟实验环境
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.4 DHCP中继

模拟的环境就是,局域网A网段的主机A,通过DHCP服务+一台DHCP中继器,可以将局域网B网段的主机B进行连接,使得DHCP服务可以为不同网段的主机,实现分配IP的功能,依靠的就是DHCP中继服务的能力。
下图为本人粗略根据理解所画的草图,正确性不敢保证
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
isc-dhcp option是指Internet Systems Consortium Dynamic Host Configuration Protocol (ISC-DHCP)中的一个功能,它允许管理员在DHCP服务器上配置和控制DHCP客户端的一些选项和参数。 ISC-DHCP是一种网络协议,它用于自动分配IP地址、网关、DNS服务器等网络设置,以简化网络管理。在ISC-DHCP服务器上配置并添加option,可以向客户端提供一些额外的选项和参数,以满足特定的网络需求。 ISC-DHCP服务器支持多种不同的option类型,包括基本的网络参数如DNS服务器、域名、时间服务器等,还包括一些自定义的选项。管理员可以在DHCP服务器的配置文件中指定这些option的值,然后将其分配给特定的DHCP客户端。 使用ISC-DHCP option,管理员能够对客户端进行更精细的网络定制。例如,可以通过设置DNS服务器option为特定的IP地址,让客户端在获取IP地址时同时获得正确的DNS服务器信息,从而实现域名解析功能。还可以配置时间服务器option,让客户端同步网络时间。此外,还可以通过其他自定义的option,向客户端提供详细的网络配置信息,如代理服务器、NTP服务器等。 在实际应用中,ISC-DHCP option广泛用于不同类型的网络环境,如企业网络、学校网络、公共无线网络等。它提供了一种简单且灵活的方式,让管理员能够根据具体需求为DHCP客户端提供定制化的网络配置。通过合理配置ISC-DHCP option,可以提高网络的稳定性和性能,并简化网络管理的工作量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值