华为实验之OSPF协议
实验目的
掌握单区域 OSPF 的配置方法
掌握 OSPF 区域认证的配置方法
修 改 OSPF 的 Loopback 的 32 位主机路由
掌握对 OSPF 接口代价值进行修改的方法
掌握 OSPF 中 Silent-interface 的配置方法
掌握使用 Display 查看 OSPF 各种状态的方法
掌握使用 Debug 命令查看 OSPF 邻接关系和进行故障排除的方法
单区域的 OSPF
1:首先配置 IP 地址,这里不再演示,请参考上面的实验。
2:配置单区域(area0 )的 OSPF
[R1]ospf 1 router-id 11.1.1.1 //配置 OSPF 的进程号以及 route-ID
[R1-ospf-1]area 0 //进入到区域 0 里面。
[R1-ospf-1-area-0.0.0.0]network 12.1.1.1 0.0.0.0 //精确宣告一个 IP 地址。
[R1-ospf-1-area-0.0.0.0]network 11.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher yeslab // 基于区域的
MD5 认证
在 R2 上配置
[R2]ospf 1 router-id 22.1.1.1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 23.1.1.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 22.1.1.1 0.0.0.0
[R2-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher yeslab
在 R3 上去配置
[R3]ospf 1 router-id 33.1.1.1
[R3-ospf-1-area-0.0.0.0]network 33.1.1.1 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 23.1.1.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher yeslab
配置好以后去查看路由表:
[R1]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
22.1.1.1/32 OSPF 10 1 D 12.1.1.2 Ethernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
33.1.1.1/32 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
在 R2 上查看:
[R2]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
11.1.1.1/32 OSPF 10 1 D 12.1.1.1 Ethernet0/0/0
33.1.1.1/32 OSPF 10 1 D 23.1.1.3 Ethernet0/0/1
在 R3 上查看:
[R3]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
11.1.1.1/32 OSPF 10 2 D 23.1.1.2 Ethernet0/0/0
12.1.1.0/24 OSPF 10 2 D 23.1.1.2 Ethernet0/0/0
22.1.1.1/32 OSPF 10 1 D 23.1.1.2 Ethernet0/0/0
使用 display ospf brief 命令查看 OSPF 运行的基本信息。
[R1]display ospf brief
————省略一部分显示————
Area: 0.0.0.0 (MPLS TE not enabled)
Authtype: MD5 Area flag: Normal //区域 0 的认证类型
SPF scheduled Count: 8
ExChange/Loading Neighbors: 0
Router ID conflict state: Normal
Interface: 12.1.1.1 (Ethernet0/0/0) //接口的的开销,状态,接口网络类型
Cost: 1 State: DR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 12.1.1.1
Backup Designated Router: 12.1.1.2
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
Interface: 11.1.1.1 (LoopBack1)
Cost: 0 State: P-2-P Type: P2P MTU: 1500
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
再去查看邻居关系:
[R1]display ospf peer brief
OSPF Process 1 with Router ID 11.1.1.1
Peer Statistic Information
Area Id Interface Neighbor id State
0.0.0.0 Ethernet0/0/0 22.1.1.1 Full
//以上表示 R1 上能看到 R2 这个邻居,有邻居的 route-ID, 状态,本地接口和区域等
去查看 LSDB 表项:
[R1]display ospf lsdb
OSPF Process 1 with Router ID 11.1.1.1
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 33.1.1.1 33.1.1.1 668 48 80000004 0
Router 22.1.1.1 22.1.1.1 668 60 80000009 1
Router 11.1.1.1 11.1.1.1 726 48 80000006 1
Network 23.1.1.2 22.1.1.1 668 32 80000001 0
Network 12.1.1.1 11.1.1.1 726 32 80000001 0
//以上输出表示能看到一类的和 2 类的 LSA,与 CISCO 没有区别。
再去查看一条详细的内容:
[R1]display ospf lsdb router 33.1.1.1
OSPF Process 1 with Router ID 11.1.1.1
Area: 0.0.0.0
Link State Database
Type : Router
Ls id : 33.1.1.1
Adv rtr : 33.1.1.1
Ls age : 694
Len : 48
Options : E
seq# : 80000004
chksum : 0xc9d2
Link count: 2Link ID: 33.1.1.1
Data : 255.255.255.255
Link Type: StubNet
Metric : 0
Priority : Medium
Link ID: 23.1.1.2
Data : 23.1.1.3
Link Type: TransNet
Metric : 1
//以上输出表示 R3 通告了二项信息,一个是回环回,一个是连接 R2 的接口。具体理解请看 OSPF 的讲解视频。
控制 DR/BDR 的举 ,观察邻居状态变迁
实验步骤
接着上面的实验:
先去查看 R1 与 R2 之间谁是 DR
[R1]display ospf peer
OSPF Process 1 with Router ID 11.1.1.1
Neighbors
Area 0.0.0.0 interface 12.1.1.1(Ethernet0/0/0)'s neighbors
Router ID: 22.1.1.1 Address: 12.1.1.2
State: Full Mode:Nbr is Master Priority: 1
DR: 12.1.1.1 BDR: 12.1.1.2 MTU: 0
Dead timer due in 37 sec
Retrans timer interval: 5
Neighbor is up for 00:28:53
Authentication Sequence: [ 2472]
以上表示 R1 为 DR。但在这里 每个人得到的实验结果会不一样,因为 DR/BDR 的选
举是非抢占的。
接下来修改 R1 的接口优先集。
[R1-Ethernet0/0/0]ospf dr-priority 10
然后 shutdown 二边的接口,打开 debug,观察 OSPF 的邻居建立过程。
debugging ospf 1 event
[R1]info-center enable
Undo shutdown 接口,观察以下信息
May 16 2013 17:43:39-08:00 R1 %%01PHY/1/PHY(l)[0]: Ethernet0/0/0: change status to up
May 16 2013 17:43:39-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface Ethernet0/0/0 has entered the
UP state.
May 16 2013 17:43:39-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[2]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=Init)
May 16 2013 17:43:48-08:00 R1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.191.3.1 configurations have been changed.
The current change number is 23, the change loop count is 0, and the maximum number of records is 4095.
May 16 2013 17:43:58-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[3]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=2Way)
May 16 2013 17:44:20-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=AdjOk?, NeighborPreviousState=2Way, NeighborCurrentState=ExStart)
May 16 2013 17:44:25-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=NegotiationDone, NeighborPreviousState=ExStart, NeighborCurrentState=Exchange)
May 16 2013 17:44:25-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[6]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=ExchangeDone, NeighborPreviousState=Exchange, NeighborCurrentState=Loading)
May 16 2013 17:44:25-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[7]:Neighbor changes event: neighbor status changed. (ProcessId=1,
NeighborAddress=12.1.1.2, NeighborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full)
再去 R2 上查看邻居信息:
[R2]display ospf peer
OSPF Process 1 with Router ID 22.1.1.1
Neighbors
Area 0.0.0.0 interface 12.1.1.2(Ethernet0/0/0)'s neighbors
Router ID: 11.1.1.1 Address: 12.1.1.1
State: Full Mode:Nbr is Slave Priority: 10
DR: 12.1.1.1 BDR: 12.1.1.2 MTU: 0
Dead timer due in 37 sec
Retrans timer interval: 5
Neighbor is up for 00:02:36
Authentication Sequence: [ 8265]
//以上表示 R1 的优先集己经被修改为 10 了。
配置接口的网络类型
实验步骤
先去查看 R1 的路由表,将会发现 R1 上收到的 R2,R3 的环回口路由都是 32 位的主机路由:
[R1]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
22.1.1.1/32 OSPF 10 1 D 12.1.1.2 Ethernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
33.1.1.1/32 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
再去查看 R2 上环回口的网络类型。
[R2]display ospf interface LoopBack 1
OSPF Process 1 with Router ID 22.1.1.1
Interfaces
Interface: 22.1.1.1 (LoopBack1)
Cost: 0 State: P-2-P Type: P2P MTU: 1500
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
//以上输出表示类型是 P2P,这些与 CISCO 是不一样的。CISCO 的回环口是 loopback,
但是结局都是一样的,都是似送 32 位主机路由。
修改接口的网络类型如下:
[R2]interface LoopBack 1
[R2-LoopBack1]ospf network-type broadcast
修改后再去 R1 查看结果:
[R1]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
22.1.1.0/24 OSPF 10 1 D 12.1.1.2 Ethernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
33.1.1.1/32 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
//以上表示 R1 收到 R2 的路由是 24 位的了。
修改 OSPF 接口的 COST
实验步骤
通以上面的实验输出可以发现,LOOPBACK 口的 COST 值为 0,接下来把 R2 的环回口
COST 值修改为 99,再去 R1 看结果。
[R2]interface loop 1
[R2-LoopBack1]ospf cost 99
[R1]display ip routing protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
22.1.1.0/24 OSPF 10 100 D 12.1.1.2 Ethernet0/0/0
23.1.1.0/24 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
33.1.1.1/32 OSPF 10 2 D 12.1.1.2 Ethernet0/0/0
配置 OSPF 的被动接口
实验步骤
OSPF 的被动接口与 RI