当前位置:   article > 正文

OSPF(开放式最短路径优先协议)简介_ospf协议

ospf协议

目录

一.OSPF协议原理简介

二.OSPF协议特点

三.OSPF区域

1.OSPF区域划分作用

2.OSPF 区域划分方式:基于接口(链路)划分区域

3.OSPF 区域标识: 最终归结为32个二进制

4.区域分类: 便于区域设计

5.OSPF 路由器角色:

四.OSPF简单配置

1.路由配置

2.缺省路由配置


一.OSPF协议原理简介

路由器向邻居发送报文,报文中包含自己所知道的路由信息,与邻居形成邻居表,后路由器之间发送链路状态通告告知邻居自己的链路连接状态,形成LSDB拓扑表,后形成路由表。

二.OSPF协议特点

1.协议范围是IGP内部网关协议,协议算法采用链路状态型路由协议,传递网络掩码(无类别的路由协议) ,基于IP协议封装,IP层协议号为89。

2.OSPF是一种链路状态型协议(既传递路由信息也传递拓扑信息),传递的是 LSA (链路状态通告 共6种类型LSA1 2 3 4 5 7) 。

3.OSPF 更新方式: 触发更新 + 30分钟的周期链路状态刷新 。触发更新—网络结构稳定的时候不发数据,网络结构产生变化(网段数量或信息变化,接口状态变化等)时发数据,OSPF 更新地址: 224.0.0.5/6

4.OSPF 支持区域划分,比较消耗路由器资源。

5.开销值计算方式为100Mbps(参照带宽)/真实带宽,若产生小数点直接舍弃

三.OSPF区域

1.OSPF区域划分作用

限制LSA的传播范围

减少LSA的数量

2.OSPF 区域划分方式:基于接口(链路)划分区域

503ace60685b48c98430be6f4af46bc8.png

3.OSPF 区域标识: 最终归结为32个二进制

十进制数或者类似于IP地址形式

4.区域分类: 便于区域设计

骨干区域(0区域)

非骨干区域 (非0区域)

区域设计原则:

OSPF网络中必须存在并且唯一的骨干区域(单区域可以不为骨干区域 )

有非骨干区域时,非骨干区域必须与骨干区域直接相连

0ccc9d8cb48a4623ba03518679a4d419.png

5.OSPF 路由器角色:

骨干路由器:路由器所有接口都属于骨干区域

非骨干路由器:路由器接口都不属于骨干区域

ABR:区域边界路由器,骨干区域和非骨干区域的接界

ASBR:自治系统边界路由器,位于使用不同协议的路由器边界上,将路由引入为对方能够学习成功的路由

四.OSPF简单配置

77fee0bdf67a4d31b0b5889978d957a7.png

  1. [r1]display ip interface brief
  2. Interface IP Address/Mask Physical Protocol
  3. GigabitEthernet0/0/0 10.1.1.1/24 up up
  4. LoopBack0 1.1.1.1/24 up up(s)
  5. [r2]display ip interface brief
  6. Interface IP Address/Mask Physical Protocol
  7. GigabitEthernet0/0/0 20.1.1.1/24 up up
  8. GigabitEthernet0/0/1 10.1.1.2/24 up up
  9. LoopBack0 2.2.2.2/24 up up(s)
  10. [r3]display ip interface brief
  11. Interface IP Address/Mask Physical Protocol
  12. GigabitEthernet0/0/1 20.1.1.2/24 up up
  13. LoopBack0 3.3.3.3/24 up up(s)

1.路由配置

(1)启用ospf指定进程号(和rip协议相同,进程号只具有本地意义),指定router id(路由标识符),必须书写,代表着该设备在ospf网络中的唯一性,有两种方式——手工指定,这是最简易的也是最优先的;自动选取环回接口/物理接口最大的作为标识

  1. [r1]ospf 100 router-id 91.1.1.1
  2. [r2]ospf 100 router-id 92.1.1.1
  3. [r3]ospf 100 router-id 93.1.1.1

(2)进入ospf区域(以全区域为例)

  1. [r1-ospf-100]area 0
  2. [r1-ospf-100-area-0.0.0.0]
  3. [r2-ospf-100]area 0
  4. [r2-ospf-100-area-0.0.0.0]
  5. [r3-ospf-100]area 0
  6. [r3-ospf-100-area-0.0.0.0]

