目录

一、实验目标

二、拓扑图

三、配置基本环境

四、配置OSPF

五、修改·OSPF hello、dead时间参数

七、控制OSPF DR、BDR的选举

八、配置信息


一、实验目标

  • 掌握OSPF 中Router ID 的配置方法
  • 掌握OSPF的配置方法
  • 掌握通过display命令查看OSPF运行状态的方法
  • 掌握使用OSPF发布缺省路由的方法
  • 掌握修改OSPF hello和dead 时间的配置方法
  • 理解多路访问网络中的DR 或 BDR 选举
  • 掌握OSPF路由优先级的修改方法

二、拓扑图

ensp ospf 密码认证 ensp ospf配置_网络协议

三、配置基本环境

R1:

[Huawei]sysname R1
[R1]int g0/0/0 
[R1-GigabitEthernet0/0/0]ip address 192.168.12.1 24
Mar 17 2022 23:42:17-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.13.1 24
Mar 17 2022 23:42:32-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R1-GigabitEthernet0/0/1]q
[R1]int LoopBack 0
[R1-LoopBack0]ip address 1.1.1.1 32
[R1-LoopBack0]q
[R1]

R2:

<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.  
[Huawei]sysname R2
[R2]int g0/0/0 
[R2-GigabitEthernet0/0/0]ip address 192.168.12.2 24
Mar 17 2022 23:50:10-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R2-GigabitEthernet0/0/0]q
[R2]int LoopBack 0
[R2-LoopBack0]ip address 2.2.2.2 32
[R2-LoopBack0]

R3:

<Huawei>system-view 
Enter system view, return user view with Ctrl+Z. 
[Huawei]sysname R3
[R3]int g0/0/0  
[R3-GigabitEthernet0/0/0]ip address 192.168.13.2 24
Mar 17 2022 23:52:56-08:00 R3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R3-GigabitEthernet0/0/0]q
[R3]int LoopBack 0
[R3-LoopBack0]ip address 3.3.3.3 32   
[R3-LoopBack0]q 
[R3]int LoopBack 1 
[R3-LoopBack1]ip address 3.3.3.4 32
[R3-LoopBack1]q
[R3]

四、配置OSPF

将R1的RouterID配置为1.1.1.1 (即R1逻辑接口loopback 0 的地址),开启OSPF进程1(缺省进程),并将R1直连网段1.1.1.0/32、192.168.12.0/24、192.168.13.0/24 发布到OSPF区域0。

<R1>system-view 
Enter system view, return user view with Ctrl+Z.
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 192.168.12.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 3.3.3.0 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 192.168.13.0 0.0.0.255	
[R1-ospf-1-area-0.0.0.0]display this 
[V200R003C00]
#
 area 0.0.0.0 
  network 3.3.3.0 0.0.0.0 
  network 192.168.12.0 0.0.0.255 
  network 192.168.13.0 0.0.0.255 
#
return
[R1-ospf-1-area-0.0.0.0]q
[R1-ospf-1]

在同一台路由器可以开启多个OSPF进程,默认进程为1,不同路由器的OSPF进程号可以相同,同时要注意在OSPF区域中发布网段时,网段IP后面为反掩码。

将R2的RouterID配置为2.2.2.2 ,同时开启OSPF进程1,在OSPF区域0中发布直连网段192.168.12.0/24、192.168.13.0/24

<R2>system-view 
Enter system view, return user view with Ctrl+Z.
[R2]ospf		
[R2]ospf router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 192.168.12.0 0.0.0.255
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[0]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=Init) 
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[1]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=2Way) 
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[2]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=AdjOk?, NeighborPreviousState=2Way, NeighborCurrentState=ExStart) 
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[3]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=NegotiationDone, NeighborPreviousState=ExStart, NeighborCurrentState=Ex
change) 
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=ExchangeDone, NeighborPreviousState=Exchange, NeighborCurrentState=Load
ing) 
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
Mar 18 2022 00:12:13-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[5]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full) 
[R2-ospf-1-area-0.0.0.0]network2.2.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]

