一.ospf原理:

概述

        ospf又称为开放最短路径优先协议,属于链路状态路由协议。这种路由协议用途广泛,通常用在大型园区企业网络中。

特点

        ospf有以下几个特点 :1.通常采用了触发更新,对带宽占用小,只有网络变化才通知。2.更新路由条目时,发布的是链路状态时对周边网络的描述。3.通过组播发送信息。4.meric值又称为cost,也就是说通过带宽去选择最佳路径,计算metric值是基于带宽得出来的。5.关于网络规模,ospf理论上是没有规模的限制,但实际中它的最大规模是1000台。6.在负载均衡方面,ospf是等代价的。7.收敛速度快。8.不会形成环路径9.ospf通常有三张表格,分别是邻居表、链路状态数据库、通过spf算出的路由表。10.支持可变成子网掩码。等等
二.案例
  ospf多区域配置
实验要求:
1.        rip网络重发布到 ospf,ospf以默认路由重发布到rip
2.        在 ospf1设置末节区域,路由表只有区域间路由和域内路由
3.        在 ospf1设置完全末节区域,路由表显示域内路由和默认
4.        实现全网互通
实验设备要求:六台路由器  线若干  
实验拓扑图:
 
以CISCO路由器为例:
下面为配置信息:
r1配置 :
 
  
  1. router>en  
  2. router#conf t  
  3. router(config)#host r1 [为路由器起别名]  
  4. r1(config)#inter lo0  
  5. r1(config-if)#ip add 192.168.1.1 255.255.255.0   
  6. r1(config-if)#inter s1/0   [进入接口配置IP地址]  
  7. r1(config-if)#ip add 192.168.2.1 255.255.255.0  
  8. r1(config-if)#no shut  
  9. r1(config-if)#router ospf 10 [配置ospf协议]  
  10. r1(config-router)#net 192.168.1.0 0.0.0.255 a 1 [ospf的网段写法,首先写出该网段的IP 地址,然后跟上该网段的反掩码,最后跟上该网段所属的area x区域]  
  11. r1(config-router)#net 192.168.2.0 0.0.0.255 a 1  
  12. [r1路由配置完毕]  
r2配置:
 
  
  1. r2(config)#inter s1/0  
  2. r2(config-if)#ip add 192.168.2.2 255.255.255.0  
  3. r2(config-if)#no shut  
  4. r2(config)#inter s1/1                        
  5. r2(config-if)#ip add 192.168.3.1 255.255.255.0  
  6. r2(config-if)#no shut  
  7. r2(config-if)#inter s1/2  
  8. r2(config-if)#ip add 192.168.6.1 255.255.255.0  
  9. r2(config-if)#no shut  
  10. r2(config-if)#exit  
  11. r2(config)#router ospf 10  
  12. r2(config-router)#net 192.168.2.0 0.0.0.255 a 1  
  13. r2(config-router)#net 192.168.3.0 0.0.0.255 a 0  
  14. r2(config-router)#exit  
  15. r2(config)#router rip [配置rip]  
  16. r2(config-router)#net 192.168.6.0  
  17. r2(config)#router ospf 10   [对rip协议进行重分发,在ospf 区域中学习到各个区域中的详细路由表]  
  18. r2(config-router)#redistribute rip metric 100 subnets  
  19. r2(config-router)#router rip [rip区域中学习到默认路由]  
  20. r2(config-router)#default-information originate  
r3配置 :
 
  
  1. router(config)#host r3  
  2. r3(config)#inter s1/1  
  3. r3(config-if)#ip add 192.168.3.2 255.255.255.0  
  4. r3(config-if)#no shut  
  5. r3(config-if)#inter s1/0  
  6. r3(config-if)#ip add 192.168.4.1 255.255.255.0  
  7. r3(config-if)#no shut                           
  8. r3(config-if)#exit  
  9. r3(config)#router ospf 10  
  10. r3(config-router)#net 192.168.3.0 0.0.0.255 a 0  
  11. r3(config-router)#net 192.168.4.0 0.0.0.255 a 2  
  12. r3(config)#router ospf 10  
  13. r3(config-router)#area 2 stub [末节区域需要在该区域的所有路由器上都声明 area x stub]  
  14.    
  15. r3(config-router)#area 2 stub no-summary [配置完全末节]  
r4配置 :
 
  
  1. router(config)#inter s1/0  
  2. router(config-if)#ip add 192.168.4.2 255.255.255.0  
  3. router(config-if)#no shut  
  4. router(config-if)#inter lo0  
  5. router(config-if)#ip add 192.168.5.1 255.255.255.0  
  6. router(config-if)#exit  
  7. router(config)#router ospf 10  
  8. router(config-router)#net 192.168.4.0 0.0.0.255 a 2  
  9. router(config-router)#net 192.168.5.0 0.0.0.255 a 2  
  10. router(config-router)#router ospf 10  
  11. router(config-router)#area 2 stub【设置末节区域】  
r5配置 :
 
  
  1. router(config)#inter s1/2  
  2. router(config-if)#ip add 192.168.6.2 255.255.255.0  
  3. router(config-if)#no shut  
  4. router(config-if)#inter s1/0  
  5. router(config-if)#ip add 192.168.7.1 255.255.255.0  
  6. router(config-if)#no shut  
  7. router(config-if)#exit  
  8. router(config)#router rip [RIP的路由协议配置]  
  9. router(config-router)#net 192.168.6.0 [跟上直连的网段]  
  10. router(config-router)#net 192.168.7.0  
r6配置 :
 
  
  1. router(config)#inter s1/0  
  2. router(config-if)#ip add 192.168.7.2 255.255.255.0  
  3. router(config-if)#no shut  
  4. router(config-if)#inter lo0  
  5. router(config-if)#ip add 192.168.8.1 255.255.255.0  
  6. router(config-if)#exit  
  7. router(config)#router rip  
  8. router(config-router)#net 192.168.7.0  
  9. router(config-router)#net 192.168.8.0  
实验结果:
r3和 r4配置末节区域前R4路由表:
r3和 r4配置末节区域后R4路由表:
结论:学习除了本区域,外部区域的路由均为静态默认路由。
r3上配置完全末节区域后 r4路由表:
结论: r4为完全末节区域,学习到的路由表只有自己本区域和一条直连路由。