企业网主流动态路由OSPF协议报文 ,及基本配置,一分钟了解下

2024-03-18 01:13:43

一、OSPF简介

OSPF(Open Shortest Path First,开放最短路径优先)是 IETF(Internet Engineering Task Force,

互联网工程任务组)组织开发的一个基于链路状态的内部网关协议。

二、OSPF的特点

OSPF 具有如下特点:

1、适应范围广:支持各种规模的网络,最多可支持几百台路由器。

2、快速收敛:在网络的拓扑结构发生变化后立即发送更新报文,使这一变化在自治系统中同步。

3、 无自环:由于 OSPF 根据收集到的链路状态用最短路径树算法计算路由,从算法本身保证了

不会生成自环路由。

4、区域划分:允许自治系统的网络被划分成区域来管理。路由器链路状态数据库的减小降低了

内存的消耗和 CPU 的负担;区域间传送路由信息的减少降低了网络带宽的占用。

5、等价路由:支持到同一目的地址的多条等价路由。

6、路由分级:使用 4 类不同的路由,按优先顺序来说分别是:区域内路由、区域间路由、第一

类外部路由、第二类外部路由。

7、支持验证:支持基于区域和接口的报文验证,以保证报文交互和路由计算的安全性。

8、 组播发送:在某些类型的链路上以组播地址发送协议报文,减少对其他设备的干扰。

三、OSPF报文类型

OSPF 协议报文直接封装为 IP 报文,协议号为 89。

OSPF 有五种类型的协议报文:

1、 Hello 报文:周期性发送,用来发现和维持 OSPF 邻居关系,以及进行 DR(Designated

Router,指定路由器)/BDR(Backup Designated Router,备份指定路由器)的选举。

2、DD(Database Description,数据库描述)报文:描述了本地 LSDB(Link State DataBase,

链路状态数据库)中每一条 LSA(Link State Advertisement,链路状态通告)的摘要信息,

用于两台路由器进行数据库同步。

3、 LSR(Link State Request,链路状态请求)报文:向对方请求所需的 LSA。两台路由器互相

交换 DD 报文之后,得知对端的路由器有哪些 LSA 是本地的 LSDB 所缺少的,这时需要发送

LSR 报文向对方请求所需的 LSA。

4、 LSU(Link State Update,链路状态更新)报文:向对方发送其所需要的 LSA。

5、LSACK(Link State Acknowledgment,链路状态确认)报文:用来对收到的 LSA 进行确认。

四、基本OSPF配置

1. 组网需求

A、 所有的交换机都运行 OSPF,并将整个自治系统划分为 3 个区域。

B、 其中 Switch A 和 Switch B 作为 ABR 来转发区域之间的路由。

C、 配置完成后,每台交换机都应学到 AS 内的到所有网段的路由

2. 组网图

3. 配置步骤(IP地址忽略)

配置 OSPF 基本配置

1)、 配置 Switch A

system-view

[SwitchA] router id 10.2.1.1

[SwitchA] ospf

[SwitchA-ospf-1] area 0

[SwitchA-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255

[SwitchA-ospf-1-area-0.0.0.0] quit

[SwitchA-ospf-1] area 1

[SwitchA-ospf-1-area-0.0.0.1] network 10.2.1.0 0.0.0.255

[SwitchA-ospf-1-area-0.0.0.1] quit

[SwitchA-ospf-1] quit

2)、 配置 Switch B

system-view

[SwitchB] router id 10.3.1.1

[SwitchB] ospf

[SwitchB-ospf-1] area 0

[SwitchB-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255

[SwitchB-ospf-1-area-0.0.0.0] quit

[SwitchB-ospf-1] area 2

[SwitchB-ospf-1-area-0.0.0.2] network 10.3.1.0 0.0.0.255

[SwitchB-ospf-1-area-0.0.0.2] quit

[SwitchB-ospf-1] quit

3)、配置 Switch C

system-view

[SwitchC] router id 10.4.1.1

[SwitchC] ospf

[SwitchC-ospf-1] area 1

[SwitchC-ospf-1-area-0.0.0.1] network 10.2.1.0 0.0.0.255

[SwitchC-ospf-1-area-0.0.0.1] network 10.4.1.0 0.0.0.255