在发布第一个网段后,R2给出了回显信息:

ensp ospf 密码认证 ensp ospf配置_OSPF_02

可以看到,这里回显信息显示了R1与R2在建立OSPF邻接关系中的几种状态,最终达到“FULL”状态,也就表明两台路由器邻接关系建立成功!

待OSPF收敛完成后,分别查看三台路由器的路由表:

R1:

ensp ospf 密码认证 ensp ospf配置_网络协议_03

R2:

ensp ospf 密码认证 ensp ospf配置_OSPF_04

R3:

ensp ospf 密码认证 ensp ospf配置_网络协议_05

可以看到,这里三台路由器的路由表中都已经学到了邻居发布的路由信息,这其中包括R2到R3的逻辑接口地址。路由表中同时还给出了路由信息的来源,如“OSPF”。

接下来我们查看三台路由器的OSPF邻居关系:

查看邻居关系命令为:display ospf peer 

查看简化邻居关系:display ospf peer brief

R1:
 

ensp ospf 密码认证 ensp ospf配置_tcp/ip_06

 简化邻居关系:

ensp ospf 密码认证 ensp ospf配置_OSPF_07

R2:

ensp ospf 密码认证 ensp ospf配置_ensp ospf 密码认证_08

 

R3:

ensp ospf 密码认证 ensp ospf配置_tcp/ip_09

 

基本上到这里OSPF的单区域配置就是这些了,主要就是涉及到OSPF进程的建立,同时在OSPF区域中发布网段,待OSPF收敛完成后,就可以进行PING命令测测试了。

测试R2到R1、R2到R3的连通性:


ensp ospf 密码认证 ensp ospf配置_网络协议_10

PJNG R2 到R1的逻辑地址

 


ensp ospf 密码认证 ensp ospf配置_OSPF_11

PING R2到 R3的接口地址

可以看到,R2到R1、R3都是连通的,那么我们OSPF实现单区域路由通信就成功了!

五、修改·OSPF hello、dead时间参数

以R1为例,这里通过命令修改OSPF的hello、dead时间参数

R1:首先查看R1的一个接口上的OSPF参数:

ensp ospf 密码认证 ensp ospf配置_OSPF_12

 可以看到,这里在R1的G0/0/0接口上的OSPF hello、dead时间参数值,接下来对这个接口进行参数设置:

<R1>system-view 
Enter system view, return user view with Ctrl+Z.
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ospf timer hello 20	
[R1-GigabitEthernet0/0/0]ospf timer  dead 50
[R1-GigabitEthernet0/0/0]q
[R1]
Mar 18 2022 18:01:59-08:00 R1 %%01OSPF/3/NBR_CHG_DOWN(l)[0]:Neighbor event:neigh
bor state changed to Down. (ProcessId=256, NeighborAddress=2.2.2.2, NeighborEven
t=InactivityTimer, NeighborPreviousState=Full, NeighborCurrentState=Down) 
[R1]
Mar 18 2022 18:01:59-08:00 R1 %%01OSPF/3/NBR_DOWN_REASON(l)[1]:Neighbor state le
aves full or changed to Down. (ProcessId=256, NeighborRouterId=2.2.2.2, Neighbor
AreaId=0, NeighborInterface=GigabitEthernet0/0/0,NeighborDownImmediate reason=Ne
ighbor Down Due to Inactivity, NeighborDownPrimeReason=Interface Parameter Misma
tch, NeighborChangeTime=2022-03-18 18:01:59-08:00)

再查看现在的参数:

ensp ospf 密码认证 ensp ospf配置_网络协议_13

既然参数已经修改过来了,我们在看看R1的OSPF邻居简化信息有什么变化:

