相信ospf大家都不会陌生,ospf属于链路状态的路由协议。一般用于大型企业中,他是一个rfc标准不像eigrp是cisco的私有只能在cisco路由器上用,因此如果有不同厂商的路由器就要用ospf,当然我们还有强大的重分发工具可以使用。ospf有三张表,邻居表,可以通过命令show ip ospf nei查看。拓扑表,可以通过show ip ospf data查看,ospf根据拓扑表中的数据运行spf算法算出最佳路由放入第三张表,路由表,而这张表相信大家都不会陌生,而命令就更不用说了。以往我们都做的是单区域的ospf配置,今天做双区域的配置,其中在查看路由条目的时候会有很大的不同额。先介绍几个概念。ABR简称边界路由器,它连接的是多个ospf区域,就比如本实验中的R3。ASBR区域边界路由器,这种路由器是运行了多种路由协议的路由器,好像翻译。区域内路由器,就是一个区域内的普通路由器。还有一个需要注意的地方,所有的区域都必须与区域0相连,如果不能相连都要通过虚链路通过中转区域与区域0相连。
r1,r2和r3的e1/1,e1/2属于区域0.r3的e1/3,e1/4和r4,r5属于区域1.r1,r2,r4,r5都属于区域内路由器,r3属于abr。
r1:
in e1/0
ip add 192.168.1.1 255.255.255.0
no sh
in loop 1
ip add 172.16.0.1 255.255.255.0
in loop 2
ip add 172.16.1.1 255.255.255.0
in loop 3
ip add 172.16.2.1 255.255.255.0
in loop 4
ip add 172.16.3.1 255.255.255.0
router ospf 1
router-id 1.1.1.1
net 192.168.1.1 0.0.0.0 a 0
net 172.16.0.1 0.0.0.0 a 0
net 172.16.1.1 0.0.0.0 a 0
net 172.16.2.1 0.0.0.0 a 0
net 172.16.3.1 0.0.0.0 a 0
r2:
in e1/1
ip add 192.168.2.1 255.255.255.0
no sh
router ospf 1
net 192.168.2.1 0.0.0.0 a 0
router-d 2.2.2.2
r3:
in e1/1
ip add 192.168.1.2 255.255.255.0
no sh
in e1/2
ip add 192.168.2.2 255.255.255.0
no sh
in e1/3
ip add 192.168.3.1 255.255.255.0
no sh
in e1/4
ip add 192.168.4.1 255.255.255.0
router ospf 1
router-id 3.3.3.3
net 192.168.1.2 0.0.0.0 a 0
net 192.168.2.2 0.0.0.0 a 0
net 192.168.3.1 0.0.0.0 a 1
net 192.168.4.1 0.0.0.0 a 1
r4:
in e1/1
ip add 192.168.3.2 255.255.255.0
no sh
in e1/2
ip add 192.168.5.2 255.255.255.0
no sh
router ospf 1
router-id 4.4.4.4
net 192.168.3.2 0.0.0.0 a 1
net 192.168.5.2 0.0.0.0 a 1
r5:
in e1/1
ip add 192.168.4.2 255.255.255.0
no sh
in e1/2
ip add 192.168.5.1 255.255.255.0
no sh
router ospf 1
net 192.168.4.2 0.0.0.0 a 1
net 192.168.5.1 0.0.0.0 a 1
验证命令:
show ip ro
show ip ospf nei
show runn
输出示例:
在R2上的路由表输出
R2#show ip ro
Codes: C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/32 is subnetted, 4 subnets
O 172.16.1.1 [110/21] via 192.168.2.2, 00:00:03, Ethernet1/1
O 172.16.0.1 [110/21] via 192.168.2.2, 00:00:03, Ethernet1/1
O 172.16.3.1 [110/21] via 192.168.2.2, 00:00:03, Ethernet1/1
O 172.16.2.1 [110/21] via 192.168.2.2, 00:00:03, Ethernet1/1
O IA 192.168.4.0/24 [110/20] via 192.168.2.2, 00:00:03, Ethernet1/1
O IA 192.168.5.0/24 [110/30] via 192.168.2.2, 00:00:03, Ethernet1/1
O 192.168.1.0/24 [110/20] via 192.168.2.2, 00:00:03, Ethernet1/1
C 192.168.2.0/24 is directly connected, Ethernet1/1
O IA 192.168.3.0/24 [110/20] via 192.168.2.2, 00:00:03, Ethernet1/1
R2#show ip ospf nei
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/BDR 00:00:39 192.168.2.2 Ethernet1/1
有一个很有趣的现象,从区域1学来的路由在O后面都有一个IA标志,这表明这是一条区域间路由
再看看R5上的输出
R5#show ip ro
Codes: C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/32 is subnetted, 4 subnets
O IA 172.16.1.1 [110/21] via 192.168.4.1, 00:18:29, Ethernet1/1
O IA 172.16.0.1 [110/21] via 192.168.4.1, 00:18:39, Ethernet1/1
O IA 172.16.3.1 [110/21] via 192.168.4.1, 00:18:19, Ethernet1/1
O IA 172.16.2.1 [110/21] via 192.168.4.1, 00:18:29, Ethernet1/1
C 192.168.4.0/24 is directly connected, Ethernet1/1
C 192.168.5.0/24 is directly connected, Ethernet1/3
O IA 192.168.1.0/24 [110/20] via 192.168.4.1, 00:36:11, Ethernet1/1
O IA 192.168.2.0/24 [110/20] via 192.168.4.1, 00:36:11, Ethernet1/1
O 192.168.3.0/24 [110/20] via 192.168.5.2, 00:36:11, Ethernet1/3
[110/20] via 192.168.4.1, 00:36:11, Ethernet1/1
R5#show ip ospf nei
Neighbor ID Pri State Dead Time Address Interface
4.4.4.4 1 FULL/BDR 00:00:34 192.168.5.2 Ethernet1/3
3.3.3.3 1 FULL/DR 00:00:34 192.168.4.1 Ethernet1/1
是不是很简单?
上次我讲过eigrp汇总,这次顺便也讲一下ospf的汇总。ospf汇总只能在abr和asbr上汇总,而asbr我暂时不讲,今天先讲讲在abr上的汇总。无论是从R5还是R2上的路由表输出都表明我配置的4个环回接口都被学习到了,而且有4条路由条目,我现在就进行汇总将这4条路由汇总为1条。
r3:
router ospf 1
area 0 range 172.16.0.0 255.255.252.0
配置很简单,一条命令就搞定了,简单解释下area 0表示汇总区域0的路由,而后面的是具体的汇总路由。
再看看R5的输出
R5#show ip ro
Codes: C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/22 is subnetted, 1 subnets
O IA 172.16.0.0 [110/21] via 192.168.4.1, 00:00:25, Ethernet1/1
C 192.168.4.0/24 is directly connected, Ethernet1/1
C 192.168.5.0/24 is directly connected, Ethernet1/3
O IA 192.168.1.0/24 [110/20] via 192.168.4.1, 00:42:10, Ethernet1/1
O IA 192.168.2.0/24 [110/20] via 192.168.4.1, 00:42:10, Ethernet1/1
O 192.168.3.0/24 [110/20] via 192.168.5.2, 00:42:10, Ethernet1/3
[110/20] via 192.168.4.1, 00:42:10, Ethernet1/1
r2上的路由输出
R2#show ip rout ospf
172.16.0.0/32 is subnetted, 4 subnets
O 172.16.1.1 [110/21] via 192.168.2.2, 00:30:29, Ethernet1/1
O 172.16.0.1 [110/21] via 192.168.2.2, 00:30:29, Ethernet1/1
O 172.16.3.1 [110/21] via 192.168.2.2, 00:30:29, Ethernet1/1
O 172.16.2.1 [110/21] via 192.168.2.2, 00:30:29, Ethernet1/1
O IA 192.168.4.0/24 [110/20] via 192.168.2.2, 00:30:29, Ethernet1/1
O IA 192.168.5.0/24 [110/30] via 192.168.2.2, 00:30:29, Ethernet1/1
O 192.168.1.0/24 [110/20] via 192.168.2.2, 00:30:29, Ethernet1/1
O IA 192.168.3.0/24 [110/20] via 192.168.2.2, 00:30:29, Ethernet1/1
本文出自 “话巴山夜雨时” 博客,转载请与作者联系!