OSPF在企业网上的应用
OSPF简介:
OSPF是Open Shortest Path First(开放最短路由优先协议)的缩写。他是IETF组织开发的一个基于链路状态的自治系统内部路由协议。
实验环境:cisco
一、
为什么要使用OSPF来作为企业网中的动态路由协议?
企业网内的动态路由,常用的就三种:rip,ospf和eigrp,前两种是公开协议,每个厂家的路由器都支持,最后一种是cisco的私有协议,只有思科路由器可以使用该协议。
rip只适合用于规模较小的网络,因为其原理,决定了网络越大,使用rip消耗的网络带宽、处理器、内存资源就越多。ospf和eigrp都考虑到了大型网络的需要,适合较大型的企业网,但eigrp是思科私有的,有些用户对其不太感冒,希望用开放的协议。
所以最后就只剩下ospf可以选了。
OSPF有什么样的特点?
1、路由更新:触发更新,只有当网络结构发生变化时才进行路由更新;
2、网络规模:ospf最多可支持500台以上路由器工作;
3、具有认证机制,保证安全;
4、收敛的速度快;
5、负载均衡;
6、属于无环路径,不会形成路由环路。
7、支持vlsm子网和子网不连续
8、拥有区域划分功能,将故障屏蔽在单个区域;
9、丰富的策略,控制路由和报文
10、路由更新以组播的方式进行传递。
OSPF路由表形成的过程?
首先A向B发送hello包,当B接收到hello包后,将A添加到邻居表格。
然后B再向A发送hello包,当A接收到hello包后,将B添加到邻居表格,这时候A和B将达到two-way状态(双向状态)。
然后,比较路由器的优先级,选取出DR和BDR。若B为DR,所以A只能与B互换LSDB(链路状态数据库),在进行互换之前,A与B首先比较RouteID,可以发现B的RouteID大于A的,所以,B会先将自己的DBD(大纲)发送给A。A再将自己的DBD发送给B。两者都受到对方的DBD后,都会返回一个LSack(链路状态应答)。
当B获得A的DBD后,如果有陌生的条目,会再向A请求LSR(链路状态信息),然后,A会向B回复相应的信息LSU(链路状态更新)。直到A与B的LSDB达到一致后,两者处于full状态。
当A与B达到full状态后,每台路由器会通过SPF算法来计算最优的路由表格。
多区域OSPF有什么优点?
1、减少路由器的路由条目,从而减少资源的占用;
2、减少LSA的泛洪;减少由于网络不稳定而造成的,所有路由器泛洪LSA形成网络拥塞堵塞;
3、提高路由的效率:缩减部分路由器的OSPF路由条目,降低路由收敛的复杂度,对某些特定的lsa,可以在区域边界上,实现汇总/过滤/控制,而实现全网互通
二、
案例1:多区域OSPF和路由再发布
拓扑图:(地址方案)
配置:(详细步骤和详细说明)
配置路由器R1:
en
conf t
line console 0
##配置日志同步
logging sy
##取消连接超时
no exec-t
exit
##为fa0/0配置地址
int fa 0/0
ip add 192.168.1.1 255.255.255.0
no shut
exit
##为serial2/0配置地址和时钟
int s 2/0
clock rate 64000
ip add 192.168.2.1 255.255.255.0
no shut
exit
##开启ospf并划分相应的区域
route ospf 100
network 192.168.1.0 0.0.0.255 area 1
network 192.168.2.0 0.0.0.255 area 1
exit
##查看路由表信息
Router#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, Serial2/0
O IA 192.168.3.0/24 [110/1562] via 192.168.2.2, 00:10:26, Serial2/0
O IA 192.168.4.0/24 [110/2343] via 192.168.2.2, 00:07:29, Serial2/0
O IA 192.168.5.0/24 [110/2344] via 192.168.2.2, 00:06:43, Serial2/0
O E2 192.168.6.0/24 [110/20] via 192.168.2.2, 00:05:00, Serial2/0
O E2 192.168.7.0/24 [110/20] via 192.168.2.2, 00:04:48, Serial2/0
Router#
Router#
配置路由器R2:
en
conf t
line console 0
##配置日志同步
logging sy
##取消连接超时
no exec-t
exit
##为serial3/0配置地址
int s 3/0
ip add 192.168.2.2 255.255.255.0
no shut
exit
##为serial2/0配置地址和时钟
int s 2/0
clock r
clock rate 64000
ip add 192.168.3.1 255.255.255.0
no shut
exit
##为fa0/0配置地址
int fa 0/0
ip add 192.168.6.1 255.255.255.0
no shut
exit
##开启ospf并划分相应的区域
route ospf 100
network 192.168.2.0 0.0.0.255 area 1
network 192.168.3.0 0.0.0.255 area 0
exit
##开启rip并配置路由转发的链路
route rip
network 192.168.6.0
exit
##配置从rip区域到ospf区域的重分发
route ospf 100
redistribute connected
redistribute rip
exit
##配置从ospf区域到rip区域的重分发
route rip
redistribute connected
redistribute ospf 100 metric 2
exit
%SYS-5-CONFIG_I: Configured from console by console
##查看路由表信息
Router#show ip rout
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
O 192.168.1.0/24 [110/782] via 192.168.2.1, 00:10:55, Serial3/0
C 192.168.2.0/24 is directly connected, Serial3/0
C 192.168.3.0/24 is directly connected, Serial2/0
O IA 192.168.4.0/24 [110/1562] via 192.168.3.2, 00:08:02, Serial2/0
O IA 192.168.5.0/24 [110/1563] via 192.168.3.2, 00:07:17, Serial2/0
C 192.168.6.0/24 is directly connected, FastEthernet0/0
R 192.168.7.0/24 [120/1] via 192.168.6.2, 00:00:13, FastEthernet0/0
Router#
配置路由器R3:
en
conf t
line console 0
##配置日志同步
logging sy
##取消连接超时
no exec-t
exit
##为serial3/0配置地址
int s 3/0
ip add 192.168.3.2 255.255.255.0
no shut
exit
##为serial2/0配置地址和时钟
int s 2/0
clock ra
clock rate 64000
ip add 192.168.4.1 255.255.255.0
no shut
exit
##开启ospf并划分相应的区域
route ospf 100
network 192.168.3.0 0.0.0.255 area 0
network 192.168.4.0 0.0.0.255 area 2
exit
##查看路由表信息
Router#show ip rout
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
O IA 192.168.1.0/24 [110/1563] via 192.168.3.1, 00:08:49, Serial3/0
O IA 192.168.2.0/24 [110/1562] via 192.168.3.1, 00:08:49, Serial3/0
C 192.168.3.0/24 is directly connected, Serial3/0
C 192.168.4.0/24 is directly connected, Serial2/0
O 192.168.5.0/24 [110/782] via 192.168.4.2, 00:07:41, Serial2/0
O E2 192.168.6.0/24 [110/20] via 192.168.3.1, 00:05:48, Serial3/0
O E2 192.168.7.0/24 [110/20] via 192.168.3.1, 00:05:36, Serial3/0
Router#
配置路由器R4:
en
conf t
line console 0
##配置日志同步
logging sy
##取消连接超时
no exec-t
exit
##为serial3/0配置地址
int s 3/0
ip add 192.168.4.2 255.255.255.0
no shut
exit
##为fa0/0配置地址
int fa 0/0
ip add 192.168.5.1 255.255.255.0
no shut
exit
##开启ospf并划分相应的区域
route ospf 100
network 192.168.4.0 0.0.0.255 area 2
network 192.168.5.0 0.0.0.255 area 2
exit
##查看路由表信息
Router#show ip rout
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
O IA 192.168.1.0/24 [110/2344] via 192.168.4.1, 00:08:06, Serial3/0
O IA 192.168.2.0/24 [110/2343] via 192.168.4.1, 00:08:06, Serial3/0
O IA 192.168.3.0/24 [110/1562] via 192.168.4.1, 00:08:06, Serial3/0
C 192.168.4.0/24 is directly connected, Serial3/0
C 192.168.5.0/24 is directly connected, FastEthernet0/0
Router#
配置路由器R5:
en
conf t
line console 0
##配置日志同步
logging sy
##取消连接超时
no exec-t
exit
##为fa1/0配置地址
int fa 1/0
ip add 192.168.6.2 255.255.255.0
no shut
exit
##为fa0/0配置地址
int fa 0/0
ip add 192.168.7.1 255.255.255.0
no shut
exit
##开启rip并配置路由转发的链路
route rip
network 192.168.6.0
network 192.168.7.0
exit
##查看路由表信息
Router#show ip rout
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
R 192.168.1.0/24 [120/2] via 192.168.6.1, 00:00:13, FastEthernet1/0
R 192.168.2.0/24 [120/1] via 192.168.6.1, 00:00:28, FastEthernet1/0
R 192.168.3.0/24 [120/1] via 192.168.6.1, 00:00:28, FastEthernet1/0
R 192.168.4.0/24 [120/2] via 192.168.6.1, 00:00:13, FastEthernet1/0
R 192.168.5.0/24 [120/2] via 192.168.6.1, 00:00:13, FastEthernet1/0
C 192.168.6.0/24 is directly connected, FastEthernet1/0
C 192.168.7.0/24 is directly connected, FastEthernet0/0
Router#
三、
小结:作为一种链路状态的路由协议,OSPF具备许多优点:快速收敛,支持变长网络屏蔽码,支持CIDR以及地址summary,具有层次化的网络结构,支持路由信息验证等。所有这些特点保证了OSPF路由协议能够被应用到大型的、复杂的网络环境中。