(3)network通告,使用反掩码,实现精确通告,连续的0和连续的1组成,0代表固定位,1代表可变位,仅告知是否可变,不告知网络/主机位

  1. [r1-ospf-100-area-0.0.0.0]network 1.1.1.1 0.0.0.0
  2. [r1-ospf-100-area-0.0.0.0]network 10.1.1.1 0.0.0.0
  3. [r2-ospf-100-area-0.0.0.0]network 2.2.2.2 0.0.0.0
  4. [r2-ospf-100-area-0.0.0.0]network 10.1.1.2 0.0.0.0
  5. [r2-ospf-100-area-0.0.0.0]network 20.1.1.1 0.0.0.0
  6. [r3-ospf-100-area-0.0.0.0]network 3.3.3.3 0.0.0.0
  7. [r3-ospf-100-area-0.0.0.0]network 20.1.1.2 0.0.0.0

(4)查表

邻居表

  1. [r1-ospf-100-area-0.0.0.0]display ospf peer brief
  2. OSPF Process 100 with Router ID 91.1.1.1
  3. Peer Statistic Information
  4. ----------------------------------------------------------------------------
  5. Area Id Interface Neighbor id State
  6. 0.0.0.0 GigabitEthernet0/0/0 92.1.1.1 Full
  7. ----------------------------------------------------------------------------
  8. [r2-ospf-100-area-0.0.0.0]display ospf peer brief
  9. OSPF Process 100 with Router ID 92.1.1.1
  10. Peer Statistic Information
  11. ----------------------------------------------------------------------------
  12. Area Id Interface Neighbor id State
  13. 0.0.0.0 GigabitEthernet0/0/1 91.1.1.1 Full
  14. 0.0.0.0 GigabitEthernet0/0/0 93.1.1.1 Full
  15. ----------------------------------------------------------------------------
  16. [r3-ospf-100-area-0.0.0.0]display ospf peer brief
  17. OSPF Process 100 with Router ID 93.1.1.1
  18. Peer Statistic Information
  19. ----------------------------------------------------------------------------
  20. Area Id Interface Neighbor id State
  21. 0.0.0.0 GigabitEthernet0/0/1 92.1.1.1 Full
  22. ----------------------------------------------------------------------------

LSDB表

  1. [r1-ospf-100-area-0.0.0.0]display ospf lsdb
  2. OSPF Process 100 with Router ID 91.1.1.1
  3. Link State Database
  4. Area: 0.0.0.0
  5. Type LinkState ID AdvRouter Age Len Sequence Metric
  6. Router 93.1.1.1 93.1.1.1 284 48 80000005 1
  7. Router 92.1.1.1 92.1.1.1 292 60 80000009 1
  8. Router 91.1.1.1 91.1.1.1 428 48 80000005 1
  9. Network 10.1.1.2 92.1.1.1 422 32 80000002 0
  10. Network 20.1.1.2 93.1.1.1 284 32 80000002 0
  11. [r2-ospf-100-area-0.0.0.0]display ospf lsdb
  12. OSPF Process 100 with Router ID 92.1.1.1
  13. Link State Database
  14. Area: 0.0.0.0
  15. Type LinkState ID AdvRouter Age Len Sequence Metric
  16. Router 93.1.1.1 93.1.1.1 302 48 80000005 1
  17. Router 92.1.1.1 92.1.1.1 310 60 80000009 1
  18. Router 91.1.1.1 91.1.1.1 448 48 80000005 1
  19. Network 10.1.1.2 92.1.1.1 440 32 80000002 0
  20. Network 20.1.1.2 93.1.1.1 302 32 80000002 0
  21. [r3-ospf-100-area-0.0.0.0]display ospf lsdb
  22. OSPF Process 100 with Router ID 93.1.1.1
  23. Link State Database
  24. Area: 0.0.0.0
  25. Type LinkState ID AdvRouter Age Len Sequence Metric
  26. Router 93.1.1.1 93.1.1.1 317 48 80000005 1
  27. Router 92.1.1.1 92.1.1.1 327 60 80000009 1
  28. Router 91.1.1.1 91.1.1.1 465 48 80000005 1
  29. Network 10.1.1.2 92.1.1.1 457 32 80000002 0
  30. Network 20.1.1.2 93.1.1.1 317 32 80000002 0

