OSPF动态路由协议

一、OSPF实验拓扑

在这里插入图片描述

基础配置

# 配置ip地址,必须配环回接口

#配置ospf
方式一
R1(config)#router ospf 1
R1(config-router)#network 1.0.0.0 0.0.0.255 area 0
方式二
R2(config)#int range e0/0-1,lo0
R2(config-if-range)#ip ospf 1 area 0

R1:

int range e0/0,lo0
ip ospf 1 area 0

R2:

int range e0/0-1,lo0
ip ospf 1 area 0

R3:

int range e0/0,lo0
ip ospf 1 area 0

管理距离

在这里插入图片描述
R1:

int e0/0
ip address 192.168.12.1 255.255.255.0
no sh
int e0/1
ip addr 192.168.14.1 255.255.255.0
no sh
int lo0
ip add 1.1.1.1 255.255.255.255

router rip
ver 2
network 192.168.12.0
network 1.1.1.1

int range e0/1,lo0
ip ospf 1 area 0

R2:

int e0/0
ip add 192.168.12.2 255.255.255.0
no sh
int e0/1
ip add 192.168.23.2 255.255.255.0
no sh
int lo0
ip add 2.2.2.2 255.255.255.255

router rip
ver 2
network 192.168.12.0
network 192.168.23.0
network 2.2.2.2

R3:

int e0/0
ip add 192.168.23.3 255.255.255.0
no sh
int e0/1
ip addr 192.168.34.3 255.255.255.0
no sh
int lo0
ip add 3.3.3.3 255.255.255.255

router rip
ver 2
network 192.168.23.0
network 3.3.3.3

int range e0/1,lo0
ip ospf 1 area 0

R4:

int e0/0
ip add 192.168.14.4 255.255.255.0
no sh
int e0/1
ip add 192.168.34.4 255.255.255.0
no sh
int lo0
ip add 4.4.4.4 255.255.255.255

int range lo0,e0/0-1
ip ospf 1 area 0
R3#show ip route
Codes: 	L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
		D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
		N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
		E1 - OSPF external type 1, E2 - OSPF external type 2
		i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
		ia - IS-IS inter area, * - candidate default, U - per-user static route
		o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
		a - application route
		+ - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set
		
		1.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
R 		1.0.0.0/8 [120/2] via 192.168.23.2, 00:00:19, Ethernet0/0
O 		1.1.1.1/32 [110/21] via 192.168.34.4, 00:00:21, Ethernet0/1
......

R3#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
  1 192.168.34.4 5 msec 6 msec 5 msec
  2 192.168.14.1 1 msec * 1 msec

可以看到在两个路由表都可以去1.1.1.1的时候,选择了匹配更精确的那一条,这里是因为最长匹配原则
所以在
R 	1.0.0.0/8
O 	1.1.1.1/32
两个路由中选择了下面一条,但是我们是要为了验证管理距离对于选路的影响,所以可以关闭rip协议的自动汇总,再重启一下接口,更新路由表,可以看到更新完成后,只有一条路由表
R3#show ip route
Codes: 	L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
		D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
		N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
		E1 - OSPF external type 1, E2 - OSPF external type 2
		i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
		ia - IS-IS inter area, * - candidate default, U - per-user static route
		o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
		a - application route
		+ - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set

		1.0.0.0/32 is subnetted, 1 subnets
O 1.1.1.1 [110/21] via 192.168.34.4, 00:08:08, Ethernet0/1
.......
R3#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
  1 192.168.34.4 1 msec 1 msec 0 msec
  2 192.168.14.1 0 msec * 1 msec
最终选择了管理距离短的ospf协议的路径

OSPF简介

  • OSPF(Open Shortest Path First,开放最短路径优先)是一种链路状态路由协议,无路由循环(全局拓扑),属于IGP。RFC 2328,“开放”意味着非私有的,对公众开放的。

  • OSPF的报文封装

  • OSPF协议包直接封装于IP,协议号89。

  • OSPF协议使用的组播地址

  • 所有OSPF路由器——224.0.0.5;DR BDR——224.0.0.6

  • OSPF路由协议的管理距离:110

二、路由重发步概念

  • 是可以将不同的自治系统他们之间的路由信息进行交换
  • 从一种协议到另外一种协议
  • 同一种协议的不同实例
  • 路由重发是针对外部的,自身的路由器不会有变化

拓扑

路由重发步
R2的环回接口接入ospf协议

