OSPF 如果有多个区域,则其中一个必须为区域0,即骨干区域,其他所有区域都与区域0直接相连,且区域0必须是连续的,OSPF 要求所有非骨干区域都将路由通告给骨干,以便将这些路由通告到其他区域。
OSPF 虚链路作用
通过使用虚链路,可以将不连续的区域0连接起来,还可将区域通过中转区域连接到区域0。但是不应将其作为一种主要的骨干设计功能(不等同于骨干区域),应只在出现故障后使用OSPF虚链路功能来提供临时连接或备用连接。
背景:
R1不能学习到R4的路由
步骤1:配置各设备接口的 IP地址
R1(config)#interface GigabitEthernet 0/0
R1(config-if-GigabitEthernet 0/0)#ip address 192.168.1.1 255.255.255.0
R1(config-if-GigabitEthernet 0/0)#exit
R2(config)#interface GigabitEthernet 0/0
R2(config-if-GigabitEthernet 0/0)#ip address 192.168.1.2 255.255.255.0
R2(config-if-GigabitEthernet 0/0)#exit
R2(config)#interface GigabitEthernet 0/1
R2(config-if-GigabitEthernet 0/1)#ip address 192.168.2.1 255.255.255.0
R2(config-if-GigabitEthernet 0/1)#exit
R3(config)#interface GigabitEthernet 0/0
R3(config-if-GigabitEthernet 0/0)#ip address 192.168.3.1 255.255.255.0
R3(config-if-GigabitEthernet 0/0)#exit
R3(config)#interface GigabitEthernet 0/1
R3(config-if-GigabitEthernet 0/1)#ip address 192.168.2.2 255.255.255.0
R3(config-if-GigabitEthernet 0/1)#exit
R4(config)#interface GigabitEthernet 0/0
R4(config-if-GigabitEthernet 0/0)#ip address 192.168.3.2 255.255.255.0
R4(config-if-GigabitEthernet 0/0)#exit
步骤2:启动OSPF并设置 router-id,并把对应的接口通告到指定区域
R1(config)route ospf 1
R1(config-router)#router-id 1.1.1.1
Change router-id and update OSPF process! [yes/no]:yes
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
R1(config-router)#exit
R2(config)#route ospf 1
R2(config-router)#router-id 2.2.2.2
Change router-id and update OSPF process! [yes/no]:yes
R2(config-router)#network 192.168.1.0 0.0.0.255 area 0
R2(config-router)#network 192.168.2.0 0.0.0.255 area 1
R2(config-router)#exit
R3(config)#route ospf 1
R3(config-router)#router-id 3.3.3.3
Change router-id and update OSPF process! [yes/no]:yes
R3(config-router)#network 192.168.2.0 0.0.0.255 area 1
R3(config-router)#network 192.168.3.0 0.0.0.255 area 2
R3(config-router)#exit
R4(config)#route ospf 1
R4(config-router)#router-id 4.4.4.4
Change router-id and update OSPF process! [yes/no]:yes
R4(config-router)#network 192.168.3.0 0.0.0.255 area 2
R4(config-router)#exit
步骤3:查看各设备的 OSPF 邻居建立是否成功
R1#show ip ospf neighbor
OSPF process 1, 1 Neighbors, 1 is Full:
Neighbor ID Pri State BFD State Dead Time Address Interface
2.2.2.2 1 Full/BDR - 00:00:32 192.168.1.2 GigabitEthernet 0/0
R2#show ip ospf neighbor
OSPF process 1, 3 Neighbors, 3 is Full:
Neighbor ID Pri State BFD State Dead Time Address Interface
1.1.1.1 1 Full/DR - 00:00:33 192.168.1.1 GigabitEthernet 0/0
3.3.3.3 1 Full/DR - 00:00:35 192.168.2.2 GigabitEthernet 0/1
R3#show ip ospf neighbor
OSPF process 1, 3 Neighbors, 3 is Full:
Neighbor ID Pri State BFD State Dead Time Address Interface
2.2.2.2 1 Full/BDR - 00:00:38 192.168.2.1 GigabitEthernet 0/0
4.4.4.4 1 Full/DR - 00:00:36 192.168.3.2 GigabitEthernet 0/1
R4#show ip ospf neighbor
OSPF process 1, 1 Neighbors, 1 is Full:
Neighbor ID Pri State BFD State Dead Time Address Interface
3.3.3.3 1 Full/BDR - 00:00:39 192.168.3.1 GigabitEthernet 0/0
步骤4:让R2和R3建立ospf虚拟链路
R2(config)#route ospf 1
# 其中 3.3.3.3、2.2.2.2 为 对端设备 OSPF 的 Route-id
R2(config-router)#area 1 virtual-link 3.3.3.3
R2(config-router)#exit
R3(config)#route ospf 1
R3(config-router)#area 1 virtual-link 2.2.2.2
R3(config-router)#exit
步骤5:查看R1是否学到192.168.2.0和192.168.3.0的邻居关系
R1#show ip route
Codes: C - Connected, L - Local, S - Static
R - RIP, O - OSPF, B - BGP, I - IS-IS, V - Overflow route
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
SU - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
IA - Inter area, EV - BGP EVPN, A - Arp to host
LA - Local aggregate route
* - candidate default
Gateway of last resort is no set
C 192.168.1.0/24 is directly connected, GigabitEthernet 0/0
C 192.168.1.1/32 is local host.
O IA 192.168.2.0/24 [110/2] via 192.168.1.2, 00:07:04, GigabitEthernet 0/0
O IA 192.168.3.0/24 [110/3] via 192.168.1.2, 00:05:54, GigabitEthernet 0/0
步骤6:在R2,R3上查看虚链路的运行状态
R2#show ip ospf virtual-links
Virtual Link VLINK0 to router 3.3.3.3 is up
Transit area 0.0.0.1 via interface GigabitEthernet 0/1
Local address 192.168.2.1/32
Remote address 192.168.2.2/32
Transmit Delay is 1 sec, State Point-To-Point,
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:05
Adjacency state Full
R3#show ip ospf virtual-links
Virtual Link VLINK0 to router 2.2.2.2 is up
Transit area 0.0.0.1 via interface GigabitEthernet 0/0
Local address 192.168.2.2/32
Remote address 192.168.2.1/32
Transmit Delay is 1 sec, State Point-To-Point,
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:07
Adjacency state Full