路由表

  1. [r1-ospf-100-area-0.0.0.0]display ip routing-table protocol ospf
  2. Route Flags: R - relay, D - download to fib
  3. ------------------------------------------------------------------------------
  4. Public routing table : OSPF
  5. Destinations : 3 Routes : 3
  6. OSPF routing table status : <Active>
  7. Destinations : 3 Routes : 3
  8. Destination/Mask Proto Pre Cost Flags NextHop Interface
  9. 2.2.2.2/32 OSPF 10 1 D 10.1.1.2 GigabitEthernet
  10. 0/0/0
  11. 3.3.3.3/32 OSPF 10 2 D 10.1.1.2 GigabitEthernet
  12. 0/0/0
  13. 20.1.1.0/24 OSPF 10 2 D 10.1.1.2 GigabitEthernet
  14. 0/0/0
  15. OSPF routing table status : <Inactive>
  16. Destinations : 0 Routes : 0
  17. [r2-ospf-100-area-0.0.0.0]display ip routing-table protocol ospf
  18. Route Flags: R - relay, D - download to fib
  19. ------------------------------------------------------------------------------
  20. Public routing table : OSPF
  21. Destinations : 2 Routes : 2
  22. OSPF routing table status : <Active>
  23. Destinations : 2 Routes : 2
  24. Destination/Mask Proto Pre Cost Flags NextHop Interface
  25. 1.1.1.1/32 OSPF 10 1 D 10.1.1.1 GigabitEthernet
  26. 0/0/1
  27. 3.3.3.3/32 OSPF 10 1 D 20.1.1.2 GigabitEthernet
  28. 0/0/0
  29. OSPF routing table status : <Inactive>
  30. Destinations : 0 Routes : 0
  31. [r3-ospf-100-area-0.0.0.0]display ip routing-table protocol ospf
  32. Route Flags: R - relay, D - download to fib
  33. ------------------------------------------------------------------------------
  34. Public routing table : OSPF
  35. Destinations : 3 Routes : 3
  36. OSPF routing table status : <Active>
  37. Destinations : 3 Routes : 3
  38. Destination/Mask Proto Pre Cost Flags NextHop Interface
  39. 1.1.1.1/32 OSPF 10 2 D 20.1.1.1 GigabitEthernet
  40. 0/0/1
  41. 2.2.2.2/32 OSPF 10 1 D 20.1.1.1 GigabitEthernet
  42. 0/0/1
  43. 10.1.1.0/24 OSPF 10 2 D 20.1.1.1 GigabitEthernet
  44. 0/0/1
  45. OSPF routing table status : <Inactive>
  46. Destinations : 0 Routes : 0

可以注意到表内环回接口掩码被标注为32位,表示一条主机路由,固定为一个主机,是由于OSPF测试到你是一个环回接口,默认给你识别为32位。进入环回更改network类型即可还原真实网络掩码。

  1. [r1]interface LoopBack 0
  2. [r1-LoopBack0]ospf network-type broadcast
  3. [r2]interface LoopBack 0
  4. [r2-LoopBack0]ospf network-type broadcast
  5. [r3]interface LoopBack 0
  6. [r3-LoopBack0]ospf network-type broadcast
  7. [r1]display ip routing-table protocol ospf
  8. Route Flags: R - relay, D - download to fib
  9. ------------------------------------------------------------------------------
  10. Public routing table : OSPF
  11. Destinations : 3 Routes : 3
  12. OSPF routing table status : <Active>
  13. Destinations : 3 Routes : 3
  14. Destination/Mask Proto Pre Cost Flags NextHop Interface
  15. 2.2.2.0/24 OSPF 10 1 D 10.1.1.2 GigabitEthernet
  16. 0/0/0
  17. 3.3.3.0/24 OSPF 10 2 D 10.1.1.2 GigabitEthernet
  18. 0/0/0
  19. 20.1.1.0/24 OSPF 10 2 D 10.1.1.2 GigabitEthernet
  20. 0/0/0
  21. OSPF routing table status : <Inactive>
  22. Destinations : 0 Routes : 0
  23. [r2]display ip routing-table protocol ospf
  24. Route Flags: R - relay, D - download to fib
  25. ------------------------------------------------------------------------------
  26. Public routing table : OSPF
  27. Destinations : 2 Routes : 2
  28. OSPF routing table status : <Active>
  29. Destinations : 2 Routes : 2
  30. Destination/Mask Proto Pre Cost Flags NextHop Interface
  31. 1.1.1.0/24 OSPF 10 1 D 10.1.1.1 GigabitEthernet
  32. 0/0/1
  33. 3.3.3.0/24 OSPF 10 1 D 20.1.1.2 GigabitEthernet
  34. 0/0/0
  35. OSPF routing table status : <Inactive>
  36. Destinations : 0 Routes : 0
  37. [r3]display ip routing-table protocol ospf
  38. Route Flags: R - relay, D - download to fib
  39. ------------------------------------------------------------------------------
  40. Public routing table : OSPF
  41. Destinations : 3 Routes : 3
  42. OSPF routing table status : <Active>
  43. Destinations : 3 Routes : 3
  44. Destination/Mask Proto Pre Cost Flags NextHop Interface
  45. 1.1.1.0/24 OSPF 10 2 D 20.1.1.1 GigabitEthernet
  46. 0/0/1
  47. 2.2.2.0/24 OSPF 10 1 D 20.1.1.1 GigabitEthernet
  48. 0/0/1
  49. 10.1.1.0/24 OSPF 10 2 D 20.1.1.1 GigabitEthernet
  50. 0/0/1
  51. OSPF routing table status : <Inactive>
  52. Destinations : 0 Routes : 0

