一. OSPF的原理
OSPF(Open Shortest Path First)是开放式最短路径优先协议,其管理距离是110。OSPF是一种链路状态协议,ospf是一类内部网关协议(IGP),用于属于单个自治体系的路由之间的路由选择。Ospf采用链路状态技术,路由器互相发送直连的链路信息和他所拥有到其他路由器的链路信息。在一个ospf网络中每个路由器通过hello报文学习到邻居路由器,每个路由器维护相同的自治与系统拓扑数据库,通过SPF算法算出最短路径得到路由表,当网络拓扑结构发生变化时,ospf能够迅速计算最短路径,得出新的路由路由表。
二. OSPF的特点
1、OSPF 采用触发更新,每30分钟更新一次
2、采用组播地址发送报文(224.0.0.5和224.0.0.6)
3、OSPF协议没有路由还
4、OSPF协议收敛速度快
5、Ospf协议支持路由验证
6、Ospf对路由协议支持负载均衡
7、适用于较大型的网络拓扑结构
8、Ospf协议有三张表格分别是邻居表格、链路状态数据库(LSDB)和根据SPF算法的出的路由表,交换信息数据时占用资源较大
三. OSPF与RIP,IGRP,EIGRP的区别
1、OSPF适用于大型网络,RIP是距离矢量路由协议
,支持最大跳数是16
2、IGRP是内部网关路由协议,EIGRP是增强的内部网关协议(仅cisco支持)
3、RIP和IGRP采用周期更新,OSPF和EIGRP采用触发更新
4、RIP和IGRP采用广播地址发送报文,OSPF和EIGRP采用组播,OSPF采用的组播地址是224.0.0.5和224.0.0.6。EIGRP的组播地址是224.0.0.10
5、RIP和IGRP的收敛速度慢,OSPF和EIGRP收敛速度快,EIGRP速度最快
6、RIP、IGRP和EIGRP支持等代价和非等代价的负载均衡,OSPF只支持等代价的负载均衡
7、RIP的metric值由跳数决定,OSPF的metric值由COST决定,IGRP和EIGRP的metric值由带宽、延迟、可靠度、负载、MTU决定
8、RIP版本1不支持子网不连续和可变子网掩码,EIGRP和OSPF协议支持
四. 案例
实验要求:
1、网络中有三种协议,分别是OSPF协议网络、RIP协议网络、RIGRP协议的网络,rip网络较小,OSPF和IGRP网络较大
2、考虑到不同网络的接收数据的能力,现将较大的OSPF网络以默认路由重发不到RIP网络,而RIP重发布到OSPF网络
3、OSPF有区域 0 ,1 ,2 ,3 存在不连续区域,运用虚拟链路实现多区域的OSPF通信
4、为优化网络,提高通信性能,将OSPF区域1,3分别实现末节区域和完全末节区域,缩减路由条目
5、实现全网互通
实验设备
1、cisco路由器R3640 九台
2、连接广域网的V.35线缆若干和局域网双绞线若干
拓扑图
路由器主要配置
R1
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
//接口配置 loopback
loopback
interface Serial1/0
ip address 192.168.2.1 255.255.255.0
router ospf 10
//OSPF区域的进程号
area 1 stub
// 在路由器设置末节区域1
network 192.168.1.0 0.0.0.255 area 1 //配置OSPF并声明所在区域1
network 192.168.2.0 0.0.0.255 area 1
R2
interface FastEthernet0/0
ip address 192.168.7.1 255.255.255.0
interface Serial1/0
ip address 192.168.2.2 255.255.255.0
interface Serial1/1
ip address 192.168.3.1 255.255.255.0
//相关接口配置
router ospf 10
area 1 stub //在路由器上设置末节区域1
redistribute rip
//将RIP重发布到OSPF网络
network 192.168.2.0 0.0.0.255 area 1
network 192.168.3.0 0.0.0.255 area 0
// OSPF区域设置
router rip
// 配置RIP路由协议
network 192.168.7.0
default-information originate
//将默认路由发布到RIP网络
ip route 0.0.0.0 0.0.0.0 Null0
//配置静态路由
R3
interface FastEthernet0/0
ip address 192.168.10.1 255.255.255.0
interface Serial1/0
ip address 192.168.4.1 255.255.255.0
interface Serial1/1
ip address 192.168.3.2 255.255.255.0
//接口ip地址配置
router eigrp 10
//EIGRP进程号
redistribute ospf 10 metric 2 100 100 100 100
//OSPF发布到EIGRP网络
network 192.168.10.0
//配置eigrp路由协议
router ospf 10
area 2 virtual-link 192.168.5.1
//在OSPF区域2上设置虚拟链路指向BRD router id
network 192.168.3.0 0.0.0.255 area 0
network 192.168.4.0 0.0.0.255 area 2
default-information originate
//EIGRP 以默认路由重发布到OSPF
ip route 0.0.0.0 0.0.0.0 Null0
//静态路由配置
R4
interface Serial1/0
ip address 192.168.4.2 255.255.255.0
interface Serial1/1
ip address 192.168.5.1 255.255.255.0
router ospf 10
area 2 virtual-link 192.168.4.1
//在区域2上设置虚拟链路指向BRD router id
area 3 stub no-summary
//设置区域3为完全末节区域
network 192.168.4.0 0.0.0.255 area 2
network 192.168.5.0 0.0.0.255 area 3
R5
interface Serial1/1
ip address 192.168.5.2 255.255.255.0
router ospf 10
area 3 stub no-summary
//设置区域3为完全末节区域
network 192.168.5.0 0.0.0.255 area 3
network 192.168.6.0 0.0.0.255 area 3
//OSPF协议配置
R6
interface Serial1/0
ip address 192.168.8.1 255.255.255.0
interface FastEthernet0/0
ip address 192.168.7.2 255.255.255.0
router rip
network 192.168.7.0
network 192.168.8.0
R7
interface FastEthernet0/0
ip address 192.168.9.1 255.255.255.0
loopback
//loopback 回环接口
interface Serial1/0
ip address 192.168.8.2 255.255.255.0
router rip
//RIP协议的配置
network 192.168.8.0
network 192.168.9.0
R8
interface Serial1/0
ip address 192.168.11.1 255.255.255.0
interface FastEthernet0/0
ip address 192.168.10.2 255.255.255.0
router eigrp 10
//EIGRP 协议的配置
network 192.168.10.0
network 192.168.11.0
R9
interface Serial1/0
ip address 192.168.11.2 255.255.255.0
interface FastEthernet0/0
ip address 192.168.12.1 255.255.255.0
loopback
router eigrp 10
//EIGRP 协议的配置
network 192.168.11.0
network 192.168.12.0
路由表
R1#show ip route
// 路由器位于末节区域只能看到域内和域间路由,其他外部路由以默认显示
O IA 192.168.4.0/24 [110/192] via 192.168.2.2, 00:27:44, Serial1/0
//域间路由
O IA 192.168.5.0/24 [110/256] via 192.168.2.2, 00:27:44, Serial1/0
O IA 192.168.6.0/24 [110/257] via 192.168.2.2, 00:24:52, Serial1/0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, Serial1/0
O IA 192.168.3.0/24 [110/128] via 192.168.2.2, 00:27:44, Serial1/0
//域内路由
O*IA 0.0.0.0/0 [110/65] via 192.168.2.2, 00:27:44, Serial1/0
//默认路由
R2# show ip route
R 192.168.8.0/24 [120/1] via 192.168.7.2, 00:00:08, FastEthernet0/0
R 192.168.9.0/24 [120/2] via 192.168.7.2, 00:00:08, FastEthernet0/0
//RIP网络
O IA 192.168.4.0/24 [110/128] via 192.168.3.2, 00:26:48, Serial1/1
O IA 192.168.5.0/24 [110/192] via 192.168.3.2, 00:26:48, Serial1/1
O IA 192.168.6.0/24 [110/193] via 192.168.3.2, 00:24:02, Serial1/1
C 192.168.7.0/24 is directly connected, FastEthernet0/0
O 192.168.1.0/24 [110/65] via 192.168.2.1, 00:26:48, Serial1/0
//OSPF网络
C 192.168.2.0/24 is directly connected, Serial1/0
C 192.168.3.0/24 is directly connected, Serial1/1
S* 0.0.0.0/0 is directly connected, Null0
//静态路由
R3# show ip route
D 192.168.12.0/24 [90/2174976] via 192.168.10.2, 01:05:30, FastEthernet0/0
O E2 192.168.8.0/24 [110/20] via 192.168.3.1, 00:23:42, Serial1/1
O E2 192.168.9.0/24 [110/20] via 192.168.3.1, 00:23:42, Serial1/1
C 192.168.10.0/24 is directly connected, FastEthernet0/0
D 192.168.11.0/24 [90/2172416] via 192.168.10.2, 01:05:30, FastEthernet0/0
C 192.168.4.0/24 is directly connected, Serial1/0
O IA 192.168.5.0/24 [110/128] via 192.168.4.2, 01:19:46, Serial1/0
O IA 192.168.6.0/24 [110/129] via 192.168.4.2, 00:23:47, Serial1/0
O E2 192.168.7.0/24 [110/20] via 192.168.3.1, 00:23:42, Serial1/1
O IA 192.168.1.0/24 [110/129] via 192.168.3.1, 00:26:33, Serial1/1
O IA 192.168.2.0/24 [110/128] via 192.168.3.1, 01:19:46, Serial1/1
C 192.168.3.0/24 is directly connected, Serial1/1
S* 0.0.0.0/0 is directly connected, Null0
R4#show ip route
O E2 192.168.8.0/24 [110/20] via 192.168.4.1, 00:24:28, Serial1/0
O E2 192.168.9.0/24 [110/20] via 192.168.4.1, 00:24:28, Serial1/0
C 192.168.4.0/24 is directly connected, Serial1/0
C 192.168.5.0/24 is directly connected, Serial1/1
O 192.168.6.0/24 [110/65] via 192.168.5.2, 00:24:28, Serial1/1
//学习到OSPF
O E2 192.168.7.0/24 [110/20] via 192.168.4.1, 00:24:28, Serial1/0
O IA 192.168.1.0/24 [110/193] via 192.168.4.1, 00:24:28, Serial1/0
O IA 192.168.2.0/24 [110/192] via 192.168.4.1, 00:24:28, Serial1/0
O 192.168.3.0/24 [110/128] via 192.168.4.1, 00:25:08, Serial1/0
O*E2 0.0.0.0/0 [110/1] via 192.168.4.1, 00:24:28, Serial1/0
R5#show ip route
//此路由器位于完全末节区域3区域,只显示直连路由与默认路由
C 192.168.5.0/24 is directly connected, Serial1/1
C 192.168.6.0/24 is directly connected, FastEthernet0/0
//直连路由
O*IA 0.0.0.0/0 [110/65] via 192.168.5.1, 00:25:24, Serial1/1
//默认路由
R6# show ip route
C 192.168.8.0/24 is directly connected, Serial1/0
R 192.168.9.0/24 [120/1] via 192.168.8.2, 00:00:04, Serial1/0
//学习到rip网络
C 192.168.7.0/24 is directly connected, FastEthernet0/0
R* 0.0.0.0/0 [120/1] via 192.168.7.1, 00:00:28, FastEthernet0/0
//学习到默认路由
R7#show ip route
C 192.168.8.0/24 is directly connected, Serial1/0
C 192.168.9.0/24 is directly connected, FastEthernet0/0
R 192.168.7.0/24 [120/1] via 192.168.8.1, 00:00:03, Serial1/0
R* 0.0.0.0/0 [120/2] via 192.168.8.1, 00:00:03, Serial1/0
//学习到默认路由
R8#show ip route
D
192.168.12.0/24 [90/212233] via 192.168.11.2, 01:34:18, Serial1/0
//学习到EIGRP网络
D EX 192.168.8.0/24
[170/1280028160] via 192.168.10.1, 00:27:40, FastEthernet0/0
D EX 192.168.9.0/24
[170/1280028160] via 192.168.10.1, 00:27:40, FastEthernet0/0
C
192.168.10.0/24 is directly connected, FastEthernet0/0
C
192.168.11.0/24 is directly connected, Serial1/0
D EX 192.168.4.0/24
[170/1280028160] via 192.168.10.1, 00:27:40, FastEthernet0/0
D EX 192.168.5.0/24
[170/1280028160] via 192.168.10.1, 00:27:40, FastEthernet0/0
D EX 192.168.6.0/24
[170/1280028160] via 192.168.10.1, 00:22:24, FastEthernet0/0
D EX 192.168.7.0/24
[170/1280028160] via 192.168.10.1, 00:27:40, FastEthernet0/0
D EX 192.168.1.0/24
[170/1280028160] via 192.168.10.1, 00:25:11, FastEthernet0/0
D EX 192.168.2.0/24
[170/1280028160] via 192.168.10.1, 00:27:41, FastEthernet0/0
D EX 192.168.3.0/24
[170/1280028160] via 192.168.10.1, 00:27:41, FastEthernet0/0
R9#show ip route
C 192.168.12.0/24 is directly connected, FastEthernet0/0
D EX 192.168.8.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D EX 192.168.9.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D 192.168.10.0/24 [90/2172416] via 192.168.11.1, 02:14:51, Serial1/0
//学习到EIGRP网络
C 192.168.11.0/24 is directly connected, Serial1/0
D EX 192.168.4.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D EX 192.168.5.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D EX 192.168.6.0/24 [170/1280540160] via 192.168.11.1, 00:23:00, Serial1/0
D EX 192.168.7.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D EX 192.168.1.0/24 [170/1280540160] via 192.168.11.1, 00:25:46, Serial1/0
D EX 192.168.2.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
D EX 192.168.3.0/24 [170/1280540160] via 192.168.11.1, 00:28:16, Serial1/0
//通过重发布学习到EIGRP网络
测试