R2#sh ip route
	1.0.0.0/24 is subnetted, 1 subnets
R	 1.1.1.0 [120/1] via 192.168.12.1, 00:00:15, Ethernet0/0
	2.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C	 2.2.2.0/24 is directly connected, Loopback0
L	 2.2.2.2/32 is directly connected, Loopback0
	3.0.0.0/32 is subnetted, 1 subnets
O	 3.3.3.3 [110/11] via 192.168.23.3, 00:02:40, Ethernet0/1
	192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.12.0/24 is directly connected, Ethernet0/0
L	 192.168.12.2/32 is directly connected, Ethernet0/0
	192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.23.0/24 is directly connected, Ethernet0/1
L	 192.168.23.2/32 is directly connected, Ethernet0/1

R1#sh ip route
	1.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C	 1.1.1.0/24 is directly connected, Loopback0
L	 1.1.1.1/32 is directly connected, Loopback0
	192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.12.0/24 is directly connected, Ethernet0/0
L	 192.168.12.1/32 is directly connected, Ethernet0/0

R3#sh ip route
	2.0.0.0/32 is subnetted, 1 subnets
O	 2.2.2.2 [110/11] via 192.168.23.2, 00:00:12, Ethernet0/0
	3.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C	 3.3.3.0/24 is directly connected, Loopback0
L	 3.3.3.3/32 is directly connected, Loopback0
	192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.23.0/24 is directly connected, Ethernet0/0
L	 192.168.23.3/32 is directly connected, Ethernet0/0

做双向重发步
R2(config-if-range)#router rip
R2(config-router)#ver 2
R2(config-router)#redistribute ospf 1 metric 5
R2(config-router)#router ospf 1
R2(config-router)#redistribute rip subnets

再次检查路由表
R1#sh ip route
	1.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C	 1.1.1.0/24 is directly connected, Loopback0
L	 1.1.1.1/32 is directly connected, Loopback0
	2.0.0.0/24 is subnetted, 1 subnets
R	 2.2.2.0 [120/5] via 192.168.12.2, 00:00:28, Ethernet0/0
	3.0.0.0/32 is subnetted, 1 subnets
R	 3.3.3.3 [120/5] via 192.168.12.2, 00:00:28, Ethernet0/0
	192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.12.0/24 is directly connected, Ethernet0/0
L	 192.168.12.1/32 is directly connected, Ethernet0/0
R	 192.168.23.0/24 [120/5] via 192.168.12.2, 00:00:28, Ethernet0/0

R2#sh ip route
	1.0.0.0/24 is subnetted, 1 subnets
R	 1.1.1.0 [120/1] via 192.168.12.1, 00:00:24, Ethernet0/0
	2.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C	 2.2.2.0/24 is directly connected, Loopback0
L	 2.2.2.2/32 is directly connected, Loopback0
	3.0.0.0/32 is subnetted, 1 subnets
O	 3.3.3.3 [110/11] via 192.168.23.3, 00:07:58, Ethernet0/1
	192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.12.0/24 is directly connected, Ethernet0/0
L	 192.168.12.2/32 is directly connected, Ethernet0/0
	192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C	 192.168.23.0/24 is directly connected, Ethernet0/1
L	 192.168.23.2/32 is directly connected, Ethernet0/1

R3# sh ip route
	1.0.0.0/24 is subnetted, 1 subnets
O E2	 1.1.1.0 [110/20] via 192.168.23.2, 00:02:30, Ethernet0/0
	2.0.0.0/32 is subnetted, 1 subnets
O		 2.2.2.2 [110/11] via 192.168.23.2, 00:04:10, Ethernet0/0
	3.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C		 3.3.3.0/24 is directly connected, Loopback0
L		 3.3.3.3/32 is directly connected, Loopback0
O E2	 192.168.12.0/24 [110/20] via 192.168.23.2, 00:02:30, Ethernet0/0
	192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C		 192.168.23.0/24 is directly connected, Ethernet0/0
L		 192.168.23.3/32 is directly connected, Ethernet0/0

三、OSPF三张表

ospf三张表

R2#show ip ospf nei
Neighbor 	ID 	Pri 	State 		Dead Time 	Address Interface
3.3.3.3 		1 		FULL/DR 	00:00:31 	192.168.23.3 Ethernet0/1
1.1.1.1 		1 		FULL/BDR 	00:00:39 	192.168.12.1 Ethernet0/0