ensp ospf 密码认证 ensp ospf配置_tcp/ip_14

 可以看到,R1的OSPF邻居已由之前的·两个减为了一个,与R2的邻居关系消失了?这是因为修改了R1与R2建立OSPF邻居关系的接口参数后,由于建立邻居关系的两个接口参数不匹配,所以R1就无法与R2建立邻居关系。此时我们再修改R2的参数保持与R1一致:

<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ospf timer he	
[R2-GigabitEthernet0/0/0]ospf timer hello  20
[R2-GigabitEthernet0/0/0]ospf timer dead 50
[R2-GigabitEthernet0/0/0]q
[R2]
Mar 18 2022 18:08:23-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[0]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=Init) 
[R2]
Mar 18 2022 18:08:26-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[1]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=ExStart)
 
[R2]
Mar 18 2022 18:08:26-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[2]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=NegotiationDone, NeighborPreviousState=ExStart, NeighborCurrentState=Ex
change) 
[R2]
Mar 18 2022 18:08:26-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[3]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=ExchangeDone, NeighborPreviousState=Exchange, NeighborCurrentState=Load
ing) 
[R2]
Mar 18 2022 18:08:26-08:00 R2 %%01OSPF/4/NBR_CHANGE_E(l)[4]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=1.12.168.192, Neigh
borEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full) 
[R2]

从是上面的信息可以看出,在修改R2的参数后,回显信息显示此时与R1的邻居关系又重新建立了。可以从下面的R1OSPF邻居简化信息证实:

ensp ospf 密码认证 ensp ospf配置_OSPF_15

 六、OSPF缺省路由及验证

[R3]ip route-static 0.0.0.0 0.0.0.0 LoopBack 1   
[R3]ospf 1
[R3-ospf-1]default-route-advertise
[R3-ospf-1]q
[R3]

接下来查看R2的路由表信息:

ensp ospf 密码认证 ensp ospf配置_网络协议_16

 可以看到,R2已经学习了我们配置并发布的缺省路由信息。然后验证此条路由信息:

ensp ospf 密码认证 ensp ospf配置_tcp/ip_17

 那么PING命令也是成功了的!

七、控制OSPF DR、BDR的选举

先执行命令,查看R1与R2之间的DR、BDR角色:

R1:

ensp ospf 密码认证 ensp ospf配置_OSPF_18

 可以看出,在这两个路由器之间的OSPF邻居关系中,DR为R2,BDR为R1,因为默认OSFP路由器优先级为1,相同,但是这里由于R2的RouterID 大于R1的,所以R2为DR,R1为BDR。

接下来我们分别修改R1和R2的DR优先级:

R1:

[R1]int g0/0/0	
[R1-GigabitEthernet0/0/0]ospf dr-priority 200
[R1-GigabitEthernet0/0/0]q
[R1]

R2:

<R2>system-view 
Enter system view, return user view with Ctrl+Z.
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ospf dr-priority 100
[R2-GigabitEthernet0/0/0]q
[R2]

由于OSPF默认为非抢占模式,所以在修改DR优先级之后,系统不会重新选举DR,所以我们需要重置R1与R2之间的邻居关系。

关闭R1上的G0/0/0接口,然后再打开:

