OSPF协议

1、OSPF理论知识

1.1、常规

ospf:开放最短距离优先 管理距离:110

封装IP头部协议字段:88eigrp 89ospf

组播地址:224.0.0.5 224.0.0.6

三个表:邻居表、数据库、路由表

主干路由器:BR 区域边界路由器:ABR 自治系统边界路由器:ASBR

指定路由:DR 备份指定路由:BDR

1.2、原理:

通过hello数据包建立邻居表。用lsa链路状态创建链路状态数据库,使用SPF 算法计算到目的地的最优路径加入到路由表中

1.3、划分区域的好处:

1、减少路由表的路由条目
2、拓朴发生改变时,只影响本区域的数据库
3、每隔30分钟泛数据库信息(周期和触发更新),划分区域后,只在本区域泛洪
4、网络设计灵活

1.4、邻接七种状态

down、init、2way、exstart、exchange、loading、full

​ down :路由器A刚启动时,ospf处于down的状态,因为它还没有与其他路由器交换信息。它使用组播地址224.0.0.5发送hello分组。

​ init:所有运行ospf的路由器收到A的hello分组时,将A加入邻居列表中,这是init状态。

​ 2way :收到A的hello的路由器都向A发送单播应答,A收到后,将这些路由器加入邻居列表,所有路由器都建立了双向关系,进入了2way状态。

​ Exstart :如果链路类型是广播网络(如以太网),接下来必须选举DR和BDR,选举结束后,路由器处于预启动Exstart状态。

​ Exchange :然后交换链路状态数据库摘要,也就是交换DBD,这是Exchange状态。

​ Loading :DBD交换完毕后进入Loading状态

​ Full :路由器根据DBD发送LSR请求更新链路状态条目,对方用LSU进行响应。至此,双方都学到了路由条目,database完整,就是Full状态。

1.5、最短路径优先算法(SPF Calculation)

Cost=108/BW(b/s)
metric值=所有目的地址到达本地路由器的入接口的cost值之和

metric值=所有本地路由器到达目的地址的路由器的出接口的cost值之和

修改接口的cost值:
Router(config)#int f0/0
Router(config-if)#ip ospf cost 1

或Router(config-if)#bandwidth 100

1.6、 DR/BDR选取

DR:指定路由 BDR:备份指定路由

(1)DR与BDR有自己的组播地址:224.0.0.6

(2)DR与BDR选取原则

​ 首要因素是时间

​ 其次是接口优先级(多路访问网络的接口优先级为1,点到点网络接口优先级为0。

​ ip ospf priority 可以修改接口优先级,若为0则不参与DR选举

​ 再次是路由器ID:先比环回接口,再比物理接口

(3)DR与BDR选取是非抢占的,以下情况会重选

​ 重启ospf进程或路由器;参与的路由器都执行clear ip ospf process命令;DR故障;

OSPF接口优先级为0。

(4)如果DR故障,BDR接管DR,如果BDR故障,选新的BDR

1.7、明文和MD5身份验证

(1)配置明文认证

R1(config-if)#ip ospf authentication-key ccie 设置明文密码,两端口密码要一致

R1(config-if)#ip ospf authentication 开启接口认证

R1(config)#router ospf 1

R1(config-router)#area 1 authentication 开户区域认证

(2)配置MD5认证

​ R1(config-if)#ip ospf message-digest-key 1 md5 ccie

​ R1(config-if)#ip ospf authentication 接口md5

​ R1(config-if)#ip ospf message-digest-key 1 md5 ccie

​ R1(config-router)#area 1 authentication message-digest 区域MD5

2、操作

实验一

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wJeaXPgR-1581760528131)(C:\Users\asus\AppData\Roaming\Typora\typora-user-images\1576249410474.png)]

区域1要求用OSPF明文验证

OSPF协议

R1(config)#int f0/0
R1(config-if)#ip ospf authentication-key 123456
R1(config-if)#ip ospf authentication

R2(config)#int f0/0
R2(config-if)#ip ospf authentication-key 123456
R2(config-if)#ip ospf authentication

R3(config)#int f0/0
R3(config-if)#ip ospf authentication-key 123456
R3(config-if)#ip ospf authentication

区域0要求用可靠的验证方式

R4(config)#int f0/1
R4(config-if)#ip ospf message-digest-key 1 md5 123456
R4(config)#router ospf 1
R4(config-router)#area 0 authentication message-digest

R4(config)#int s1/0
R4(config-if)#ip ospf message-digest-key 1 md5 123456
R4(config)#router ospf 1
R4(config-router)#area 0 authentication message-digest

R3(config)#int f0/1
R3(config-if)#ip ospf message-digest-key 1 md5 123456
R3(config)#router ospf 1
R3(config-router)#area 0 authentication message-digest

R2(config)#int s1/0
R2(config-if)#ip ospf message-digest-key 1 md5 123456
R2(config)#router ospf 1
R2(config-router)#area 0 authentication message-digest

要求R4去往R1的环回从R2走

R4(config)#int s1/0
R4(config-if)#ip ospf cost 2

cost小于R3

R1上看到去往R4的两条等价负载均衡

R2(config)#int s1/0
R2(config-if)#ip ospf cost 10

COST相等

实验二

OSPF协议

区域间路由汇总

R2(config-router)#area 1 range 172.16.0.0 255.255.252.0

eigrp重分ospf

R3(config)#router ospf 1
R3(config-router)#redistribute eigrp 1 subnets

默认为 metric-type 2 OE2,Metric为20,不累加 metric-type 1 OE1
R3(config-router)#redistribute eigrp 1 metric-type 1 metric 100 subnets

ospf重分eigrp

R3(config)#router eigrp 1
R3(config-router)#redistribute ospf 1 metric 1000 100 255 1 1500

实验三

OSPF协议

直连和静态重分RIP

R1(config)#router rip

R1(config-router)#redistribute static metric 3

R1(config-router)#redistribute connected metric 3

eigrp重分rip

R2(config)#router rip

R2(config-router)#redistribute eigrp 1 metric 4

rip重分eigrp

R2(config)#router eigrp 1

R2(config-router)#redistribute rip metric 1000 100 255 1 1500

eigrp 重分ospf

R3(config)#router ospf 1

R3(config-router)#redistribute eigrp 1 metric-type 2 subnets

ospf 重分eigrp

R3(config)#router eigrp 1

R3(config-router)#redistribute ospf 1 metric 10000 100 1 1 1500

R3(config-router)#distance eigrp 90 150

直连重分ospf

R4(config)#router ospf 1

R4(config-router)#redistribute connected subnets