OSPF名词

  • Neighbor ID:邻居的id,这个id通常是由环回接口选的,并且是优先选取地址大的作为id
    • 在一个OSPF域中,唯一地标识一台OSPF路由器
    • 32bits,表现为IPv4地址形式。在未有手工指定的情况下,如果本地有激活的Loopback接口,则取Loopback接口IP最大值;如果没有LP接口,则取激活的物理接口IP中的最大值
    • 为了提高路由器的RID的稳定性和网络的稳定性建议手动的设置路由器的Router-ID:在OSPF的进程下修改:router-id <x.x.x.x>(建议id值以编号为准)
    router ospf 1
    router-id 30.30.30.30
    
    • 项目实施中,一般是建立loopback口,并且手工指定loopback口地址为router-id
  • Pri:优先级
  • Dead Time:死亡时间,每十秒钟会更新一次,如果40秒倒计时结束还没有收到邻居的hello包,认为邻居死亡
  • State:邻居的状态
    • 一个网段选举一个DR和BDR
    • DR
      • DR的作用:多路访问中为了减少邻接关系(N平方的问题)和LSA的洪泛,采用DR机制,BDR提供了备份
      • MA(multiple access)网络上的所有路由器均与DR、BDR建立邻居关系
    • BDR
      • 选举规则
      • 接口优先级数字越大越优先(优先级为0不能参与DR的选举)
      • Router ID越大越好
      • 稳定压倒一切(非抢占)
      • 通过控制接口优先级是控制DR选举的好办法
      • DR的选举是基于接口的,如果说某个路由器是DR,这种说法是错误的
        在这里插入图片描述
    • 在某些以太网中并不需要建立DR、BDR的过程,可以将模式修改为point-to-point来加速邻居建立的过程
R2(config)#int e0/0
R2(config-if)#ip ospf network point-to-point
R1#sh ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 0 FULL/ - 00:00:32 192.168.12.2 Ethernet0/0
# 状态中是没有DR或者BDR的
  • 优先级设置
int e0/0
ip ospf priority 5
  • 清除ospf邻居
clear ip ospf nei
  • OSPF COST

    • OSPF接口COST=参考带宽(10的8次方,单位为b)/ 接口带宽
    • 接口带宽为接口逻辑带宽,可以使用bandwith命令调整(这里默认单位为kb),主要用于路由计算,而不是接口物理带宽,但一般情况:接口逻辑带宽=接口物理带宽。
    • 手工修改接口Cost的方法
    Router(config)# int e0/0
    Router(config-if)# ip ospf cost 100 该命令在接收路由的入口上配置,也就是数据流量的出口
    
    • 也可以修改带宽值,进而修改cost值
    Router(config)# int e0/0
    Router(config-if)# bandwidth 100
    
    • 可修改“参考带宽”,来保障OSPF在现如今的网络中正常运转
      • 建议将参考带宽设置为整个网络中的最大带宽
      • auto-cost reference-bandwidth <参考带宽以Mbits为单位>

四、邻居建立过程

  • Down
    • 路由器未开始运行OSPF
  • Init
    • 路由器收到对方发过来的hello,但是却没有发现存在自己的Router-Id
  • Two-way
    • 路由器收到对方发过来的hello中,是包含有自己的Router-ID
    • 表示双方已经正常通信
    • 如果是广播网络类型,在这个阶段会等待40s,等所有路由器的Hello都充分交换,然后选择Router-id最大的作为DR,过时不候。
  • Ex-Start
    • 路由器发送空的DBD数据报文,用来选举由谁来主导整个过程,最终是选择Router-id较大的
    • L置位表示是否完成选举过程,M置位表示是否是最后一条消息,MS置位表示的是否是MASTER
  • Exchange
    • 路由器交换互相的DBD,可以理解为目录,从的节点率先发送给主节点
    • 比对哪些LSA是自己没有的
  • Loading
    • 向对方发送请求的LSA,接受对方的LSA,可以理解为书的内容
    • 并且回复ACK
  • Full
    • 完成建立过程

五、OSPF消息类型

  • hello包
    • 用来建立以及维护邻居关系(每10秒钟发送一次)的数据包
  • DBD
    • 链路状态数据库描述信息
  • LSR
    • 链路状态请求(Request),向邻居请求自己没有的信息
  • LSU
    • 链路状态更新(Update)的信息,可以包含一条或者多条
  • ACK
    • 确认消息,表示收到了

六、OSPF多区域

