路由器多区域 OSPF 配置
实训三十四 路由器多区域 OSPF 配置
定义:OSPF路由协议是用于网际协议(IP)网络的链路状态路由协议。该协议使用链路状态路由算法的内部网关协议(IGP),在单一自治系统(AS)内部工作。
概述:开放式最短路径优先(Open Shortest Path First,OSPF)是广泛使用的一种动态路由协议,它属于链路状态路由协议,具有路由变化收敛速度快、无路由环路、支持变长子网掩码(VLSM)和汇总、层次区域划分等优点。在网络中使用OSPF协议后,大部分路由将由OSPF协议自行计算和生成,无须网络管理员人工配置,当网络拓扑发生变化时,协议可以自动计算、更正路由,极大地方便了网络管理。但如果使用时不结合具体网络应用环境,不做好细致的规划,OSPF协议的使用效果会大打折扣,甚至引发故障。
OSPF协议是一种链路状态协议。每个路由器负责发现、维护与邻居的关系,并将已知的邻居列表和链路费用LSU(Link State Update)报文描述,通过可靠的泛洪与自治系统AS(Autonomous System)内的其他路由器周期性交互,学习到整个自治系统的网络拓扑结构;并通过自治系统边界的路由器注入其他AS的路由信息,从而得到整个Internet的路由信息。每隔一个特定时间或当链路状态发生变化时,重新生成LSA,路由器通过泛洪机制将新LSA通告出去,以便实现路由的实时更新。
优点
(1)OSPF适合在大范围的网络:OSPF协议当中对于路由的跳数,它是没有限制的,所以OSPF协议能用在许多场合,同时也支持更加广泛的网络规模。只要是在组播的网络中,OSPF协议能够支持数十台路由器一起运作。
(2)组播触发式更新:OSPF协议在收敛完成后,会以触发方式发送拓扑变化的信息给其他路由器,这样就可以减少网络宽带的利用率;同时,可以减小干扰,特别是在使用组播网络结构,对外发出信息时,它对其他设备不构成其他影响
(3)收敛速度快:如果网络结构出现改变,OSPF协议的系统会以最快的速度发出新的报文,从而使新的拓扑情况很快扩散到整个网络;而且,OSPF采用周期较短的HELLO报文来维护邻居状态。
(4)以开销作为度量值:OSPF协议在设计时,就考虑到了链路带宽对路由度量值的影响。OSPF协议是以开销值作为标准,而链路开销和链路带宽,正好形成了反比的关系,带宽越是高,开销就会越小,这样一来,OSPF选路主要基于带宽因素。
(5)OSPF协议的设计是为了避免路由环路:在使用最短路径的算法下,收到路由中的链路状态,然后生成路径,这样不会产生环路。
(6)应用广泛:广泛的应用在互联网上,其他会有大量的应用实例。证明这是使用最广泛的IPG之一
缺点
(1)OSPF协议的配置对于技术水平要求很高,配置比较复杂的。因为网络会根据具体的参数,给整个网络划分区域或者标注某个属性,所以各种情况都会非常复杂,这就要求网络分析员对OSPF协议的配置要相当了解,不但要求具有普通的网络知识技术,还要有更深层的技术理解,只有具备这样的人员,才能完成OSPF协议的配置和日常维护。
(2)路由其自身的负载分担能力是很低的。OSPF路由协议会根据几个主要的因素,生成优先级不同的接口。然而在同一个区域内,路由协议只会通过优先级最高的那个接口。只要是接口优先级低于最高优先级,那么路由就不会通过。在这个基础上,不同等级的路由,无法相互承担负载,只能独自运行。
OSPF的数据包:
Hello包
DBD–数据库描述包
LSR–链路状态请求
LSU–链路状态更新 携带各种LSA
LSack–链路状态确认
一、实验目的
1.掌握多区域 OSPF 的配置
2.理解 OSPF 区域的意义
二、应用环境
在大规模网络中,我们通常划分区域减少资源消耗,并将拓扑的变化本地化。
三、实验设备
1.路由器三台
2.网线 三条
3.pc二台
四、
实验拓扑
五、实验要求
路由器 | 接口 | IP地址 |
RA | G0/3 | 192.168.1.1/24 |
G0/4 | 192.168.0.1/24 | |
RB | G0/3 | 192.168.1.2/24 |
G0/4 | 192.168.2.1/24 | |
RC | G0/3 | 192.168.3.1/24 |
G0/4 | 192.168.2.2/24 |
六、实验步骤
第一步:参照上表配置各接口地址,并测试连通性
路由器 A 的配置
face g0/4 RA#config !进入全局模式
RA_config#interface g0/3 !进入接口模式
RA_config_g0/3#ip add 192.168.1.1 255.255.255.0 !设置 IP 地址
RA_config_g0/3#no shutdown ! 开启接口
RA_config_g0/3#exit !退出接口模式
RA_config#
RA_config#inter G0/4
RA_config_g0/4#ip add 192.168.0.1 255.255.255.0
RA_config_g0/4#no shutdown
RA_config_g0/4#exit
路由器 B 和 C 的配置步骤同路由器 A 一样。
第二步:路由器 A 的配置
RA#confing
RA_config#router ospf 1 !启动 OSPF 进程,进程号为 1
RA_config_ospf_1#network 192.168.1.0 255.255.255.0 area 1 !宣称 IP 地址到 1 区域
RA_config_ospf_1#network 192.168.0.0 255.255.255.0 area 1 !注意要写掩码和区域号
RA_config_ospf_100#^Z !按 ctrl+z,直接进入特权模式
第三步:路由器 B 的配置
Router-B#confing
RB_config#router ospf 1
RB_config_ospf_1#network 192.168.1.0 255.255.255.0 area 1 !注意区域的划分在接口上
RB_config_ospf_1#network 192.168.2.0 255.255.255.0 area 0
Router-B_config_ospf_100#^Z
第四步:路由器 C 的配置
Router-C#confing
RC_config#router ospf 1
RC_config_ospf_1#network 192.168.2.0 255.255.255.0 area 0
RC_config_ospf_1#network 192.168.3.0 255.255.255.0 area 0
Router-C_config_ospf_100#^Z
第五步:查看路由表
RA_config#show ip route
Codes: C - connected, S - static, R - RIP, B - BGP, BC - BGP connected
D - BEIGRP, DEX - external BEIGRP, O - OSPF, OIA - OSPF inter area
ON1 - OSPF NSSA external type 1, ON2 - OSPF NSSA external type 2
OE1 - OSPF external type 1, OE2 - OSPF external type 2
DHCP - DHCP type, L1 - IS-IS level-1, L2 - IS-IS level-2
VRF ID: 0
C 192.168.0.0/24 is directly connected, GigaEthernet0/4
C 192.168.1.0/24 is directly connected, GigaEthernet0/3
O IA 192.168.2.0/24 [110,2] via 192.168.1.2(on GigaEthernet0/3)
O IA 192.168.3.0/24 [110,3] via 192.168.1.2(on GigaEthernet0/3) !区域间的路由
RB_config#show ip route
Codes: C - connected, S - static, R - RIP, B - BGP, BC - BGP connected
D - BEIGRP, DEX - external BEIGRP, O - OSPF, OIA - OSPF inter area
ON1 - OSPF NSSA external type 1, ON2 - OSPF NSSA external type 2
OE1 - OSPF external type 1, OE2 - OSPF external type 2
DHCP - DHCP type, L1 - IS-IS level-1, L2 - IS-IS level-2VRF ID: 0
O 192.168.0.0/24 [110,2] via 192.168.1.1(on GigaEthernet0/3)
C 192.168.1.0/24 is directly connected, GigaEthernet0/3
C 192.168.2.0/24 is directly connected, GigaEthernet0/4
O 192.168.3.0/24 [110,2] via 192.168.2.2(on GigaEthernet0/4)
!对 ABR 来说是区域内的路由
RC_config#show ip route
Codes: C - connected, S - static, R - RIP, B - BGP, BC - BGP connected
D - BEIGRP, DEX - external BEIGRP, O - OSPF, OIA - OSPF inter area
ON1 - OSPF NSSA external type 1, ON2 - OSPF NSSA external type 2
OE1 - OSPF external type 1, OE2 - OSPF external type 2
DHCP - DHCP type, L1 - IS-IS level-1, L2 - IS-IS level-2
VRF ID: 0
O IA 192.168.0.0/24 [110,3] via 192.168.2.1(on GigaEthernet0/4)
O IA 192.168.1.0/24 [110,2] via 192.168.2.1(on GigaEthernet0/4) !区域间的路由
C 192.168.2.0/24 is directly connected, GigaEthernet0/4
C 192.168.3.0/24 is directly connected, GigaEthernet0/3
七、注意事项和排错
1.区域的划分在接口上进行
2.必须有 area 0 存在
3. 宣称 IP 地址时要写掩码
八、配置序列
路由器 A 的序列
RA_config#show run
Building configuration...
Current configuration:
!
!version 1.3.3H
service timestamps log date
service timestamps debug date
no service password-encryption
!
hostname RA
!
gbsc group default
!
interface FastEthernet0/0
no ip address
no ip directed-broadcast!
interface GigaEthernet0/3
ip address 192.168.1.1 255.255.255.0 !查看 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/4
ip address 192.168.0.1 255.255.255.0 !查看 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/5
no ip address
no ip directed-broadcast
!
interface GigaEthernet0/6
no ip address
no ip directed-broadcast
!
interface Serial0/1
no ip address
no ip directed-broadcast
!
interface Serial0/2
no ip address
no ip directed-broadcast
!
interface Async0/0
no ip address
no ip directed-broadcast
!
router ospf 1 !查看 ospf 进程
network 192.168.1.0 255.255.255.0 area 1
network 192.168.0.0 255.255.255.0 area 1 !查看 ospf 宣称的网段到哪个区域
!
路由器 B 的序列
RB_config#show run
Building configuration...
Current configuration:
!
!version 1.3.3H
service timestamps log date
service timestamps debug date
no service password-encryption
!
hostname RB
!
gbsc group default!
interface FastEthernet0/0
no ip address
no ip directed-broadcast
!
interface GigaEthernet0/3
ip address 192.168.1.2 255.255.255.0 !查看接口 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/4
ip address 192.168.2.1 255.255.255.0 !查看接口 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/5
no ip address
no ip directed-broadcast
!
interface GigaEthernet0/6
no ip address
no ip directed-broadcast
!
interface Serial0/1
no ip address
no ip directed-broadcast
!
interface Serial0/2
no ip address
no ip directed-broadcast
!
interface Async0/0
no ip address
no ip directed-broadcast
!
router ospf 1 !查看 ospf 进程
network 192.168.1.0 255.255.255.0 area 1
network 192.168.2.0 255.255.255.0 area 0 !查看 ospf 宣称的网段到哪个区域
!
路由器 C 的序列
RC_config#show run
Building configuration...
Current configuration:
!
!version 1.3.3H
service timestamps log date
service timestamps debug date
no service password-encryption!
hostname RC
!
gbsc group default
!
interface FastEthernet0/0
no ip address
no ip directed-broadcast
!
interface GigaEthernet0/3
ip address 192.168.3.1 255.255.255.0 !查看接口 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/4
ip address 192.168.2.2 255.255.255.0 !查看接口 IP 地址
no ip directed-broadcast
!
interface GigaEthernet0/5
no ip address
no ip directed-broadcast
!
interface GigaEthernet0/6
no ip address
no ip directed-broadcast
!
interface Serial0/1
no ip address
no ip directed-broadcast
!
interface Serial0/2
no ip address
no ip directed-broadcast
!
interface Async0/0
no ip address
no ip directed-broadcast
!
router ospf 1 !查看 ospf 进程
network 192.168.2.0 255.255.255.0 area 0
network 192.168.3.0 255.255.255.0 area 0 !查看 ospf 宣称的网段到哪个区域
!
九、共同思考
1.为什么必须有 area 0 存在?
2.在路由器 A 和 C 宣告网段的时候有其他的方法吗?
十、课后练习
请将地址改为 10.0.0.0/25 重复以上实验
十一、相关命令详解
router ospf process-id
network address mask area area-id
此命令激活 OSPF 路由协议,并且进入路由器配置模式,然后配置 OSPF 运行的接口以及接口的区
域 ID。 可以用命令 no router ospf process-id 去掉 ospf 进程。