2.缺省路由配置

在边界路由器上新建一个环回接口,此时其他路由器不能到达

(1)强制产生

进入ospf进行配置强制产生

  1. [r1]ospf 100
  2. [r1-ospf-100]default-route-advertise always
  3. [r2]display ip routing-table protocol ospf
  4. Route Flags: R - relay, D - download to fib
  5. ------------------------------------------------------------------------------
  6. Public routing table : OSPF
  7. Destinations : 3 Routes : 3
  8. OSPF routing table status : <Active>
  9. Destinations : 3 Routes : 3
  10. Destination/Mask Proto Pre Cost Flags NextHop Interface
  11. 0.0.0.0/0 O_ASE 150 1 D 10.1.1.1 GigabitEthernet
  12. 0/0/1
  13. 1.1.1.0/24 OSPF 10 1 D 10.1.1.1 GigabitEthernet
  14. 0/0/1
  15. 3.3.3.0/24 OSPF 10 1 D 20.1.1.2 GigabitEthernet
  16. 0/0/0
  17. OSPF routing table status : <Inactive>
  18. Destinations : 0 Routes : 0
  19. [r2]ping 6.6.6.6
  20. PING 6.6.6.6: 56 data bytes, press CTRL_C to break
  21. Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=255 time=20 ms
  22. Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=255 time=20 ms
  23. Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=255 time=30 ms
  24. Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=255 time=20 ms
  25. Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=255 time=20 ms
  26. --- 6.6.6.6 ping statistics ---
  27. 5 packet(s) transmitted
  28. 5 packet(s) received
  29. 0.00% packet loss
  30. round-trip min/avg/max = 20/22/30 ms
  31. [r3]ping 6.6.6.6
  32. PING 6.6.6.6: 56 data bytes, press CTRL_C to break
  33. Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=254 time=40 ms
  34. Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=254 time=20 ms
  35. Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=254 time=30 ms
  36. Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=254 time=20 ms
  37. Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=254 time=20 ms
  38. --- 6.6.6.6 ping statistics ---
  39. 5 packet(s) transmitted
  40. 5 packet(s) received
  41. 0.00% packet loss
  42. round-trip min/avg/max = 20/26/40 ms

(2)新建或已存在其它类型的缺省

进入ospf进行配置

  1. [r1]display ip interface brief
  2. Interface IP Address/Mask Physical Protocol
  3. GigabitEthernet0/0/0 10.1.1.1/24 up up
  4. GigabitEthernet0/0/1 unassigned down down
  5. GigabitEthernet0/0/2 unassigned down down
  6. LoopBack0 1.1.1.1/24 up up(s)
  7. LoopBack1 6.6.6.6/24 up up(s)
  8. NULL0 unassigned up up(s)
  9. [r1]ospf 100
  10. [r1-ospf-100]default-route-advertise
  11. [r1]ip route-static 0.0.0.0 0.0.0.0 LoopBack 1
  12. [r1]display ip routing-table protocol static
  13. Route Flags: R - relay, D - download to fib
  14. ------------------------------------------------------------------------------
  15. Public routing table : Static
  16. Destinations : 1 Routes : 1 Configured Routes : 1
  17. Static routing table status : <Active>
  18. Destinations : 1 Routes : 1
  19. Destination/Mask Proto Pre Cost Flags NextHop Interface
  20. 0.0.0.0/0 Static 60 0 D 6.6.6.6 LoopBack1
  21. Static routing table status : <Inactive>
  22. Destinations : 0 Routes : 0
  23. [r2]ping 6.6.6.6
  24. PING 6.6.6.6: 56 data bytes, press CTRL_C to break
  25. Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=255 time=30 ms
  26. Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=255 time=20 ms
  27. Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=255 time=30 ms
  28. Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=255 time=20 ms
  29. Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=255 time=20 ms
  30. --- 6.6.6.6 ping statistics ---
  31. 5 packet(s) transmitted
  32. 5 packet(s) received
  33. 0.00% packet loss
  34. round-trip min/avg/max = 20/24/30 ms
  35. [r3]ping 6.6.6.6
  36. PING 6.6.6.6: 56 data bytes, press CTRL_C to break
  37. Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=254 time=40 ms
  38. Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=254 time=30 ms
  39. Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=254 time=30 ms
  40. Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=254 time=20 ms
  41. Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=254 time=30 ms
  42. --- 6.6.6.6 ping statistics ---
  43. 5 packet(s) transmitted
  44. 5 packet(s) received
  45. 0.00% packet loss
  46. round-trip min/avg/max = 20/30/40 ms

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/755337
推荐阅读
相关标签
  

闽ICP备14008679号