单区域的问题

  • 收到的LSA通告太多了,OSPF路由器的负担很大
  • 内部动荡会引起全网路由器的完全SPF计算
  • 资源消耗过多,LSDB庞大,设备性能下降,影响数据转发
  • 每台路由器都需要维护的路由表越来越大,单区域内路由无法汇总

多区域的特点

  • 减少了LSA洪泛的范围,有效地把拓扑变化控制在区域内,达到网络优化的目的
  • 在区域边界可以做路由汇总,减小了路由表
  • 充分利用OSPF特殊区域的特性,进一步减少LSA泛洪,从而优化路由
  • 多区域提高了网络的扩展性,有利于组建大规模的网络

区域

  • 骨干区域编号为0的区域

  • 非骨干区域编号非0的区域

  • 所有非骨干区域必须和骨干区域相连

OSPF路由器角色

在这里插入图片描述

  • ABR
    • 区域边界路由器,负责各个区域的路由条目传递
    • 必须至少有一个接口和骨干区域相连
    • 必须至少有一个接口和非骨干区域相连
  • ASBR
    • AS边界路由器,负责将ospf以外的路由引入

多区域基本拓扑

在这里插入图片描述
area1:
R1e0/0,lo0 R2 e0/0

area0:
R2 e0/1,lo0 R3 e0/0,lo0

area2:
R3 e0/1 R4 e0/0,lo0

  • 相关命令
show ip ospf
显示OSPF路由器ID,OSPF定时器以及LSA信息
show ip ospf interface type
显示各种定时器和邻接关系
show ip route ospf
显示路由器学习到的OSPF路由
show ip protocols
显示IP路由协议参数
debug ip ospf events
显示OSPF相关事件
debug ip ospf adj
跟踪邻接关系的建立和终止
debug ip ospf packet
查看正在传输的OSPF分组
  • 当非骨干区域没有和骨干区域直接相连,无法学习到其他区域的路由,如何解决这个问题
    在这里插入图片描述

area3: R1 e0/1 R5 e0/0,lo0

area4: R4 e0/1 R6 e0/0,lo0

  • 第一种方式是使用虚链路
R1(config)#router ospf 1
R1(config-router)#area 1 virtual-link 2.2.2.2
R2(config)#router ospf 1
R2(config-router)#area 1 virtual-link 1.1.1.1

当R1跟R2建立虚链路之后,就相当于R1直接起了一个虚拟的接口,这个虚拟接口划分在area0当中,也就相当于area3直接于area0相邻,area3中的信息也可以被其他区域正常学习了

  • 第二种方式是使用隧道
R3(config)#int tunnel 0
R3(config-if)#ip add 192.168.100.3 255.255.255.0
R3(config-if)#ip ospf 1 area 0
R3(config-if)#tunnel source e0/1
R3(config-if)#tunnel mode ipip
R3(config-if)#tunnel destination 192.168.34.4

R4(config)#int tunnel 0
R4(config-if)#ip add 192.168.100.4 255.255.255.0
R4(config-if)#ip ospf 1 area 0
R4(config-if)#tunnel source e0/0
R4(config-if)#tunnel mode ipip
R4(config-if)#tunnel destination 192.168.34.3

七、LSA

  • LSA(链路状态广播)是链接状态协议使用的一个分组,它包括有关邻居和通道成本的信息。 LSA被路由器接收用于维护它们的路由选择表。 LSA: Link-State Advertisement。
    在这里插入图片描述
类型解释
1路由器LSA
2网络LSA
3网络汇总LSA
4ASBR汇总LSA
5AS外部LSA
6组成员LSA
7NSSA外部LSA
8外部属性LSA
9Opaque LSA (链路本地范围)
10Opaque LSA (本地区域范围)
11Opaque LSA (AS范围)

拓扑:
在这里插入图片描述
R3,R4 lo接口放入area0中

1类LSA

  • 每个路由器针对它所在的区域产生LSA1,描述区域内部与路由器直连的链路的信息(包括链路类型,Cost等)
  • LSA1只允许在本区域内洪泛,不允许跨越ABR;
  • LSA中会标识路由器是否是ABR(B比特置位),ASBR(E比特置位)或者是Virtual-link(V比特置位)的端点的身份信息;
R1#sh ip ospf database
		OSPF Router with ID (1.1.1.1) (Process ID 1)
	Router Link States (Area 0)
