在OSPF单区域中,每台路由器都需要收集其它所有路由器的链路状态信息。如网络规模不断扩大,链路状态信息会随之不断增多,这将使得单台路由器上链路状态数据库非常庞大,加重负担,也不便于维护管理。因此,OSPF协议可以把整个自治系统划分为不同的区域(Area),相当与一个国家下面划分为不同的省份来管理。 链路状态信息只在区域内部泛洪,区域之间传递的只是路由条目非链路状态信息,因此大大减小了路由器的负担。当一台路由器接口(链路)属于不同区域时称它为区域边界路由器(Area Border Router,ABR),负责传递区域间路由信息。区域间的路由信息传递类似距离矢量算法,为了防止区域间产生环路,所有非骨干区域之间的路由信息必须经过骨干区域,也就是说非骨干区域必须和骨干区域相连,且非骨干区域之间不能直接进行路由信息交互。
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。
R1接口配置: Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.12.1/24 up up GigabitEthernet0/0/1 10.0.13.1/24 up up GigabitEthernet0/0/2 10.0.15.1/24 up up
每一台路由器接口地址,主机号以路由器编号对应配置,不赘述。
ping 10.0.12.2 //测试直连链路的连通信 其余网段省略 PING 10.0.12.2: 56 data bytes, press CTRL_C to break Reply from 10.0.12.2: bytes=56 Sequence=1 ttl=255 time=110 ms Reply from 10.0.12.2: bytes=56 Sequence=2 ttl=255 time=20 ms Reply from 10.0.12.2: bytes=56 Sequence=3 ttl=255 time=20 ms Reply from 10.0.12.2: bytes=56 Sequence=4 ttl=255 time=20 ms Reply from 10.0.12.2: bytes=56 Sequence=5 ttl=255 time=20 ms
— 10.0.12.2 ping statistics — 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/38/110 ms
ping 10.0.13.3 PING 10.0.13.3: 56 data bytes, press CTRL_C to break Reply from 10.0.13.3: bytes=56 Sequence=1 ttl=255 time=90 ms Reply from 10.0.13.3: bytes=56 Sequence=2 ttl=255 time=20 ms Reply from 10.0.13.3: bytes=56 Sequence=3 ttl=255 time=20 ms Reply from 10.0.13.3: bytes=56 Sequence=4 ttl=255 time=20 ms Reply from 10.0.13.3: bytes=56 Sequence=5 ttl=255 time=40 ms
— 10.0.13.3 ping statistics — 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/38/90 ms
ping 10.0.15.5 PING 10.0.15.5: 56 data bytes, press CTRL_C to break Reply from 10.0.15.5: bytes=56 Sequence=1 ttl=255 time=110 ms Reply from 10.0.15.5: bytes=56 Sequence=2 ttl=255 time=20 ms Reply from 10.0.15.5: bytes=56 Sequence=3 ttl=255 time=20 ms Reply from 10.0.15.5: bytes=56 Sequence=4 ttl=255 time=30 ms Reply from 10.0.15.5: bytes=56 Sequence=5 ttl=255 time=30 ms
在公司总部路由器R1,R2,R3,R4上创建OSPF进程,在骨干区域0的视图下通告各网段 [R1]ospf 1 [R1-ospf-1]area 0 [R1-ospf-1-area-0.0.0.0]network 10.0.12.0 0.0.0.255 [R1-ospf-1-area-0.0.0.0]network 10.0.13.0 0.0.0.255
[R2]ospf 1 [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]network 10.0.12.0 0.0.0.255 [R2-ospf-1-area-0.0.0.0]network 10.0.24.0 0.0.0.255
[R3]ospf 1 [R3-ospf-1]area 0 [R3-ospf-1-area-0.0.0.0]network 10.0.34.0 0.0.0.255 [R3-ospf-1-area-0.0.0.0]network 10.0.3.0 0.0.0.255 [R3-ospf-1-area-0.0.0.0]network 10.0.13.0 0.0.0.255
[R4]ospf 1 [R4-ospf-1]area 0 [R4-ospf-1-area-0.0.0.0]network 10.0.34.0 0.0.0.255 [R4-ospf-1-area-0.0.0.0]network 10.0.24.0 0.0.0.255 [R4-ospf-1-area-0.0.0.0]network 10.0.4.0 0.0.0.255
测试总部两台PC间的连通性,PC-3 ping PC-4。正常通信,骨干路由器配置完成。 PC>ping 10.0.4.1
Ping 10.0.4.1: 32 data bytes, Press Ctrl_C to break From 10.0.4.1: bytes=32 seq=1 ttl=126 time=16 ms From 10.0.4.1: bytes=32 seq=2 ttl=126 time=16 ms From 10.0.4.1: bytes=32 seq=3 ttl=126 time=15 ms From 10.0.4.1: bytes=32 seq=4 ttl=126 time=32 ms From 10.0.4.1: bytes=32 seq=5 ttl=126 time=31 ms
[R5]ospf 1 //分支路由器R5上创建OSPF进程,区域为1,通告分支A的相应网段 [R5-ospf-1]area 1 [R5-ospf-1-area-0.0.0.1]network 10.0.15.0 0.0.0.255 [R5-ospf-1-area-0.0.0.1]network 10.0.35.0 0.0.0.255 [R5-ospf-1-area-0.0.0.1]network 10.0.1.0 0.0.0.255
[R1]ospf 1 //R1,R3上创建并进入区域1视图,将与R5相连的接口进行通告 [R1-ospf-1]area 1 [R1-ospf-1-area-0.0.0.1]network 10.0.15.0 0.0.0.255
[R3]ospf 1 [R3-ospf-1]area 1 [R3-ospf-1-area-0.0.0.1]network 10.0.35.0 0.0.0.255
[R5]dis ospf peer //查看邻居状态
OSPF Process 1 with Router ID 10.0.15.5 Neighbors
Area 0.0.0.1 interface 10.0.15.5(GigabitEthernet0/0/0)'s neighbors Router ID: 10.0.12.1 Address: 10.0.15.1 State: Full Mode:Nbr is Slave Priority: 1 //R5与R1邻居关系建立正常,状态为Full DR: 10.0.15.5 BDR: 10.0.15.1 MTU: 0 Dead timer due in 39 sec Retrans timer interval: 5 Neighbor is up for 00:06:19 Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.1 interface 10.0.35.5(GigabitEthernet0/0/1)'s neighbors Router ID: 10.0.34.3 Address: 10.0.35.3 State: Full Mode:Nbr is Master Priority: 1 //R5与R3邻据关系建立正常,状态为Full DR: 10.0.35.5 BDR: 10.0.35.3 MTU: 0 Dead timer due in 27 sec Retrans timer interval: 5 Neighbor is up for 00:03:38 Authentication Sequence: [ 0 ]
[R5]dis ip routing-table protocol ospf //查看OSPF路由表条目 Route Flags: R - relay, D - download to fib
Public routing table : OSPF Destinations : 6 Routes : 8
OSPF routing table status : Destinations : 6 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.3.0/24 OSPF 10 2 D 10.0.35.3 GigabitEthernet0/0/1 10.0.4.0/24 OSPF 10 3 D 10.0.35.3 GigabitEthernet0/0/1 10.0.12.0/24 OSPF 10 2 D 10.0.15.1 GigabitEthernet0/0/0 10.0.13.0/24 OSPF 10 2 D 10.0.15.1 GigabitEthernet0/0/0 OSPF 10 2 D 10.0.35.3 GigabitEthernet0/0/1 10.0.24.0/24 OSPF 10 3 D 10.0.15.1 GigabitEthernet0/0/0 OSPF 10 3 D 10.0.35.3 GigabitEthernet0/0/1 10.0.34.0/24 OSPF 10 2 D 10.0.35.3 GigabitEthernet0/0/1
OSPF routing table status : Destinations : 0 Routes : 0 除了OSPF区域2的路由外,相关路由条目都已获得。在拓扑中,R1,R3两台连接不同区域的路由器称为ABR,即区域边界路由器。该类路由器设备可以同时属于两个以上的区域,但其中至少一个端口必须在骨干区域内。ABR是用来连接骨干区域和非骨干区域的,其与骨干区域之间既可以是物理连接,也可以是逻辑上的连接。
[R5]dis ospf lsdb //查看R5的OSPF链路状态数据库信息
OSPF Process 1 with Router ID 10.0.15.5 Link State Database Area: 0.0.0.1 Type LinkState ID AdvRouter Age Len Sequence Metric Router 10.0.12.1 10.0.12.1 171 36 80000004 1 Router 10.0.34.3 10.0.34.3 174 36 80000004 1 Router 10.0.15.5 10.0.15.5 19 60 8000000B 1 Network 10.0.35.3 10.0.34.3 174 32 80000001 0 Network 10.0.15.5 10.0.15.5 161 32 80000002 0 Sum-Net 10.0.34.0 10.0.34.3 217 28 80000001 1 Sum-Net 10.0.34.0 10.0.12.1 170 28 80000001 2 Sum-Net 10.0.13.0 10.0.34.3 208 28 80000001 1 Sum-Net 10.0.13.0 10.0.12.1 209 28 80000001 1 Sum-Net 10.0.24.0 10.0.34.3 163 28 80000002 2 Sum-Net 10.0.24.0 10.0.12.1 157 28 80000003 2 Sum-Net 10.0.12.0 10.0.12.1 201 28 80000001 1 Sum-Net 10.0.12.0 10.0.34.3 156 28 80000003 2 Sum-Net 10.0.3.0 10.0.34.3 217 28 80000001 1 Sum-Net 10.0.3.0 10.0.12.1 170 28 80000001 2 Sum-Net 10.0.4.0 10.0.34.3 185 28 80000001 2 Sum-Net 10.0.4.0 10.0.12.1 170 28 80000001 3 关于其它区域的路由条目都是通过“Sum-Net”这类LSA获得,而这类LSA是不参与本区域的SPF算法的。
[R6]ospf 1 //分支路由器B上创建OSPF进程,区域为2,通告B的相应网段 [R6-ospf-1]area 2 [R6-ospf-1-area-0.0.0.2]network 10.0.26.0 0.0.0.255 [R6-ospf-1-area-0.0.0.2]network 10.0.2.0 0.0.0.255 [R6-ospf-1-area-0.0.0.2]network 10.0.46.0 0.0.0.255
[R2]ospf 1 //与R6相连的接口进行通告 [R2-ospf-1]area 2 [R2-ospf-1-area-0.0.0.2]network 10.0.26.0 0.0.0.255
[R4]ospf 1 [R4-ospf-1]area 2 [R4-ospf-1-area-0.0.0.2]network 10.0.46.0 0.0.0.255
[R6]dis ip routing-table protocol ospf //查看R6的OSPF路由条目 Route Flags: R - relay, D - download to fib
Public routing table : OSPF Destinations : 9 Routes : 12
OSPF routing table status : Destinations : 9 Routes : 12
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.0/24 OSPF 10 4 D 10.0.26.2 GigabitEthernet0/0/0 OSPF 10 4 D 10.0.46.4 GigabitEthernet0/0/1 10.0.3.0/24 OSPF 10 3 D 10.0.46.4 GigabitEthernet0/0/1 10.0.4.0/24 OSPF 10 2 D 10.0.46.4 GigabitEthernet0/0/1 10.0.12.0/24 OSPF 10 2 D 10.0.26.2 GigabitEthernet0/0/0 10.0.13.0/24 OSPF 10 3 D 10.0.26.2 GigabitEthernet0/0/0 OSPF 10 3 D 10.0.46.4 GigabitEthernet0/0/1 10.0.15.0/24 OSPF 10 3 D 10.0.26.2 GigabitEthernet0/0/0 10.0.24.0/24 OSPF 10 2 D 10.0.26.2 GigabitEthernet0/0/0 OSPF 10 2 D 10.0.46.4 GigabitEthernet0/0/1 10.0.34.0/24 OSPF 10 2 D 10.0.46.4 GigabitEthernet0/0/1 10.0.35.0/24 OSPF 10 3 D 10.0.46.4 GigabitEthernet0/0/1
OSPF routing table status : Destinations : 0 Routes : 0 //接收到所有OSPF路由信息
PC>ping 10.0.1.1 //分支B ping 分支A,PC2 ping PC1 正常通信
Ping 10.0.1.1: 32 data bytes, Press Ctrl_C to break From 10.0.1.1: bytes=32 seq=1 ttl=124 time=15 ms From 10.0.1.1: bytes=32 seq=2 ttl=124 time=47 ms From 10.0.1.1: bytes=32 seq=3 ttl=124 time=32 ms From 10.0.1.1: bytes=32 seq=4 ttl=124 time=46 ms From 10.0.1.1: bytes=32 seq=5 ttl=124 time=32 ms