OSPF单区域配置
原理概述:
OSPF (Open Shortest Path First.开放式最短路径优先协议)
版本:
第一版OSPF V1
第二版OSPF V2 现在IPv4网络中使用的都是OSPFv2
OSPF是基于链路状态的协议
优点:收敛快、路由无环、扩展性好。
运行算法:SPF
OSPF区域划分:
从逻辑上将路由器划分为不同的组,每个组用区域号(Area ID)来标识。一个网段(链路)只属于一个区域,区域0为骨干区域。
骨干区域负责在非骨干区域间发布区域间的路由信息,在一个OSPF区域中有却只有一个骨干区域。
实验模拟企业网络场景
该公司有三大办公区,A、B、C
每个公共区用一台路由器,三台路由器互相连接,三台路由器运行OSPF协议,且都为骨干区域。
部署单区域OSPF网络
基本配置:
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 172.16.1.1 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 172.16.10.2 24
[R1-GigabitEthernet0/0/1]int g0/0/2
[R1-GigabitEthernet0/0/2]ip add 172.16.20.1 24
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 172.16.30.1 24
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 172.16.10.1 24
[R2-GigabitEthernet0/0/1]int g0/0/2
[R2-GigabitEthernet0/0/2]ip add 172.16.2.254 24
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 172.16.30.2 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 172.16.3.1 24
[R1-GigabitEthernet0/0/1]int g0/0/2
[R1-GigabitEthernet0/0/2]ip add 172.16.20.2 24
OSPF配置:R1配置
<Huawei>sys
[Huawei]sysname R1
[R1]ospf 1 (创建进程号为1 OSPF实例)
[R1-ospf-1]area 0 (配置骨干区域)
[R1-ospf-1-area-0.0.0.0]net 172.16.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]net 172.16.10.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]net 172.16.20.0 0.0.0.2.255
R2配置
<Huawei>sys
[Huawei]sysname R2
[R2]ospf 1 (创建进程号为1 OSPF实例)
[R2-ospf-1]area 0 (配置骨干区域)
[R2-ospf-1-area-0.0.0.0]net 172.16.2.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]net 172.16.10.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]net 172.16.30.0 0.0.0.2.255
R3配置
<Huawei>sys
[Huawei]sysname R3
[R3]ospf 1 (创建进程号为1 OSPF实例)
[R3-ospf-1]area 0 (配置骨干区域)
[R3-ospf-1-area-0.0.0.0]net 172.16.3.0 0.0.0.255 (通告所属网段)
[R3-ospf-1-area-0.0.0.0]net 172.16.20.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]net 172.16.30.0 0.0.0.2.255
验证:通过命令dis ospf peer 查看ospf邻居状态
<R3>dis ospf peer
OSPF Process 1 with Router ID 172.16.20.2
Neighbors
Area 0.0.0.0 interface 172.16.20.2(GigabitEthernet0/0/2)'s neighbors
Router ID: 172.16.10.2 Address: 172.16.20.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 172.16.20.1 BDR: 172.16.20.2 MTU: 0
Dead timer due in 38 sec
Retrans timer interval: 0
Neighbor is up for 00:02:23
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 172.16.30.2(GigabitEthernet0/0/0)'s neighbors
Router ID: 172.16.30.1 Address: 172.16.30.1
State: Full Mode:Nbr is Master Priority: 1
DR: 172.16.30.1 BDR: 172.16.30.2 MTU: 0
Dead timer due in 33 sec
Retrans timer interval: 5
Neighbor is up for 00:02:08
Authentication Sequence: [ 0 ]
查看路由表:dis ospf routing-table protocol ospf 查看R1上OSPF路由表
<R1>dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 4
OSPF routing table status : <Active>
Destinations : 3 Routes : 4
Destination/Mask Proto Pre Cost Flags NextHop Interface
172.16.2.0/24 OSPF 10 2 D 172.16.10.1 GigabitEthernet
0/0/1
172.16.3.0/24 OSPF 10 2 D 172.16.20.2 GigabitEthernet
0/0/2
172.16.30.0/24 OSPF 10 2 D 172.16.10.1 GigabitEthernet
0/0/1
OSPF 10 2 D 172.16.20.2 GigabitEthernet
0/0/2
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0