Link ID 	ADV Router 	Age 	Seq# 	Checksum Link 	count
1.1.1.1 	1.1.1.1 	88 	0x80000005 	0x006F8C 3
2.2.2.2 	2.2.2.2 	89 	0x80000006 	0x000BE6 3
  • Link ID:链路ID,可以理解为目的地
  • ADV Router:链路来自哪一个路由器
  • Age:是计时器
  • Seq:序列号,初始值为 0x80000001,每收到一次数据包更新一次这个数值会+1, 加到0x8fffffff达到最大,下一次变为 0x80000000,ospf认为0x80000000是不可用的
  • Checksum:校验和

2类LSA

  • 描述TransNet(包括Broadcast和NBMA网络)网络信息;
  • 由DR生成,描述其在该网络上连接的所有路由器以及网段掩码信息,以及这个MA所属的路由器;
  • LSA类型2只在本区域Area内洪泛,不允许跨越ABR;
  • Network LSA ID是DR进行宣告的那个接口的IP地址
  • Network LSA 中没有COST字段
R1#sh ip ospf database network
			OSPF Router with ID (1.1.1.1) (Process ID 1)
		Net Link States (Area 0)
  LS age: 148
  Options: (No TOS-capability, DC)
  LS Type: Network Links
  Link State ID: 192.168.12.3 (address of Designated Router)
  Advertising Router: 3.3.3.3
  LS Seq Number: 80000002
  Checksum: 0x1484
  Length: 36
  Network Mask: /24
	Attached Router: 3.3.3.3
	Attached Router: 1.1.1.1
	Attached Router: 2.2.2.2
  • 通过LSA1,LSA2在区域内洪泛,使区域内每个路由器的LSDB达到同步,计算生成标识为“O”的路由,解决区域内部的通信问题。

3类LSA

  • ABR生成,实际上这就就是将区域内部的Type1 Type2的信息收集起来以路由子网的形式扩散出去,是Summay LSA中Summay的含义(注意这里的summary与路由汇总没有关系)
  • Type 3 的链路状态ID是目的网络地址。
  • 如果—台ABR路由器在与它本身相连的区域内有多条路由可以到达目的地,那么它将只会始发单一的一条网络汇总LSA到骨干区域,而且这条网络汇总LSA是上述多条路由中代价最低的
  • ABR收到来自同区域其它ABR传来的Type 3 LSA后重新生成新的Type3 LSA(Advertising Router改为自己)然后继续在整个OSPF系统内扩散
R1#show ip ospf database summary
			OSPF Router with ID (1.1.1.1) (Process ID 1)
		Summary Net Link States (Area 0)
  LS age: 145
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 5.5.5.5 (summary Network Number)
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000001
  Checksum: 0xD441
  Length: 28
  Network Mask: /32
    MTID: 0 Metric: 11
  LS age: 186
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 192.168.25.0 (summary Network Number)
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000001
  Checksum: 0xEBBC
  Length: 28
  Network Mask: /24
	MTID: 0 Metric: 10

4类LSA

  • ASBR Summary LSA由ABR生成,用于描述ABR能够到达的ASBR它的链路状态,链路状态ID为目的ASBR的RID。
#给R1再定义个环回接口,使用重发步的方式把路由加进去
R1(config-if)#int lo10
R1(config-if)#ip add 172.16.10.10 255.255.255.0
R1(config)#router ospf 1
R1(config-router)#redistribute connected subnets 

R5#sh ip ospf database asbr-summary
		OSPF Router with ID (5.5.5.5) (Process ID 1)
	Summary ASB Link States (Area 1)
LS age: 318
Options: (No TOS-capability, DC, Upward)
LS Type: Summary Links(AS Boundary Router)
Link State ID: 1.1.1.1 (AS Boundary Router address)
Advertising Router: 2.2.2.2
LS Seq Number: 80000001
Checksum: 0x75B0
Length: 28
Network Mask: /0
  MTID: 0 Metric: 10

5类LSA

  • Autonomous System External LSA由ASBR生成用于描述OSPF自治域系统外的目标网段信息,链路状态ID是目的地址的IP网络号。
  • 外部路由通过重发布,引入OSPF路由域,相应信息(路由条目)由ASBR以LSA5的形式生成然后进入OSPF路由域
  • OE2 开销= 外部开销;
  • OE1 开销= 外部开销+ 内部开销;
R1(config)#router ospf 1
R1(config-router)#no redistribute connected subnets
R1(config-router)#redistribute connected subnets metric-type 1
# metric-type不指定时默认重发布进来为OE2类型
R5#sh ip ospf database external
		OSPF Router with ID (5.5.5.5) (Process ID 1)
	Type-5 AS External Link States
