9.2 OSPF多区域配置
9.2.1 原理概述
在OSPF单区域中,每台路由器都需要收集其他所有路由器的链路状态信息,如果网络规模不断扩大,链路状态信息也会随之不断增多,这将使得单台路由器上链路状态数据库非常庞大,导致路由器负担加重,也不便于维护管理。为了解决上述问题,OSPF协议可以将整个自治系统划分为不同的区域(Area),就像一个国家的国土面积很大时,会把整个国家划分为不同的省份来管理一样。
链路状态信息只在区域内部泛洪,区域之间传递的只是路由条目而非链路状态信息,因此大大减小了路由器的负担。当一台路由器属于不同区域时称它为区域边界路由器(Area Border Router,ABR),负责传递区域间路由信息。区域间的路由信息传递类似距离矢量算法,为了防止区域间产生环路,所有非骨干区域之间的路由信息必须经过骨干区域,也就是说非骨干区域必须和骨干区域相连,且非骨干区域之间不能直接进行路由信息交互。
9.2.2 实验内容
本实验模拟企业网络场景。R1、R2、R3、R4为企业总部核心区域设备,属于区域0,R5属于新增分支机构A的网关设备,R6属于新增分支机构B的网关设备。PC-1和PC-2分别属于分支机构A和B,PC-3和PC-4属于总部管理员登录设备,用于管理网络。在该网络中,如果设计方案采用单区域配置,则会导致单一区域LSA数目过于庞大,导致路由器开销过高,SPF算法运算过于频繁。因此网络管理员选择配置多区域方案进行网络配置,将两个新分支运行在不同的OSPF区域中,其中R5属于区域1,R6属于区域2。
9.2.3 实验拓扑图
9.2.4 实验编址表
设备 | 接口 | IP地址 | 子网掩码 | 默认网关 |
---|---|---|---|---|
AR1(AR2220) | GE 0/0/0 | 172.16.3.1 | 255.255.255.252 | N/A |
AR1(AR2220) | GE 0/0/1 | 172.16.2.1 | 255.255.255.252 | N/A |
AR1(AR2220) | GE 0/0/2 | 172.16.1.1 | 255.255.255.252 | N/A |
AR2(AR2220) | GE 0/0/0 | 172.16.3.2 | 255.255.255.252 | N/A |
AR2(AR2220) | GE 0/0/1 | 172.16.4.2 | 255.255.255.252 | N/A |
AR2(AR2220) | GE 0/0/2 | 172.16.5.2 | 255.255.255.252 | N/A |
AR3(AR2220) | GE 0/0/0 | 172.16.8.2 | 255.255.255.252 | N/A |
AR3(AR2220) | GE 0/0/1 | 172.16.2.2 | 255.255.255.252 | N/A |
AR3(AR2220) | GE 0/0/2 | 172.16.7.2 | 255.255.255.252 | N/A |
AR3(AR2220) | GE 1/0/0 | 192.168.30.254 | 255.255.255.0 | N/A |
AR4(AR2220) | GE 0/0/0 | 172.16.6.1 | 255.255.255.252 | N/A |
AR4(AR2220) | GE 0/0/1 | 172.16.4.1 | 255.255.255.252 | N/A |
AR4(AR2220) | GE 0/0/2 | 172.16.7.1 | 255.255.255.252 | N/A |
AR4(AR2220) | GE 1/0/0 | 192.168.40.254 | 255.255.255.0 | N/A |
AR5(AR2220) | GE 0/0/0 | 172.16.8.1 | 255.255.255.252 | N/A |
AR5(AR2220) | GE 0/0/1 | 192.168.10.254 | 255.255.255.0 | N/A |
AR5(AR2220) | GE 0/0/2 | 172.16.1.2 | 255.255.255.252 | N/A |
AR6(AR2220) | GE 0/0/0 | 172.16.6.2 | 255.255.255.252 | N/A |
AR6(AR2220) | GE 0/0/1 | 192.168.20.254 | 255.255.255.0 | N/A |
AR6(AR2220) | GE 0/0/2 | 172.16.5.1 | 255.255.255.252 | N/A |
PC1 | Ethernet 0/0/1 | 192.168.10.1 | 255.255.255.0 | 192.168.10.254 |
PC2 | Ethernet 0/0/1 | 192.168.20.1 | 255.255.255.0 | 192.168.20.254 |
PC3 | Ethernet 0/0/1 | 192.168.30.1 | 255.255.255.0 | 192.168.30.254 |
PC4 | Ethernet 0/0/1 | 192.168.40.1 | 255.255.255.0 | 192.168.40.254 |
9.2.5 实验步骤
1、基本配置
根据实验编址表进行路由器接口配置和pcIP地址配置。
erlang
[AR1]interface GigabitEthernet 0/0/0
[AR1-GigabitEthernet0/0/0]ip address 172.16.3.1 30
[AR1-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR1-GigabitEthernet0/0/1]ip address 172.16.2.1 30
[AR1-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR1-GigabitEthernet0/0/2]ip address 172.16.1.1 30
[AR2]interface GigabitEthernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip address 172.16.3.2 30
[AR2-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip address 172.16.4.2 30
[AR2-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR2-GigabitEthernet0/0/2]ip address 172.16.5.2 30
[AR3]interface GigabitEthernet 0/0/0
[AR3-GigabitEthernet0/0/0]ip address 172.16.8.2 30
[AR3-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR3-GigabitEthernet0/0/1]ip address 172.16.2.2 30
[AR3-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR3-GigabitEthernet0/0/2]ip address 172.16.7.2 30
[AR3-GigabitEthernet0/0/2]interface GigabitEthernet 1/0/0
[AR3-GigabitEthernet1/0/0]ip address 192.168.30.254 24
[AR4]interface GigabitEthernet 0/0/0
[AR4-GigabitEthernet0/0/0]ip address 172.16.6.1 30
[AR4-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR4-GigabitEthernet0/0/1]ip address 172.16.4.1 30
[AR4-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR4-GigabitEthernet0/0/2]ip address 172.16.7.1 30
[AR4-GigabitEthernet0/0/2]interface GigabitEthernet 1/0/0
[AR4-GigabitEthernet1/0/0]ip address 192.168.40.254 24
[AR5]interface GigabitEthernet 0/0/0
[AR5-GigabitEthernet0/0/0]ip address 172.16.8.1 30
[AR5-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR5-GigabitEthernet0/0/1]ip address 192.168.10.254 24
[AR5-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR5-GigabitEthernet0/0/2]ip address 172.16.1.2 30
[AR6]interface GigabitEthernet 0/0/0
[AR6-GigabitEthernet0/0/0]ip address 172.16.6.2 30
[AR6-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[AR6-GigabitEthernet0/0/1]ip address 192.168.20.254 24
[AR6-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[AR6-GigabitEthernet0/0/2]ip address 172.16.5.1 30
配置完成后进行直连链路测试,我这里只测试一个,其他省略。
[AR6]ping 172.16.5.2
PING 172.16.5.2: 56 data bytes, press CTRL_C to break
Reply from 172.16.5.2: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 172.16.5.2: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 172.16.5.2: bytes=56 Sequence=3 ttl=255 time=20 ms
Reply from 172.16.5.2: bytes=56 Sequence=4 ttl=255 time=10 ms
Reply from 172.16.5.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 172.16.5.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/28/70 ms
2、配置骨干区域路由器
在公司总部路由器R1、R2、R3、R4上创建OSPF进程,并通告路由。
erlang
[AR1]ospf 1
[AR1-ospf-1]area 0
[AR1-ospf-1-area-0.0.0.0]network 172.16.3.0 0.0.0.3
[AR1-ospf-1-area-0.0.0.0]network 172.16.2.0 0.0.0.3
[AR2]ospf 1
[AR2-ospf-1]area 0
[AR2-ospf-1-area-0.0.0.0]network 172.16.3.0 0.0.0.3
[AR2-ospf-1-area-0.0.0.0]network 172.16.4.0 0.0.0.3
[AR3]ospf 1
[AR3-ospf-1]area 0
[AR3-ospf-1-area-0.0.0.0]network 172.16.2.0 0.0.0.3
[AR3-ospf-1-area-0.0.0.0]network 172.16.7.0 0.0.0.3
[AR3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[AR4]ospf 1
[AR4-ospf-1]area 0
[AR4-ospf-1-area-0.0.0.0]network 172.16.4.0 0.0.0.3
[AR4-ospf-1-area-0.0.0.0]network 172.16.7.0 0.0.0.3
[AR4-ospf-1-area-0.0.0.0]network 192.168.40.0 0.0.0.255
配置完成后,测试总部两台pc的连通性。
pgp
PC3>ping 192.168.40.1
Ping 192.168.40.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.40.1: bytes=32 seq=2 ttl=126 time=15 ms
From 192.168.40.1: bytes=32 seq=3 ttl=126 time=16 ms
From 192.168.40.1: bytes=32 seq=4 ttl=126 time=31 ms
From 192.168.40.1: bytes=32 seq=5 ttl=126 time=16 ms
--- 192.168.40.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/19/31 ms
3、配置非骨干区域路由器
在分支A的路由器R5上面创建OSPF进程,并进入区域1,并通告相应网段。
erlang
[AR5]ospf 1
[AR5-ospf-1]area 1
[AR5-ospf-1-area-0.0.0.1]network 172.16.1.0 0.0.0.3
[AR5-ospf-1-area-0.0.0.1]network 172.16.8.0 0.0.0.3
[AR5-ospf-1-area-0.0.0.1]network 192.168.10.0 0.0.0.255
[AR1]ospf 1
[AR1-ospf-1]area 1
[AR1-ospf-1-area-0.0.0.1]network 172.16.1.0 0.0.0.3
[AR3]ospf 1
[AR3-ospf-1]area 1
[AR3-ospf-1-area-0.0.0.1]network 172.16.8.0 0.0.0.3
使用display ospf peer
命令查看OSPF邻居状态,可以看到OSPF邻居关系建立正常,State状态都为full状态。
pgp
[AR5]display ospf peer
OSPF Process 1 with Router ID 172.16.8.1
Neighbors
Area 0.0.0.1 interface 172.16.8.1(GigabitEthernet0/0/0)'s neighbors
Router ID: 172.16.8.2 Address: 172.16.8.2
State: Full Mode:Nbr is Master Priority: 1
DR: 172.16.8.1 BDR: 172.16.8.2 MTU: 0
Dead timer due in 39 sec
Retrans timer interval: 5
Neighbor is up for 00:03:45
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.1 interface 172.16.1.2(GigabitEthernet0/0/2)'s neighbors
Router ID: 172.16.3.1 Address: 172.16.1.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 172.16.1.2 BDR: 172.16.1.1 MTU: 0
Dead timer due in 40 sec
Retrans timer interval: 5
Neighbor is up for 00:05:47
Authentication Sequence: [ 0 ]
使用display ip routing-table Protocol ospf
命令 查看R5路由表中的OSPF路由条目,可以看到,除OSPF区域2内的路由外,相关的路由条目都已经获取到,连接不同区域的路由器称为ABR,即区域边界路由器,该类路由器设备可以同时属于两个以上的区域,但其中至少一个端口必须在骨干区域内。ABR是用来连接骨干区域和非骨干区域的,即可以是物理连接,也可以是逻辑上的连接。
pgp
[AR5]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 6 Routes : 8
OSPF routing table status : <Active>
Destinations : 6 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
172.16.2.0/30 OSPF 10 2 D 172.16.1.1 GigabitEthernet0/0/2
OSPF 10 2 D 172.16.8.2 GigabitEthernet0/0/0
172.16.3.0/30 OSPF 10 2 D 172.16.1.1 GigabitEthernet0/0/2
172.16.4.0/30 OSPF 10 3 D 172.16.1.1 GigabitEthernet0/0/2
OSPF 10 3 D 172.16.8.2 GigabitEthernet0/0/0
172.16.7.0/30 OSPF 10 2 D 172.16.8.2 GigabitEthernet0/0/0
192.168.30.0/24 OSPF 10 2 D 172.16.8.2 GigabitEthernet0/0/0
192.168.40.0/24 OSPF 10 3 D 172.16.8.2 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes :
使用display ospf lsdb
命令查看R5的OSPF链路状态数据库信息,可以看到关于其他区域的路由条目都是通过sum-net这类lsa获得,所以不参与本区域的SPF算法运算的。
pgp
[AR5]display ospf lsdb
OSPF Process 1 with Router ID 172.16.8.1
Link State Database
Area: 0.0.0.1
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 172.16.3.1 172.16.3.1 1349 36 80000003 1
Router 172.16.8.2 172.16.8.2 1227 36 80000003 1
Router 172.16.8.1 172.16.8.1 1219 60 8000000C 1
Network 172.16.1.2 172.16.8.1 1338 32 80000002 0
Network 172.16.8.1 172.16.8.1 1219 32 80000002 0
Sum-Net 172.16.3.0 172.16.3.1 1350 28 80000001 1
Sum-Net 172.16.3.0 172.16.8.2 1231 28 80000001 2
Sum-Net 172.16.2.0 172.16.3.1 1350 28 80000001 1
Sum-Net 172.16.2.0 172.16.8.2 1231 28 80000001 1
Sum-Net 192.168.30.0 172.16.3.1 1350 28 80000001 2
Sum-Net 192.168.30.0 172.16.8.2 1231 28 80000001 1
Sum-Net 172.16.7.0 172.16.3.1 1350 28 80000001 2
Sum-Net 172.16.7.0 172.16.8.2 1231 28 80000001 1
Sum-Net 172.16.4.0 172.16.3.1 1350 28 80000001 2
Sum-Net 172.16.4.0 172.16.8.2 1231 28 80000001 2
Sum-Net 192.168.40.0 172.16.3.1 1350 28 80000001 3
Sum-Net 192.168.40.0 172.16.8.2 1231 28 80000001 2
对公司另一个分部B的路由器也做相同的配置。
erlang
[AR6]ospf 1
[AR6-ospf-1]area 2
[AR6-ospf-1-area-0.0.0.2]network 172.16.5.0 0.0.0.3
[AR6-ospf-1-area-0.0.0.2]network 172.16.6.0 0.0.0.3
[AR6-ospf-1-area-0.0.0.2]network 192.168.20.0 0.0.0.255
[AR2]ospf 1
[AR2-ospf-1]area 2
[AR2-ospf-1-area-0.0.0.2]network 172.16.5.0 0.0.0.3
[AR4]ospf 1
[AR4-ospf-1]area 2
[AR4-ospf-1-area-0.0.0.2]network 172.16.6.0 0.0.0.3
配置完成查看R6的路由条目,并测试分支A和分支B的连通性。
pgp
[AR6]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 9 Routes : 12
OSPF routing table status : <Active>
Destinations : 9 Routes : 12
Destination/Mask Proto Pre Cost Flags NextHop Interface
172.16.1.0/30 OSPF 10 3 D 172.16.5.2 GigabitEthernet0/0/2
172.16.2.0/30 OSPF 10 3 D 172.16.5.2 GigabitEthernet0/0/2
OSPF 10 3 D 172.16.6.1 GigabitEthernet0/0/0
172.16.3.0/30 OSPF 10 2 D 172.16.5.2 GigabitEthernet0/0/2
172.16.4.0/30 OSPF 10 2 D 172.16.5.2 GigabitEthernet0/0/2
OSPF 10 2 D 172.16.6.1 GigabitEthernet0/0/0
172.16.7.0/30 OSPF 10 2 D 172.16.6.1 GigabitEthernet0/0/0
172.16.8.0/30 OSPF 10 3 D 172.16.6.1 GigabitEthernet0/0/0
192.168.10.0/24 OSPF 10 4 D 172.16.5.2 GigabitEthernet0/0/2
OSPF 10 4 D 172.16.6.1 GigabitEthernet0/0/0
192.168.30.0/24 OSPF 10 3 D 172.16.6.1 GigabitEthernet0/0/0
192.168.40.0/24 OSPF 10 2 D 172.16.6.1 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
PC1>ping 192.168.20.1
Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.20.1: bytes=32 seq=2 ttl=124 time=31 ms
From 192.168.20.1: bytes=32 seq=3 ttl=124 time=32 ms
From 192.168.20.1: bytes=32 seq=4 ttl=124 time=31 ms
From 192.168.20.1: bytes=32 seq=5 ttl=124 time=31 ms
--- 192.168.20.1 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/31/32 ms