OSPF简介
-
OSPF(Open Shortest Path First,开放最短路径优先)是典型的链路状态路由协议,是目前业内使用最广泛的IGP之一;
-
路由器之间交互的是链路状态信息,而不是直接交互路由;
-
每台OSPF路由器都知晓网络拓扑结构,采用SPF算法计算达到目的地的最短路径;
-
支持VLSM,支持手工路由汇总;
-
多区域的设计使得OSPF能够支持更大规模的网络。
OSPF metric
OSPF报文类型
OSPF的三张表
OSPF邻居建立过程
OSPF区域
单区域OSPF
多区域OSPF
DR与BDR
实验拓扑
配置三台路由器
配置R1
R1#configure
R1(config)#interface e0/0
R1(config-if)#ip address 192.168.12.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface e0/1
R1(config-if)#ip address 192.168.14.1 255.255.255.0
R1(config-if)#no shutdown
R1(config)#router ospf 1
R1(config-router)#network 192.168.12.0 0.0.0.255 area 0
R1(config-router)#network 192.168.14.0 0.0.0.255 area 0
配置R2
R2#configure
R2(config)#interface e0/0
R2(config-if)#ip address 192.168.12.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#interface e0/1
R2(config-if)#ip address 192.168.23.2 255.255.255.0
R2(config-if)#no shutdown
R2(config)#router ospf 1
R2(config-router)#network 192.168.12.0 0.0.0.255 area 0
R2(config-router)#network 192.168.23.0 0.0.0.255 area 0
配置R3
R3#configure
R3(config)#interface e0/0
R3(config-if)#ip address 192.168.23.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#interface e0/1
R3(config-if)#ip address 192.168.35.3 255.255.255.0
R3(config-if)#no shutdown
R3(config)#router ospf 1
R3(config-router)#network 192.168.23.0 0.0.0.255 area 0
R3(config-router)#network 192.168.35.0 0.0.0.255 area 0
查看OSPF的一些相关信息
查看OSPF邻居关系
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.23.2 1 FULL/BDR 00:00:32 192.168.12.2 Ethernet0/0
R2#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.35.3 1 FULL/BDR 00:00:33 192.168.23.3 Ethernet0/1
192.168.14.1 1 FULL/DR 00:00:30 192.168.12.1 Ethernet0/0
R3#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.23.2 1 FULL/DR 00:00:39 192.168.23.2 Ethernet0/0
查看路由表
R1#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is not set
192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.12.0/24 is directly connected, Ethernet0/0
L 192.168.12.1/32 is directly connected, Ethernet0/0
192.168.14.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.14.0/24 is directly connected, Ethernet0/1
L 192.168.14.1/32 is directly connected, Ethernet0/1
O 192.168.23.0/24 [110/20] via 192.168.12.2, 00:12:52, Ethernet0/0
O 192.168.35.0/24 [110/30] via 192.168.12.2, 00:09:15, Ethernet0/0
R2#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is not set
192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.12.0/24 is directly connected, Ethernet0/0
L 192.168.12.2/32 is directly connected, Ethernet0/0
O 192.168.14.0/24 [110/20] via 192.168.12.1, 00:12:59, Ethernet0/0
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, Ethernet0/1
L 192.168.23.2/32 is directly connected, Ethernet0/1
O 192.168.35.0/24 [110/20] via 192.168.23.3, 00:09:35, Ethernet0/1
R3#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is not set
O 192.168.12.0/24 [110/20] via 192.168.23.2, 00:10:01, Ethernet0/0
O 192.168.14.0/24 [110/30] via 192.168.23.2, 00:10:01, Ethernet0/0
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, Ethernet0/0
L 192.168.23.3/32 is directly connected, Ethernet0/0
192.168.35.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.35.0/24 is directly connected, Ethernet0/1
L 192.168.35.3/32 is directly connected, Ethernet0/1
配置VP4和VP5互通
VPC4> ip 192.168.14.4/24 192.168.14.1
Checking for duplicate address...
VPC4 : 192.168.14.4 255.255.255.0 gateway 192.168.14.1
VPC5> ip 192.168.35.5/24 192.168.35.3
Checking for duplicate address...
VPC5 : 192.168.35.5 255.255.255.0 gateway 192.168.35.3
ping 测试
VPC4> ping 192.168.35.5
84 bytes from 192.168.35.5 icmp_seq=1 ttl=61 time=2.053 ms
84 bytes from 192.168.35.5 icmp_seq=2 ttl=61 time=1.616 ms
84 bytes from 192.168.35.5 icmp_seq=3 ttl=61 time=1.428 ms
84 bytes from 192.168.35.5 icmp_seq=4 ttl=61 time=1.505 ms
84 bytes from 192.168.35.5 icmp_seq=5 ttl=61 time=1.694 ms