LS age: 71
Options: (No TOS-capability, DC, Upward)
LS Type: AS External Link
Link State ID: 0.0.0.0 (External Network Number )
Advertising Router: 1.1.1.1
LS Seq Number: 80000002
Checksum: 0xA9E8
Length: 36
Network Mask: /0
  Metric Type: 1 (Comparable directly to link state metric)
  MTID: 0
  Metric: 666
  Forward Address: 0.0.0.0
  External Route Tag: 1

四类和五类的理解

  • 四类LSA告诉你怎么到达ASBR,由ABR产生
  • 五类LSA告诉你具体外部有哪些路由可以走,由ASBR产生

7类LSA

  • NSSA中的外部LSA NSSA External LSA
  • 在NSSA(非完全存根区域)not-so-stubby area中ASBR针对外部网络产生类似于LSA5的LSA类型7,
  • 链路ID是外部网路地址
  • LSA类型7只能在NSSA区域中洪泛,到达NSSA区域ABR后,NSSA ABR将其转换成LSA类型5外部路由,传播到Area 0,从而传播到整个OSPF路由域
  • 生成路由缺省用ON2表示,也可指定为ON1;
R2#sh ip ospf database nssa-external
		OSPF Router with ID (2.2.2.2) (Process ID 1)
	Type-7 AS External Link States (Area 1)
LS age: 493
Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
LS Type: AS External Link
Link State ID: 100.100.100.0 (External Network Number )
Advertising Router: 1.1.1.1
LS Seq Number: 80000002
Checksum: 0x4719
Length: 36
Network Mask: /24
  Metric Type: 2 (Larger than any link state path)
  MTID: 0
  Metric: 20
  Forward Address: 1.1.1.1
  External Route Tag: 0

八、特殊区域

拓扑

在这里插入图片描述

stub area

目的是精简自治系统外部的路由

  • 随着大量的5类LSA进入ospf区域,OSPF Database会变得庞大,同时路由表的外部地址也会增大。这会占用路由器大量的资源。
  • 解决这个问题的办法是:让Area内部的路由器不记录任何AS外部的地址,而使用ABR作为默认网关,有一条指向ABR的默认路由
  • 这种方式我们把它叫做stub area。
  • 配置
    • router ospf 2
    • area 1 stub
  • 在区域二里涉及到的所有路由器使用上述命令
  • 没有配置末梢节点之前的路由表
# 在R1上多定义几个环回接口,模拟庞大的信息
R1(config-if)#int lo20
R1(config-if)#ip add 172.16.20.20 255.255.255.0
R1(config)#int lo30
R1(config-if)#ip add 172.16.30.30 255.255.255.0
R1(config-if)#int lo40
R1(config-if)#ip add 172.16.40.40 255.255.255.0
R1(config-if)#int lo50
R1(config-if)#ip add 172.16.50.50 255.255.255.0
R1(config-if)#int lo60
R1(config-if)#ip add 172.16.60.60 255.255.255.0
R1(config-if)#int lo70
R1(config-if)#ip add 172.16.70.70 255.255.255.0
R1(config-if)#int lo80
R1(config-if)#ip add 172.16.80.80 255.255.255.0
R1(config-if)#int lo90
R1(config-if)#ip add 172.16.90.90 255.255.255.0

R6#sh ip route
O*E2 0.0.0.0/0 [110/1] via 192.168.46.4, 00:00:03, Ethernet0/0
	1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/31] via 192.168.46.4, 00:08:01, Ethernet0/0
	2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/31] via 192.168.46.4, 00:08:01, Ethernet0/0
	3.0.0.0/32 is subnetted, 1 subnets
O IA 3.3.3.3 [110/21] via 192.168.46.4, 00:08:01, Ethernet0/0
	4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/11] via 192.168.46.4, 00:08:01, Ethernet0/0
	5.0.0.0/32 is subnetted, 1 subnets
O 5.5.5.5 [110/21] via 192.168.46.4, 00:08:01, Ethernet0/0
	6.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 6.6.6.0/24 is directly connected, Loopback0
L 6.6.6.6/32 is directly connected, Loopback0
O IA 192.168.13.0/24 [110/30] via 192.168.46.4, 00:08:01, Ethernet0/0
O IA 192.168.23.0/24 [110/30] via 192.168.46.4, 00:08:01, Ethernet0/0
O IA 192.168.34.0/24 [110/20] via 192.168.46.4, 00:08:01, Ethernet0/0
O 192.168.45.0/24 [110/20] via 192.168.46.4, 00:08:01, Ethernet0/0
	192.168.46.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.46.0/24 is directly connected, Ethernet0/0
