实验介绍
开放式最短路径优先 OSPF(Open Shortest Path First)是 IETF 组织开发的一个基于链路状态 的内部网关协议(Interior Gateway Protocol)。目前针对 IPv4 协议使用的是 OSPF Version 2 (RFC2328);OSPF 作为基于链路状态的协议,OSPF 具有以下优点:
实验目的
掌握 OSPF 的基本配置命令。
掌握如何查看 OSPF 的运行状态。
掌握如何通过 Cost 控制 OSPF 的选路。
掌握 OSPF 发布默认路由的方法。
掌握 OSPF 认证配置方法。

OSPF 基本配置
查看 OSPF 状态
查看 IP 路由表中由 OSPF 学习到的路由
配置 OSPF 认证
在 R1 上宣告默认路由
[R1]ospf
[R1-ospf-1]default-route-advertise always
default-route-advertise命令用来将默认路由通告到普通OSPF区域,如果没有配置
always参数,本机路由表中必须有激活的非本OSPF默认路由时才向其他路由器发布默认路
由。本例中,本地路由表中没有默认路由,所以需要增加always参数。通过修改 R1 相应接口的 Cost 值,使得 R1 的 LoopBack0 接口通过 R1->R3->R2 的路径 访问 R2 的 LoopBack0 接口
<R1>display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
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 unassigned down down
LoopBack0 10.0.1.1/32 up up(s)
NULL0 unassigned up up(s)
<R2>display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 10.0.12.2/24 up up
GigabitEthernet0/0/1 10.0.23.2/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 10.0.1.2/32 up up(s)
NULL0 unassigned up up(s)
<R3>display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 10.0.23.3/24 up up
GigabitEthernet0/0/1 10.0.13.3/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 10.0.1.3/32 up up(s)
NULL0 unassigned up up(s) R1:
[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 10.0.12.1 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.0.13.1 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.0.1.1 0.0.0.0
network network-address wildcard-mask用来指定运行OSPF协议的接口。满足下面两个
条件,OSPF协议才能在接口上运行:
1. 接口的IP地址掩码长度≥network命令中的掩码长度。OSPF使用反掩码,例如0.0.0.255
表示掩码长度24位。
2. 接口的IP地址必须在network命令指定的网段范围之内。
R2:
[R2]ospf
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.12.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.23.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.1.2 0.0.0.0
当network命令配置的wildcard-mask为全0时,如果接口的IP地址与network-address配置
的IP地址相同,则此接口也会运行OSPF协议。
R3:
[R3]ospf
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.13.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.23.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.1.3 0.0.0.0<R1>display ospf peer
OSPF Process 1 with Router ID 10.0.1.1
Neighbors
Area 0.0.0.0 interface 10.0.12.1(GigabitEthernet0/0/0)'s neighbors
Router ID: 10.0.1.2 Address: 10.0.12.2
State: Full Mode:Nbr is Master Priority: 1
DR: 10.0.12.1 BDR: 10.0.12.2 MTU: 0
Dead timer due in 33 sec
Retrans timer interval: 5
Neighbor is up for 01:00:01
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 10.0.13.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 10.0.1.3 Address: 10.0.13.3
State: Full Mode:Nbr is Master Priority: 1
DR: 10.0.13.1 BDR: 10.0.13.3 MTU: 0
Dead timer due in 36 sec
Retrans timer interval: 5
Neighbor is up for 00:58:52
Authentication Sequence: [ 0 ]
<R1>display 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
10.0.1.2/32 OSPF 10 1 D 10.0.12.2 GigabitEthernet
0/0/0
10.0.1.3/32 OSPF 10 1 D 10.0.13.3 GigabitEthernet
0/0/1
10.0.23.0/24 OSPF 10 2 D 10.0.12.2 GigabitEthernet
0/0/0
OSPF 10 2 D 10.0.13.3 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
R1:
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123
[R1-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123
R2:
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123
[R1-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123
R3:
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123
[R1-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/0]ospf authentication-mode md5 1 cipher huawei@123[R1]interface GigabitEthernet0/0/0
[R1- GigabitEthernet0/0/0]ospf cost 10
[R1]tracert -a 10.0.1.1 10.0.1.2
traceroute to 10.0.1.2(10.0.1.2), max hops: 30 ,packet length: 40,press CTRL_C
to break
1 10.0.13.3 30 ms 20 ms 10 ms
2 10.0.23.2 20 ms 20 ms 30 ms