设为首页收藏本站language 语言切换
查看: 2574|回复: 12
收起左侧

[分享] 5个超经典实验,老杨带你高效进阶OSPF

[复制链接]
发表于 2021-11-10 16:25:51 | 显示全部楼层 |阅读模式
本帖最后由 网络工程师-老杨 于 2021-11-10 16:30 编辑

我是老杨,今天咱们来继续讲讲OSPF。


OSPF是一种基于链路状态的路由协议,也是专为 IP 开发的路由协议,直接运行在 IP 层上面。它从设计上保证了无路由环路。除此之外,IS-IS也是很常见的链路状态协议。

1.jpg


OSPF路由协议的应用面非常广,认可度也很高,毕竟的确是好用的。所以,在网络部署IGP协议的时候,很多网工都会优先考虑用OSPF组网。


之前写过不少文章都是关于它,但今天想讲讲实操,让你更好理解。配合五个实验,手把手带你系统理解OSPF的各方面配置。

2.jpg

5个实验的实操内容回复本帖查看哈
游客,如果您要查看本帖隐藏内容请回复


01
点到点型网络配置
单区域ospf和MD5认证

3.jpg

file:///C:\Users\86152\AppData\Local\Temp\ksohtml\wpsD2E8.tmp.jpg

R1配置:

R1#conf t
R1(config)#hostname R1
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1255.255.255.0
R1(config-if)#ex
R1(config)#int s1/0
R1(config-if)#ip add 192.168.12.1255.255.255.0
R1(config-if)#clock rate 64000 //串口连接配置时钟频率64000
R1(config-if)#ip ospf authenticationmessage-digest//激活接口下的OSPF认证,
R1(config-if)#ip ospfmessage-digest-key 1 md5 kkfloat//设置MD5认证的密码为kkfloat
R1(config-if)#no sh
R1(config-if)#ex                                                
R1(config)#router ospf 1
R1(config-router)#network192.168.12.0 255.255.255.0 area 1
R1(config-router)#network 1.1.1.0255.255.255.0 area 1
R1(config-router)#area 1authentication message-digest//开启区域0认证,所有处于区域0的接口都需要配置同样的认证
R1(config-router)#ex


R2配置:

R2#conf t
R2(config)#int lo0
R2(config-if)#ip add 2.2.2.2255.255.255.0
R2(config-if)#ex
R2(config)#int s1/0
R2(config-if)#ip add 192.168.12.2255.255.255.0
R2(config-if)#clock rate 64000
R2(config-if)#ip ospf authenticationmessage-digest
R2(config-if)#ip ospfmessage-digest-key 1 md5 kkfloat
R2(config-if)#ex
R2(config)#int s1/1
R2(config-if)#ip add 192.168.23.2255.255.255.0
R2(config-if)#clock rate 64000
R2(config-if)#ip ospf authenticationmessage-digest
R2(config-if)#ip ospfmessage-digest-key 1 md5 kkfloat
R2(config-if)#ex
R2(config)#router ospf 1
R2(config-router)#net 2.2.2.0255.255.255.0 area 1
R2(config-router)#net 192.168.12.0255.255.255.0 area 1
R2(config-router)#network192.168.23.0 255.255.255.0 area 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#area 1authentication message-digest


R3配置:

R3#conf t
Enter configuration commands, oneper line. End with CNTL/Z.
R3(config)#int lo0
R3(config-if)#ip add 3.3.3.3255.255.255.0
R3(config-if)#no sh
R3(config-if)#ex
R3(config)#int s1/0
R3(config-if)#ip add 192.168.23.1255.255.255.0
R3(config-if)#clo
R3(config-if)#clock R
R3(config-if)#clock Rate 64000
R3(config-if)#ip ospf authenticationmessage-digest
R3(config-if)#ip ospfmessage-digest-key 1 md5 kkfloat
R3(config-if)#ex
R3(config)#router ospf 1
R3(config-router)#net 3.3.3.0255.255.255.0 area 1
R3(config-router)#net 192.168.23.0255.255.255.0 area 1
R3(config-router)#roouter-id 3.3.3.3
R3(config-router)#area 1authentication message-digest



检查各个路由器ospf学习到的路由信息,ospf的邻居信息,ospf的数据库。测试全网互通性。