L 192.168.46.6/32 is directly connected, Ethernet0/0

将area2设置为末梢区域,这样旧学习不到自治系统外部的路由了

  • 配置了末梢节点之后的路由表
R4(config)#router ospf 1
R4(config-router)#area 2 stub
R5(config)#router ospf 1
R5(config-router)#area 2 stub
R6(config)#router ospf 1
R6(config-router)#area 2 stub

R6#sh ip route
O*IA 0.0.0.0/0 [110/11] via 192.168.46.4, 00:00:14, Ethernet0/0
	1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/31] via 192.168.46.4, 00:00:24, Ethernet0/0
	2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/31] via 192.168.46.4, 00:00:24, Ethernet0/0
	3.0.0.0/32 is subnetted, 1 subnets
O IA 3.3.3.3 [110/21] via 192.168.46.4, 00:00:24, Ethernet0/0
	4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/11] via 192.168.46.4, 00:00:24, Ethernet0/0
	5.0.0.0/32 is subnetted, 1 subnets
O 5.5.5.5 [110/21] via 192.168.46.4, 00:00:24, Ethernet0/0
	6.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 6.6.6.0/24 is directly connected, Loopback0
L 6.6.6.6/32 is directly connected, Loopback0
O IA 192.168.13.0/24 [110/30] via 192.168.46.4, 00:00:24, Ethernet0/0
O IA 192.168.23.0/24 [110/30] via 192.168.46.4, 00:00:24, Ethernet0/0
O IA 192.168.34.0/24 [110/20] via 192.168.46.4, 00:00:24, Ethernet0/0
O 192.168.45.0/24 [110/20] via 192.168.46.4, 00:00:24, Ethernet0/0
	192.168.46.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.46.0/24 is directly connected, Ethernet0/0
L 192.168.46.6/32 is directly connected, Ethernet0/0
R6#	

totally stub area

  • 有时仅仅不学习外部路由仍然不能够满足需求,路由表和ospf的数据库依然非常庞大,这个时候可以连ospf的其他区域的路由也不学习
  • 只学习本区域的路由,以及有一条指向ABR的默认路由
  • 配置与stub不同的是在ABR上配置area 2 stub no-summary
  • totally stub area的路由表
R4(config-router)#router ospf 1
R4(config-router)#no area 2 stub
R4(config-router)#area 2 stub no-summary
R5(config-router)#router ospf 1
R5(config-router)#no area 2 stub
R5(config-router)#area 2 stub no-summary
R6(config)#router ospf 1
R6(config-router)#no area 2 stub
R6(config-router)#area 2 stub no-summary

R6#sh ip route
O*IA 0.0.0.0/0 [110/11] via 192.168.46.4, 00:08:11, Ethernet0/0
	5.0.0.0/32 is subnetted, 1 subnets
O 5.5.5.5 [110/21] via 192.168.46.4, 00:08:21, Ethernet0/0
	6.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 6.6.6.0/24 is directly connected, Loopback0
L 6.6.6.6/32 is directly connected, Loopback0
O 192.168.45.0/24 [110/20] via 192.168.46.4, 00:08:21, Ethernet0/0
	192.168.46.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.46.0/24 is directly connected, Ethernet0/0
L 192.168.46.6/32 is directly connected, Ethernet0/0
只有本区域的路由和一条默认路由

NSSA area

  • 当我们把区域配置成末梢区域时,有时候有特例想要加入一些外部路由,这个时候nssa允许存在ASBR通过7类LSA的方式将外部路由引入本区域,不会自动注入默认路由

  • 不会学习外部路由

  • 会学习其他区域路由

  • 可以学习ASBR注入的外部路由

  • 没有注入默认路由

  • 配置

  • 在区域内所有路由器配置以下命令

  • router ospf 1

  • area 1 nssa

  • 配置NSSA之前的路由表

R6(conf-if)#int lo100
R6(conf-if)#ip add 100.100.100.100 255.255.255.0
R6(config)#router ospf 1
R6(config-router)#redistribute connected subnets

R5#sh ip route
O*IA 0.0.0.0/0 [110/11] via 192.168.45.4, 00:03:09, Ethernet0/0
	5.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 5.5.5.0/24 is directly connected, Loopback0