<R1>system-view 
Enter system view, return user view with Ctrl+Z.
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]shutdown 
Mar 18 2022 18:40:04-08:00 R1 %%01IFPDT/4/IF_STATE(l)[0]:Interface GigabitEthern
et0/0/0 has turned into DOWN state.
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:04-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the DOWN state. 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:04-08:00 R1 %%01OSPF/3/NBR_CHG_DOWN(l)[2]:Neighbor event:neigh
bor state changed to Down. (ProcessId=256, NeighborAddress=2.2.2.2, NeighborEven
t=KillNbr, NeighborPreviousState=Full, NeighborCurrentState=Down) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:04-08:00 R1 %%01OSPF/3/NBR_DOWN_REASON(l)[3]:Neighbor state le
aves full or changed to Down. (ProcessId=256, NeighborRouterId=2.2.2.2, Neighbor
AreaId=0, NeighborInterface=GigabitEthernet0/0/0,NeighborDownImmediate reason=Ne
ighbor Down Due to Kill Neighbor, NeighborDownPrimeReason=Physical Interface Sta
te Change, NeighborChangeTime=2022-03-18 18:40:04-08:00) 
[R1-GigabitEthernet0/0/0]undo shutdown 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:18-08:00 R1 %%01IFPDT/4/IF_STATE(l)[4]:Interface GigabitEthern
et0/0/0 has turned into UP state.
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:18-08:00 R1 %%01IFNET/4/LINK_STATE(l)[5]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:39-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[6]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neigh
borEvent=HelloReceived, NeighborPreviousState=Down, NeighborCurrentState=Init) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:40:39-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[7]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neigh
borEvent=2WayReceived, NeighborPreviousState=Init, NeighborCurrentState=2Way) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:41:06-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[8]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neigh
borEvent=AdjOk?, NeighborPreviousState=2Way, NeighborCurrentState=ExStart) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:41:08-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[9]:Neighbor changes eve
nt: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neigh
borEvent=NegotiationDone, NeighborPreviousState=ExStart, NeighborCurrentState=Ex
change) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:41:08-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[10]:Neighbor changes ev
ent: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neig
hborEvent=ExchangeDone, NeighborPreviousState=Exchange, NeighborCurrentState=Loa
ding) 
[R1-GigabitEthernet0/0/0]
Mar 18 2022 18:41:08-08:00 R1 %%01OSPF/4/NBR_CHANGE_E(l)[11]:Neighbor changes ev
ent: neighbor status changed. (ProcessId=256, NeighborAddress=2.12.168.192, Neig
hborEvent=LoadingDone, NeighborPreviousState=Loading, NeighborCurrentState=Full)
 
[R1-GigabitEthernet0/0/0]q

此后再查看R1上的OSPF邻居关系信息:

ensp ospf 密码认证 ensp ospf配置_网络_19

 可以看到,此时DR和BDR已经发生了改变,由此我们就实现了手动改变DR、BDR的目的。

八、配置信息:

R1:

[R1]display  current-configuration 
[V200R003C00]
#
 sysname R1
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.12.1 255.255.255.0 
 ospf dr-priority 200
 ospf timer hello 20
 ospf timer dead 50
#
interface GigabitEthernet0/0/1
 ip address 192.168.13.1 255.255.255.0 
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
 ip address 1.1.1.1 255.255.255.255 
#
ospf 1 router-id 1.1.1.1 
 area 0.0.0.0 
  network 1.1.1.1 0.0.0.0 
  network 192.168.12.0 0.0.0.255 
  network 192.168.13.0 0.0.0.255 
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
[R1]

R2:

[R2]display current-configuration 
[V200R003C00]
#
 sysname R2
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.12.2 255.255.255.0 
 ospf dr-priority 100
 ospf timer hello 20
 ospf timer dead 50
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
 ip address 2.2.2.2 255.255.255.255 
#
ospf 1 router-id 2.2.2.2 
 area 0.0.0.0 
  network 2.2.2.2 0.0.0.0 
  network 192.168.12.0 0.0.0.255 
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
[R2]

R3:

<R3>display  current-configuration 
[V200R003C00]
#
 sysname R3
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.13.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
 ip address 3.3.3.3 255.255.255.255 
#
interface LoopBack1
 ip address 3.3.3.4 255.255.255.255 
#
ospf 1 router-id 3.3.3.3 
 default-route-advertise
 area 0.0.0.0 
  network 3.3.3.3 0.0.0.0 
  network 192.168.13.0 0.0.0.255 
#
ip route-static 0.0.0.0 0.0.0.0 LoopBack1
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
<R3>