Show ip route ospf
Show ip ospf nei
Show ip ospf database
debug ip ospfevents


总结该模式的特点:


通过点到点子接口的部分全互连逻辑拓扑或星型拓扑


不需要手工配置邻居


不选举DR/BDR


各个子接口属于不同的子网



02
广播型网络配置单区域OSPF

4.jpg

file:///C:\Users\86152\AppData\Local\Temp\ksohtml\wpsD329.tmp.jpg

R4配置:

R4#conf t
R4(config)#int lo0
R4(config-if)#ip add
R4(config-if)#ip add4.4.4.4 255.255.255.0
R4(config-if)#int e0/0
R4(config-if)#ip add192.168.1.4 255.255.255.0
R4(config-if)#no sh
R4(config-if)#ex
R4(config)#router ospf 1
R4(config-router)#network4.4.4.0 255.255.255.0 a 1
R4(config-router)#network192.168.1.0 255.255.255.0 a 1
R4(config-router)#router-id4.4.4.4


R5配置:

R5#conf t
R5(config)#int lo0
R5(config-if)#ip add5.5.5.5 255.255.255.0
R5(config-if)#ex
R5(config)#int e0/0
R5(config-if)#ip add192.168.1.5 255.255.255.0
R5(config-if)#no sh
R5(config-if)#ex
R5(config)#router ospf 1
R5(config-router)#net5.5.5.0 255.255.255.0 area 1
R5(config-router)#net192.168.1.0 255.255.255.0 a 1
R5(config-router)#router-id5.5.5.5
R5(config-router)#


R6配置:

R6#conf t
R6(config)#int lo0
R6(config-if)#ip add6.6.6.6 255.255.255.0
R6(config-if)#ex
R6(config)#int e0/0
R6(config-if)#ip add192.168.1.6 255.255.255.0
R6(config-if)#no sh
R6(config-if)#ex
R6(config)#router os
R6(config)#router ospf 1
R6(config-router)#net6.6.6.0 255.255.255.0 a 1
R6(config-router)#net192.168.1.0 255.255.255.0 a 1
R6(config-router)#router-id6.6.6.6


R7配置:

R7#conf t
R7(config)#int lo0
R7(config-if)#ip add
R7(config-if)#ip add7.7.7.7 255.255.255.0
R7(config-if)#ex
R7(config)#int e0/0
R7(config-if)#ip add192.168.1.7 255.255.255.0
R7(config-if)#no sh
R7(config-if)#ex
R7(config)#router ospf 1
R7(config-router)#net7.7.7.0 255.255.255.0 a
R7(config-router)#net7.7.7.0 255.255.255.0 area 1
R7(config-router)#net192.168.1.0 255.255.255.0 a 1


在这个时间间隔内,路由器相互监听hello包中的dr和bdr字段,并且服从优先级原则,这个时间间隔与dead interval时间相同都是40S。


因为刚开机时是一台路由器接下一台这样配置的,所以最先启动的路由器就认为自己是DR了。


而且OSPF没有DR,BDR的抢占机制,也就是说我们配置完成后,必须重启所有路由器或者重启所有路由器的ospf路由器协议


Show ip route ospf
Show ip ospf nei
Show ip ospf database
debug ip ospf events


此时我们还可以通过更改端口优先级,来更改谁是DR和BDR,甚至不参与DR与BDR选举。



03
NBMA配置单区域OSPF

5.jpg


file:///C:\Users\86152\AppData\Local\Temp\ksohtml\wpsD349.tmp.jpg

实验以帧中继网络中的NBMA(非广播多路访问网络)为例,NBMA用于精确模型X.25和帧中继环境,这些模型不具备内部广播和多点传送能力。


帧中继是一种高性能的WAN协议,它运行在OSI参考模型的物理层和数据链路层。它是一种数据包交换技术,是X.25的简化版本。


它省略了X.25的一些强健功能,如提供窗口技术和数据重发技术,而是依靠高层协议提供纠错功能。


这是因为帧中继工作在更好的WAN设备上,这些设备较之X.25的WAN设备具有更可靠的连接服务和更高的可靠性,它严格地对应于OSI参考模型的最低二层,而X.25还提供第三层的服务。


所以,帧中继比X.25具有更高的性能和更有效的传输效率。