L 5.5.5.5/32 is directly connected, Loopback0
	6.0.0.0/32 is subnetted, 1 subnets
O 6.6.6.6 [110/21] via 192.168.45.4, 00:02:59, Ethernet0/0
	192.168.45.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.45.0/24 is directly connected, Ethernet0/0
L 192.168.45.5/32 is directly connected, Ethernet0/0
O 192.168.46.0/24 [110/20] via 192.168.45.4, 00:03:09, Ethernet0/0
  • 配置成NSSA区域之后的路由表
R4(config)#router ospf 1
R4(config-router)#no area 2 stub no-summary
R4(config-router)#no area 2 stub
R4(config-router)#area 2 nssa
R5(config)#router ospf 1
R5(config-router)#no area 2 stub no-summary
R5(config-router)#no area 2 stub
R5(config-router)#area 2 nssa
R6(config)#router ospf 1
R6(config-router)#no area 2 stub no-summary
R6(config-router)#no area 2 stub
R6(config-router)#area 2 nssa

R5#sh ip route
	1.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 1.1.1.0/24 is directly connected, Loopback0
L 1.1.1.1/32 is directly connected, Loopback0
	2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/21] via 192.168.13.3, 00:00:02, Ethernet0/0
	3.0.0.0/32 is subnetted, 1 subnets
O IA 3.3.3.3 [110/11] via 192.168.13.3, 00:00:12, Ethernet0/0
	4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/21] via 192.168.13.3, 00:00:12, Ethernet0/0
	5.0.0.0/32 is subnetted, 1 subnets
O IA 5.5.5.5 [110/31] via 192.168.13.3, 00:00:12, Ethernet0/0
	6.0.0.0/32 is subnetted, 1 subnets
O IA 6.6.6.6 [110/31] via 192.168.13.3, 00:00:12, Ethernet0/0
	192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks
O N2 100.100.100.0 [110/20] via 192.168.23.3, 00:00:19, Ethernet0/0
C 192.168.13.0/24 is directly connected, Ethernet0/0
L 192.168.13.1/32 is directly connected, Ethernet0/0
O 192.168.23.0/24 [110/20] via 192.168.13.3, 00:00:12, Ethernet0/0
O IA 192.168.34.0/24 [110/20] via 192.168.13.3, 00:00:12, Ethernet0/0
O IA 192.168.45.0/24 [110/30] via 192.168.13.3, 00:00:12, Ethernet0/0
O IA 192.168.46.0/24 [110/30] via 192.168.13.3, 00:00:12, Ethernet0/0
还是没有学习到其他区域的外部的172.16.x.x的路由,但是本区域的100.100.100.100学习到了
R5#sh ip ospf data
Type-7 AS External Link States (Area 2)

Link ID ADV Router Age Seq# Checksum Tag
100.100.100.0 6.6.6.6 208 0x80000001 0x00AD8B 0
可以看到通过7类lsa实现的本区域外部路由的学习

Totally NSSA area

  • 不会学习外部路由
  • 不会学习其他区域路由
  • 可以学习ASBR注入的外部路由
  • 会自动注入默认路由
  • 配置:与nssa不同的是在ABR上配置以下命令
    • router ospf 1
    • area 1 nssa no-summary
R4(config)#router ospf 1
R4(config-router)#area 2 nssa no-summary
R5(config)#router ospf 1
R5(config-router)#area 2 nssa no-summary
R6(config)#router ospf 1
R6(config-router)#area 2 nssa no-summary

R5#sh ip route
O*IA 0.0.0.0/0 [110/11] via 192.168.45.4, 00:00:52, Ethernet0/0
	5.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 5.5.5.0/24 is directly connected, Loopback0
L 5.5.5.5/32 is directly connected, Loopback0
	6.0.0.0/32 is subnetted, 1 subnets
O 6.6.6.6 [110/21] via 192.168.45.4, 00:00:52, Ethernet0/0
	100.0.0.0/24 is subnetted, 1 subnets
O N2 100.100.100.0 [110/20] via 192.168.45.4, 00:00:52, Ethernet0/0
	192.168.45.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.45.0/24 is directly connected, Ethernet0/0
L 192.168.45.5/32 is directly connected, Ethernet0/0
O 192.168.46.0/24 [110/20] via 192.168.45.4, 00:00:52, Ethernet0/0
会在nssa配置基础上,实现一条默认路由,用来实现不学习其他区域的路由
  • 32
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值