[SwitchC-ospf-1-area-0.0.0.1] quit

[SwitchC-ospf-1] quit

4)、 配置 Switch D

system-view

[SwitchD] router id 10.5.1.1

[SwitchD] ospf

[SwitchD-ospf-1] area 2

[SwitchD-ospf-1-area-0.0.0.2] network 10.3.1.0 0.0.0.255

[SwitchD-ospf-1-area-0.0.0.2] network 10.5.1.0 0.0.0.255

[SwitchD-ospf-1-area-0.0.0.2] quit

[SwitchD-ospf-1] quit

4. 验证配置

1)、 查看 Switch A 的 OSPF 邻居

[SwitchA] display ospf peer verbose

OSPF Process 1 with Router ID 10.2.1.1

Neighbors

Area 0.0.0.0 interface 10.1.1.1(Vlan-interface100)'s neighbors

Router ID: 10.3.1.1 Address: 10.1.1.2 GR State: Normal

State: Full Mode: Nbr is Master Priority: 1

DR: 10.1.1.1 BDR: 10.1.1.2 MTU: 0

Options is 0x02 (-|-|-|-|-|-|E|-)

Dead timer due in 37 sec

Neighbor is up for 06:03:59

Authentication Sequence: [ 0 ]

Neighbor state change count: 5

Area 0.0.0.1 interface 10.2.1.1(Vlan-interface200)'s neighbors

Router ID: 10.4.1.1 Address: 10.2.1.2 GR State: Normal

State: Full Mode: Nbr is Master Priority: 1

DR: 10.2.1.1 BDR: 10.2.1.2 MTU: 0

Options is 0x02 (-|-|-|-|-|-|E|-)

Dead timer due in 32 sec

Neighbor is up for 06:03:12

Authentication Sequence: [ 0 ]

Neighbor state change count: 5

2)、查看 Switch A 的 OSPF 路由信息

[SwitchA] display ospf routing

OSPF Process 1 with Router ID 10.2.1.1

Routing Tables

Routing for Network

Destination Cost Type NextHop AdvRouter Area

10.2.1.0/24 1 Transit 10.2.1.1 10.2.1.1 0.0.0.1

10.3.1.0/24 2 Inter 10.1.1.2 10.3.1.1 0.0.0.0

10.4.1.0/24 2 Stub 10.2.1.2 10.4.1.1 0.0.0.1

10.5.1.0/24 3 Inter 10.1.1.2 10.3.1.1 0.0.0.0

10.1.1.0/24 1 Transit 10.1.1.1 10.2.1.1 0.0.0.0

Total Nets: 5

Intra Area: 3 Inter Area: 2 ASE: 0 NSSA: 0

3)、查看 Switch D 的 OSPF 路由信息

[SwitchD] display ospf routing

OSPF Process 1 with Router ID 10.5.1.1

Routing Tables

Routing for Network

Destination Cost Type NextHop AdvRouter Area

10.2.1.0/24 3 Inter 10.3.1.1 10.3.1.1 0.0.0.2

10.3.1.0/24 1 Transit 10.3.1.2 10.3.1.1 0.0.0.2

10.4.1.0/24 4 Inter 10.3.1.1 10.3.1.1 0.0.0.2

10.5.1.0/24 1 Stub 10.5.1.1 10.5.1.1 0.0.0.2

10.1.1.0/24 2 Inter 10.3.1.1 10.3.1.1 0.0.0.2

Total Nets: 5

Intra Area: 2 Inter Area: 3 ASE: 0 NSSA: 0

4)、 在 Switch D 上使用 Ping 进行测试连通性

[SwitchD] ping 10.4.1.1

Ping 10.4.1.1 (10.4.1.1): 56 data bytes, press CTRL_C to break

56 bytes from 10.4.1.1: icmp_seq=0 ttl=253 time=1.549 ms

56 bytes from 10.4.1.1: icmp_seq=1 ttl=253 time=1.539 ms

56 bytes from 10.4.1.1: icmp_seq=2 ttl=253 time=0.779 ms

56 bytes from 10.4.1.1: icmp_seq=3 ttl=253 time=1.702 ms

56 bytes from 10.4.1.1: icmp_seq=4 ttl=253 time=1.471 ms