在此注意,OSPF运行在物理接口上,默认的运行模式即NBMA模式,因此不需要明确使用Ip OSPF network non-broadcast。


FR配置:

FR#conf t
FR(config)#frame-relayswitching//开启帧中继交换功能
FR(config)#int s0/1
FR(config-if)#encapsulationframe-relay ietf//配置接口帧中继封装模式
FR(config-if)#frame-relaylmi-type ansi//配置LMI类型
FR(config-if)#frame intf-typedce //帧中继接口缺省接口类型为 DTE ,DCE类型只有在设备用作帧中继交换或者模拟帧中继局方设备时才使用的
FR(config-if)#clock rate64000 //设置时钟频率,串口同步时间
FR(config-if)#frame-relayroute 102 interface s0/2 201//配置本地端口DLIC值及虚链路对应出口和对端DLIC
FR(config-if)#frame-relayroute 103 interface s0/3 301
FR(config-if)#no sh
FR(config-if)#exit
FR(config)#int s0/2
FR(config-if)#encapsulationframe-relay ietf
FR(config-if)#frame-relaylmi-type ansi
FR(config-if)#frameintf-type dce
FR(config-if)#clock rate64000
FR(config-if)#frame-relayroute 201 int s0/1 102
FR(config-if)#frame-relayroute 203 int s0/3 302
FR(config-if)#no sh
FR(config-if)#exit
FR(config)#int s0/3
FR(config-if)#encapsulationframe-relay ietf
FR(config-if)#frame-relaylmi-type ansi
FR(config-if)#frameintf-type dce
FR(config-if)#clock rate64000
FR(config-if)#frame-relayroute 301 int s0/1 103
FR(config-if)#frame-relayroute 302 int s0/2 203
FR(config-if)#no sh
FR(config-if)#exit


配置R1:

R1#conf t
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1255.255.255.0
R1(co2nfig-if)#int s0/1
R1(config-if)#encapsulationframe-relay itef
R1(config-if)#frame-relaylmi-type ansi
R1(config-if)#ip add192.168.0.1 255.255.255.0
R1(config-if)#no frame-relayinverse-arp //关闭动态反向ARP映射
R1(config-if)#frame-relaymap ip 192.168.0.2 102 //手动添加对端IP与本地DLIC映射
R1(config-if)#frame-relaymap ip 192.168.0.3 103
R1(config-if)#no sh
R1(config-if)#exit


配置R2:

R2#conf t
R2(config)#int lo0
R2(config-if)#ip add 2.2.2.2255.255.255.0
R2(config-if)#int s0/2
R2(config-if)#encapsulationframe-relay itef //设置帧中继封装类型
R2(config-if)#frame-relaylmi-type ansi //设置帧中继LMI类型
R2(config-if)#ip add192.168.0.2 255.255.255.0
R2(config-if)#no frame-relayinverse-arp//关闭动态反向ARP映射
R2(config-if)#frame-relaymap ip 192.168.0.1 201//手动添加对端IP与本地DLIC映射
R2(config-if)#frame-relaymap ip 192.168.0.3 203
R2(config-if)#no sh
R2(config-if)#exit


R3配置:

R3#conf t
R3(config)#int lo0
R3(config-if)#ip add 3.3.3.3255.255.255.0
R3(config-if)#int s0/3
R3(config-if)#encapsulationframe-relay itef //设置帧中继封装类型
R3(config-if)#frame-relaylmi-type ansi //设置帧中继LMI类型
R3(config-if)#ip add192.168.0.3 255.255.255.0
R3(config-if)#no frame-relayinverse-arp//关闭动态反向ARP映射
R3(config-if)#frame-relaymap ip 192.168.0.1 301//手动添加对端IP与本地DLIC映射
R3(config-if)#frame-relaymap ip 192.168.0.2 302
R3(config-if)#no sh
R3(config-if)#exit


查看各个路由器帧中继网络的映射,此时各个路由外部接口应该是互通的。但是却不能ping通内部的地址。


此时,我们使用平时的方法配置opsf动态路由协议,看看情况如何:


R1(config)#router ospf 1
R1(config-router)#net1.1.1.0 255.255.255.0 area 1
R1(config-router)#router-id1.1.1.1
R1(config-router)#net192.168.0.0 255.255.255.0 area 1

R2(config)#router ospf 1
R2(config-router)#net2.2.2.0 255.255.255.0 a 1
R2(config-router)#net192.168.0.0 255.255.255.0 a 1
R2(config-router)#router-id2.2.2.2

R3(config)#router ospf 1
R3(config-router)#net3.3.3.0 255.255.255.0 a 1
R3(config-router)#net192.168.0.0 255.255.255.0 a 1
R3(config-router)#router-id3.3.3.3

完成配置后查看R1、R2、R3的路由表你会发现根本没有OSPF学习到的路由也没有邻居


sh ip route ospf
sh ip ospf neighbor
debug ip ospf events


原因是由于NBMA网络中允许存在多台Router,物理上链路共享,通过二层虚链路(VC)建立逻辑上的连接,此时网络不是没有广播的能力,而是广播针对每一条VC发送,这样就使得一台路由器在不是Full-Mesh的NBMA拓扑中,发送的广播或组播分组可能无法到达其他所有路由器,而OSPF路由协议是依靠组播去发现邻居和传送LSA包的。


所以,OSPF正常就要手动指定邻居:


R1(config)#router ospf 1
R1(config-router)#nei 192.168.0.2
R1(config-router)#nei 192.168.0.3
R1(config-router)#exit
R1(config)#exit
R1#clear ip ospf process

R2(config)#router ospf 1
R2(config-router)#nei 192.168.0.1
R2(config-router)#nei 192.168.0.3
R2(config-router)#exit
R2(config)#exit
R2#clear ip ospf process

R3(config)#router ospf 1
R3(config-router)#nei 192.168.0.1
R3(config-router)#nei 192.168.0.2
R3(config-router)#exit
R3(config)#exit
R3#clear ip ospf process


此时我们再查看R1,R2,R3路由表,和ospf邻居关系表和数据库,就正常了


sh ip route ospf
sh ip ospf neighbor
sh ip ospf database
debug ip ospf events


如此同时我们也发现,此NBMA网络选举了R3作为DR,R2作为BDR,R1作为DROTHER.路由器间使用单播地址而不是使用组播建立邻居关系和交换路由信息。



此模式不推荐使用,一是配置复杂,而是需要选择DR,邻居建立慢。



各R之间使用PVC建立完全互连的逻辑拓扑。



邻居属于同一子网。



手工配置邻居



R之间选举DR/BDR



LSA和LSAck分别被发送到各个邻居路由器。

6.jpg


file:///C:\Users\86152\AppData\Local\Temp\ksohtml\wpsD369.tmp.jpg 老杨,一个从事网工行业8年的中年吃货,和你每天聊几句关于网工的那些事儿。

加我 领取更多的学习资料的副本.png

发表于 2021-11-11 08:28:10 | 显示全部楼层
5个超经典实验,老杨带你高效进阶OSPF
板凳 2021-11-11 08:28:10 回复 收起回复
回复 支持 反对

使用道具 举报

发表于 2021-11-11 12:57:09 | 显示全部楼层
好东西谢谢楼主分享
5# 2021-11-11 12:57:09 回复 收起回复
回复 支持 反对

使用道具 举报

发表于 2021-11-12 22:43:21 | 显示全部楼层
謝謝樓主分享
8# 2021-11-12 22:43:21 回复 收起回复
回复 支持 反对

使用道具 举报

发表于 2022-5-8 10:59:58 | 显示全部楼层
下下来看看。
11# 2022-5-8 10:59:58 回复 收起回复
回复 支持 反对

使用道具 举报

发表于 2022-5-23 09:50:34 | 显示全部楼层

谢谢您的分享  很不错的资源
12# 2022-5-23 09:50:34 回复 收起回复
回复 支持 反对

使用道具 举报

发表于 2022-6-23 13:41:00 | 显示全部楼层

5个超经典实验,老杨带你高效进阶OSPF
13# 2022-6-23 13:41:00 回复 收起回复
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 论坛注册

本版积分规则

QQ|Archiver|手机版|小黑屋|sitemap|鸿鹄论坛 ( 京ICP备14027439号 )  

GMT+8, 2025-4-26 10:30 , Processed in 0.134067 second(s), 27 queries , Redis On.  

  Powered by Discuz!

  © 2001-2025 HH010.COM

快速回复 返回顶部 返回列表