ENSP-OSPF 单区域

OSPF单区域

目标

  • 实现单区域OSPF的配置
  • 实现OSPF的区域认证的配置
  • 描述OSPF在多路访问网络中邻居关系的建立过程
  • 实现对OSPF接口代价值进行修改
  • 阐述OSPF中Silent-interface的配置方式
  • 实现通过display查看OSPF 的各种状态

实验拓扑

image
R1、R2、R3 之间通过交换机 S1 相连, 其接口、IP 地址如图所示。R1、R2、R3 上均创建 Loopback0,
IP 地址为 10.0.x.x/24, 其中 x 为设备编号。
R1、 R2、 R3 所有接口都属于区域 0, 在互联接口、 Loopback0 接口上激活 OSPF。

实验背景

你是公司的网络管理员。 现在公司的网络中有三台 AR 路由器, 通过以太网实现相互的连通。
在以太网这样的广播式多路访问网络上, 可能存在安全隐患, 所有你选择采用 OSPF 区域认证
的方法来避免恶意的路由攻击。

实验思路

  1. 设备 IP 地址配置。
  2. 在 R1、 R2、 R3 上配置 OSPF, 手动指定 Router ID, 并在互联接口、 Loopback0 接口上激
    活 OSPF。
  3. 配置完成后, 在 R1、 R2、 R3 上检查 OSPF 邻居关系状态、 OSPF 路由表, 并检查 R1、 R2、
    R3 环回口之间的连通性。
  4. 手动关闭 R1、 R2、 R3 的互联接口, 开启 debug 以观察 OSPF 邻居关系的建立过程, 再同
    时开启互联接口, 观察设备的 debug 输出。
  5. 手动修改 R2 Loopback0 接口的网络类型, 观察 OSPF 路由的掩码长度变化。
  6. 手动修改 OSPF 接口的 Cost 值。
  7. 分别将互联接口、 Loopback0 接口配置为 OSPF Silent-Interface, 观察现象的区别。

实验步骤

步骤 1 互联网接口、回环扣IP配置

设备命名
<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]sys	
[Huawei]sysname R1
[R1]
.....
# 省略R2、R3和S1
关闭本实验中未使用的接口
[R1]port-group group-member e0/0/0 to  e0/0/7
[R1-port-group]shutdown
.....
# 省略R2、R3和S1
配置R1 GE0/0/0 接口、回环地址IP
<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 10.0.123.1 24
Sep 19 2025 15:31:05-08:00 R1 %%01IFNET/4/LINK_STATE(l)[8]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R1-GigabitEthernet0/0/0]quit
[R1]int Loo	
[R1]int LoopBack 0
[R1-LoopBack0]ip add 10.0.1.1 24
[R1-LoopBack0]quit

配置R2 GE0/0/0 接口、回环地址IP

[R2]int g 0/0/0
[R2-GigabitEthernet0/0/0]ip add 10.0.123.2 24
Sep 19 2025 16:42:38-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]quit
[R2]int Loop	
[R2]int LoopBack 0
[R2-LoopBack0]ip add 10.0.2.2 24
[R2-LoopBack0]quit
[R2]
配置R3 GE0/0/0 接口、回环地址IP
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 10.0.123.3 24
Sep 19 2025 16:45:05-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]quit
[R3]int LoopBack 0
[R3-LoopBack0]ip add 10.0.3.3 24
[R3-LoopBack0]quit

在R1上验证连通性

<R1>ping 10.0.123.2
  PING 10.0.123.2: 56  data bytes, press CTRL_C to break
    Reply from 10.0.123.2: bytes=56 Sequence=1 ttl=255 time=200 ms
    Reply from 10.0.123.2: bytes=56 Sequence=2 ttl=255 time=40 ms
    Reply from 10.0.123.2: bytes=56 Sequence=3 ttl=255 time=50 ms
    Reply from 10.0.123.2: bytes=56 Sequence=4 ttl=255 time=30 ms
    Reply from 10.0.123.2: bytes=56 Sequence=5 ttl=255 time=40 ms

  --- 10.0.123.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 30/72/200 ms

<R1>ping 10.0.123.3
  PING 10.0.123.3: 56  data bytes, press CTRL_C to break
    Reply from 10.0.123.3: bytes=56 Sequence=1 ttl=255 time=110 ms
    Reply from 10.0.123.3: bytes=56 Sequence=2 ttl=255 time=50 ms
    Reply from 10.0.123.3: bytes=56 Sequence=3 ttl=255 time=40 ms
    Reply from 10.0.123.3: bytes=56 Sequence=4 ttl=255 time=40 ms
    Reply from 10.0.123.3: bytes=56 Sequence=5 ttl=255 time=50 ms

  --- 10.0.123.3 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 40/58/110 ms

步骤 2 配置单区域OSPF

配置R1、R2、R3 的OSPF Router ID 未Lookback 0 接口地址,OSPF进程号为1

[R1]ospf  1 router-id 10.0.1.1
[R2]ospf  1 router-id 10.0.2.2
[R3]ospf  1 router-id 10.0.3.3

在 R1、 R2、 R3 的互联接口、 Loopback0 接口激活 OSPF

[R1] ospf 1 router-id 10.0.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]netw	
[R1-ospf-1-area-0.0.0.0]network  10.0.123.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 10.0.1.1 0.0.0.0
[R2] ospf 1 router-id 10.0.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]netw	
[R2-ospf-1-area-0.0.0.0]network  10.0.123.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[R3] ospf 1 router-id 10.0.2.2
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]netw	
[R3-ospf-1-area-0.0.0.0]network  10.0.123.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.3.3 0.0.0.0

为保证安全性,配置OSPF的区域认证,使用明文认证方式,密码配置为"* huawei * "

<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]authentication-mode simple plain huawei
<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]authentication-mode simple plain huawei
<R3>sys
Enter system view, return user view with Ctrl+Z.
[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]authentication-mode simple plain huawei

步骤 3 检查 OSPF 配置结果

检查#检查 R1、 R2、 R3 上的 OSPF 邻居信息

<R1>display ospf peer

	 OSPF Process 1 with Router ID 10.0.1.1
		 Neighbors 

 Area 0.0.0.0 interface 10.0.123.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 10.0.2.2         Address: 10.0.123.2      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 37  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:04:47     
   Authentication Sequence: [ 0 ] 

 Router ID: 10.0.3.3         Address: 10.0.123.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 40  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:04:08     
   Authentication Sequence: [ 0 ] 

<R2>display ospf peer 

	 OSPF Process 1 with Router ID 10.0.2.2
		 Neighbors 

 Area 0.0.0.0 interface 10.0.123.2(GigabitEthernet0/0/0)'s neighbors
 Router ID: 10.0.1.1         Address: 10.0.123.1      
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 40  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:06:00     
   Authentication Sequence: [ 0 ] 

 Router ID: 10.0.3.3         Address: 10.0.123.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 40  sec 
   Retrans timer interval: 8 
   Neighbor is up for 00:10:17     
   Authentication Sequence: [ 0 ] 

<R3>display  ospf peer

	 OSPF Process 1 with Router ID 10.0.3.3
		 Neighbors 

 Area 0.0.0.0 interface 10.0.123.3(GigabitEthernet0/0/0)'s neighbors
 Router ID: 10.0.1.1         Address: 10.0.123.1      
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 33  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:05:46     
   Authentication Sequence: [ 0 ] 

 Router ID: 10.0.2.2         Address: 10.0.123.2      
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 36  sec 
   Retrans timer interval: 4 
   Neighbor is up for 00:10:42     
   Authentication Sequence: [ 0 ] 

由结果可知三台路由器已经建立了OSPF的邻居关系

检查 R1、 R2、 R3 的 OSPF 路由表

<R1>display ospf routing
	 OSPF Process 1 with Router ID 10.0.1.1
		  Routing Tables 
 Routing for Network 
 Destination        Cost  Type       NextHop         AdvRouter       Area
 10.0.1.1/32        0     Stub       10.0.1.1        10.0.1.1        0.0.0.0
 10.0.123.0/24      1     Transit    10.0.123.1      10.0.1.1        0.0.0.0
 10.0.2.2/32        1     Stub       10.0.123.2      10.0.2.2        0.0.0.0
 10.0.3.3/32        1     Stub       10.0.123.3      10.0.3.3        0.0.0.0
 Total Nets: 4  
 Intra Area: 4  Inter Area: 0  ASE: 0  NSSA: 0 

从输出结果可知 R1 已经成功学习到 R2、 R3 的 Loopback0 接口路由。

<R2>display ospf routing
	 OSPF Process 1 with Router ID 10.0.2.2
		  Routing Tables 
 Routing for Network 
 Destination        Cost  Type       NextHop         AdvRouter       Area
 10.0.2.2/32        0     Stub       10.0.2.2        10.0.2.2        0.0.0.0
 10.0.123.0/24      1     Transit    10.0.123.2      10.0.2.2        0.0.0.0
 10.0.1.1/32        1     Stub       10.0.123.1      10.0.1.1        0.0.0.0
 10.0.3.3/32        1     Stub       10.0.123.3      10.0.3.3        0.0.0.0
 Total Nets: 4  
 Intra Area: 4  Inter Area: 0  ASE: 0  NSSA: 0 

从输出结果可知 R2 已经成功学习到 R1、 R3 的 Loopback0 接口路由

<R3>display  ospf routing
	 OSPF Process 1 with Router ID 10.0.3.3
		  Routing Tables 
 Routing for Network 
 Destination        Cost  Type       NextHop         AdvRouter       Area
 10.0.3.3/32        0     Stub       10.0.3.3        10.0.3.3        0.0.0.0
 10.0.123.0/24      1     Transit    10.0.123.3      10.0.3.3        0.0.0.0
 10.0.1.1/32        1     Stub       10.0.123.1      10.0.1.1        0.0.0.0
 10.0.2.2/32        1     Stub       10.0.123.2      10.0.2.2        0.0.0.0
 Total Nets: 4  
 Intra Area: 4  Inter Area: 0  ASE: 0  NSSA: 0 

从输出结果可知 R3 已经成功学习到 R1、 R2 的 Loopback0 接口路由。

检查回环口之间的连通性

<R1>ping -c 1 -a 10.0.1.1 10.0.2.2
  PING 10.0.2.2: 56  data bytes, press CTRL_C to break
    Reply from 10.0.2.2: bytes=56 Sequence=1 ttl=255 time=50 ms
  --- 10.0.2.2 ping statistics ---
    1 packet(s) transmitted
    1 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 50/50/50 ms

<R1>ping -c 1 -a 10.0.1.1 10.0.3.3
  PING 10.0.3.3: 56  data bytes, press CTRL_C to break
    Reply from 10.0.3.3: bytes=56 Sequence=1 ttl=255 time=40 ms
  --- 10.0.3.3 ping statistics ---
    1 packet(s) transmitted
    1 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 40/40/40 ms

R1 上以 Loopback0 接口地址为源测试与 R2、 R3 的 Loopback0 接口之间的连通性

在 R1 上查看 OSPF LSDB

<R1>display ospf lsdb
	 OSPF Process 1 with Router ID 10.0.1.1
		 Link State Database 
		         Area: 0.0.0.0
 Type      LinkState ID    AdvRouter          Age  Len   Sequence   Metric
 Router    10.0.3.3        10.0.3.3           677  48    8000000A       1
 Router    10.0.2.2        10.0.2.2           677  48    8000000C       1
 Router    10.0.1.1        10.0.1.1           682  48    8000000E       1
 Network   10.0.123.2      10.0.2.2           677  36    80000006       0

在这里一共可以看到 4 条 LSA, 前 3 条为 Type-1 LSA, 分别由 R1、 R2 和 R3 产生, 可以通过
AdvRouter 判断该 LSA 是由哪台路由器生成的。 第四条为 Type-2 LSA, 是由一个网段的 DR 产
生的。在这里, R2 是 10.0.123.0/24 这个网段的 DR, 所以该 Type-2 LSA 的 AdvRouter 为 10.0.2.2。

查看R1产生的Typer-1 LSA

<R1>display  ospf lsdb router self-originate 
	 OSPF Process 1 with Router ID 10.0.1.1
		         Area: 0.0.0.0
		 Link State Database 

  Type      : Router
  Ls id     : 10.0.1.1
  Adv rtr   : 10.0.1.1  
  Ls age    : 555 
  Len       : 48 
  Options   :  E  
  seq#      : 8000000f 
  chksum    : 0x7f83
  Link count: 2
   * Link ID: 10.0.123.2   
     Data   : 10.0.123.1   
     Link Type: TransNet     
     Metric : 1
   * Link ID: 10.0.1.1     
     Data   : 255.255.255.255 
     Link Type: StubNet      
     Metric : 0 
     Priority : Medium

从输出中可以看到这条 LSA 一共描述了 2 个 Link,第一个 Link 描述了三台路由器的互联网段, Link Type为 TransNet, 可以看到 Link ID为 DR的接口地址:10.0.123.2,Data 为该网段上本地接口的 IP 地址:10.0.123.1
第二个 Link 描述了 Loopback 接口所在网段,Link Type 为 StubNet, Link ID 和 Data 分别是该 Stub 网段的 IP 地址和掩码。

查看R2产生的Typer-2 LSA

<R2>display ospf lsdb network self-originate 
	 OSPF Process 1 with Router ID 10.0.2.2
		         Area: 0.0.0.0
		 Link State Database 

  Type      : Network
  Ls id     : 10.0.123.2
  Adv rtr   : 10.0.2.2  
  Ls age    : 1422 
  Len       : 36 
  Options   :  E  
  seq#      : 80000007 
  chksum    : 0x1a76
  Net mask  : 255.255.255.0
  Priority  : Low
     Attached Router    10.0.2.2
     Attached Router    10.0.1.1
     Attached Router    10.0.3.3

从输出信息可以看到 Type-2 LSA 中的 Attached Router 描述了 DR 所在网段的邻居信息。

步骤 4 观察 OSPF 邻居关系建立过程

之前查看 OSPF 邻居信息时可以看到 DR 为 10.0.123.2, 这与根据 DR 选举原则进行预测的结果
并不一致。 在 OSPF 中, DR 的选举为非抢占, 即网络中存在 DR 或 BDR 时, 新进入网络的路
由器不能抢占 DR 或 BDR 的角色。 当在配置 OSPF 时对设备的配置顺序存在前后差距, 就可能
导致选举出的 DR 为先启动的设备。
为此可以关闭 R1、 R2、 R3 的互联接口, 并使用 debugging ospf1 event 观察 OSPF 邻居关系建
立的具体过程, 之后尽量同时重新打开 R1、 R2、 R3 的接口, 通过 debug 输出信息查看 DR、
BDR 的选举过程

关闭R1、R2、R3的互联网接口

[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]shutdown 
[R2]int g 0/0/0
[R2-GigabitEthernet0/0/0]shut
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]shut

打开 R1、 R2、 R3 的 debug 功能以及开启 debug ospfeven

<R1>terminal debugging 
Info: Current terminal debugging is on.
<R1>terminal monitor 
Info: Current terminal monitor is on.
<R1>debugging ospf 1 event

R2、 R3 相同操作, 不再重复。

重新打开R1、R2、R3的互联网接口

[R1] interface GigabitEthernet0/0/0
[R1-GigabitEthernet0/0/0] undo shutdown
[R2] interface GigabitEthernet0/0/0
[R2-GigabitEthernet0/0/0] undo shutdown
[R3] interface GigabitEthernet0/0/0
[R3-GigabitEthernet0/0/0] undo shutdow

#观察 debug 输出信息

[R1-GigabitEthernet0/0/0]
Sep 19 2025 20:32:53.222.6-08:00 R1 RM/6/RMDEBUG:
 FileID: 0xd017802c Line: 2536 Level: 0x20
  OSPF 1: Intf 10.0.123.1 Rcv NeighborChange State DR -> BackupDR.
  
[R2-GigabitEthernet0/0/0]
Sep 19 2025 20:32:53.575.3-08:00 R2 RM/6/RMDEBUG:
 FileID: 0xd017802c Line: 2107 Level: 0x20
  OSPF 1: Intf 10.0.123.2 Rcv WaitTimer State Waiting -> *DR*.
  
[R3-GigabitEthernet0/0/0]
Sep 19 2025 20:33:08.893.4-08:00 R3 RM/6/RMDEBUG:
 FileID: 0xd017802c Line: 2107 Level: 0x20
  OSPF 1: Intf 10.0.123.3 Rcv BackupSeen State Waiting -> DROther.

从输出中可以看出,R2 成为DR,R1成为BDR

步骤 5 配置OSPF接口的网络类型

在 R2上查看 OSPF 路由表中的 R1、 R3 的 Loopback0 接口路由

<R2>display ospf routing 10.0.1.1
	 OSPF Process 1 with Router ID 10.0.2.2
 Destination : 10.0.1.1/32        
 AdverRouter : 10.0.1.1                 Area      : 0.0.0.0  
 Cost        : 1                        Type      : Stub 
 NextHop     : 10.0.123.1               Interface : GigabitEthernet0/0/0  
 Priority    : Medium                   Age       : 00h17m30s  
 
<R2>display ospf routing 10.0.3.3
	 OSPF Process 1 with Router ID 10.0.2.2
 Destination : 10.0.3.3/32        
 AdverRouter : 10.0.3.3                 Area      : 0.0.0.0  
 Cost        : 1                        Type      : Stub 
 NextHop     : 10.0.123.3               Interface : GigabitEthernet0/0/0  
 Priority    : Medium                   Age       : 00h17m14s  

可以观察到Loopback0 接口路由的掩码为32位,而不是实际的24位
因为OSPF 默认将 Loopback 接口的路由以 /32 主机路由(Host Route)的方式通告出去
这相当于把 Loopback 接口当作 主机路由(Host Route) 来处理

以R1为例,查看OSPF的Type-1 LSA

<R1>display ospf lsdb router 10.0.1.1
	 OSPF Process 1 with Router ID 10.0.1.1
		         Area: 0.0.0.0
		 Link State Database 
  Type      : Router
  Ls id     : 10.0.1.1
  Adv rtr   : 10.0.1.1  
  Ls age    : 967 
  Len       : 48 
  Options   :  E  
  seq#      : 8000001b 
  chksum    : 0x678f
  Link count: 2
   * Link ID: 10.0.123.2   
     Data   : 10.0.123.1   
     Link Type: TransNet     
     Metric : 1
   * Link ID: 10.0.1.1     
     Data   : 255.255.255.255 
     Link Type: StubNet      
     Metric : 0 
     Priority : Medium

   * Link ID: 10.0.1.1    
     Data   : 255.255.255.255 

可以看到 R1 上关于 Loopback0 接口的 LSA 里已经将掩码设为 32 位, OSPF 将 Loopback 接口
视为一个末梢网络, 且该网络中只连接着一个节点, 因此无论该接口实际配置的网络掩码是多
少位, OSPF 在 Type-1 LSA 中描述这个接口时, 都以主机(32 位网络掩码) 的形式进行通告。
关于 OSPF 中 Loopback 接口详细解释可以查阅 RFC 2328 Section 9.1

修改R1 Loopback0接口的网络类型

[R1]int LoopBack 0
[R1-LoopBack0]ospf network-type  broadcast 

将 Loopback 接口的网络类型修改为 Broadcast, OSPF 在发布这个接口的网络信息时, 会使用接
口真实掩码(本例中 R2 的 Loopback0 接口真实掩码长度为 24 位) 进行发布

在R2 上再次查看ospf路由表中R1 的Lookback 0 接口路由

<R2>display ospf routing 10.0.1.1
	 OSPF Process 1 with Router ID 10.0.2.2
 Destination : 10.0.1.0/24        
 AdverRouter : 10.0.1.1                 Area      : 0.0.0.0  
 Cost        : 1                        Type      : Stub 
 NextHop     : 10.0.123.1               Interface : GigabitEthernet0/0/0  
 Priority    : Low                      Age       : 00h01m30s 

从输出信息中可以看到路由的掩码已经变为 24 位

步骤 6 修改OSPF 接口的cost值

在R1 上查看OSPF 路由表中的R3 Loopback 0接口路由

<R1>display  ospf routing  10.0.3.3   
	 OSPF Process 1 with Router ID 10.0.1.1
 Destination : 10.0.3.3/32        
 AdverRouter : 10.0.3.3                 Area      : 0.0.0.0  
 Cost        : 1                        Type      : Stub 
 NextHop     : 10.0.123.3               Interface : GigabitEthernet0/0/0  
 Priority    : Medium                   Age       : 02h11m26s 

从输出信息可以看见其Cost值为1

修改 R1 的 GE0/0/3 接口 OSPF Cost 值为 20, 修改 R3 的 GE0/0/4 接口 OSPF Cost 值为 10

[R1]int g 0/0/0
[R1-GigabitEthernet0/0/0]ospf cost 20
[R3] int g 0/0/0
[R3-GigabitEthernet0/0/0]ospf cost 10

在 R1 上重新查看 OSPF 路由表中的 R2 Loopback0 接口路由

<R1>display ospf routing 10.0.2.2

	 OSPF Process 1 with Router ID 10.0.1.1

 Destination : 10.0.2.2/32        
 AdverRouter : 10.0.2.2                 Area      : 0.0.0.0  
 Cost        : 20                       Type      : Stub 
 NextHop     : 10.0.123.2               Interface : GigabitEthernet0/0/0  
 Priority    : Medium                   Age       : 00h02m01s  

从输出信息可以看见其Cost 值为20,同时路由表中R3 的Loopback Coat值也为30

在 R3 上查看 OSPF 路由表中的 R1 Loopback0 接口路由

<R3>display ospf routing 10.0.1.1

	 OSPF Process 1 with Router ID 10.0.3.3

 Destination : 10.0.1.0/24        
 AdverRouter : 10.0.1.1                 Area      : 0.0.0.0  
 Cost        : 10                       Type      : Stub 
 NextHop     : 10.0.123.1               Interface : GigabitEthernet0/0/0  
 Priority    : Low                      Age       : 00h02m40s

其输出信息可以看见其Cost值为10.同时路由表中R2 的Loopback Coat值也为20.

配置OSPF 的Silent-interface

将 R1 的 GE0/0/0 接口配置为 Silent-Iinterfac

[R1]ospf 1
[R1-ospf-1]silent-interface g 0/0/0

查看 R1 的 OSPF 邻居表

<R1>display ospf peer
	 OSPF Process 1 with Router ID 10.0.1.1

配置互联接口为 Silent-Interface 之后, 不再从该接口发送、 接收 hello 报文, 已经建立关系的邻
居消失。

查看 R1 的 OSPF 接口 GE0/0/0 的信息

<R1>display ospf interface g 0/0/0

	 OSPF Process 1 with Router ID 10.0.1.1
		 Interfaces 

 Interface: 10.0.123.1 (GigabitEthernet0/0/0)
 Cost: 20      State: DR        Type: Broadcast    MTU: 1500  
 Priority: 1
 Designated Router: 10.0.123.1
 Backup Designated Router: 0.0.0.0
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 
 Silent interface, No hellos
Silent interface, No hellos   #静默接口,不接收hello报文

删除 R1 上 Silent-Interface 配置

[R1]ospf 1
[R1-ospf-1]undo si	
[R1-ospf-1]undo silent-interface g 0/0/0

查看R1的路由邻居表

<R1>display ospf peer

	 OSPF Process 1 with Router ID 10.0.1.1
		 Neighbors 

 Area 0.0.0.0 interface 10.0.123.1(GigabitEthernet0/0/0)'s neighbors
 Router ID: 10.0.2.2         Address: 10.0.123.2      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 34  sec 
   Retrans timer interval: 6 
   Neighbor is up for 00:00:15     
   Authentication Sequence: [ 0 ] 

 Router ID: 10.0.3.3         Address: 10.0.123.3      
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 10.0.123.2  BDR: 10.0.123.3  MTU: 0    
   Dead timer due in 40  sec 
   Retrans timer interval: 5 
   Neighbor is up for 00:00:16     
   Authentication Sequence: [ 0 ] 

将 R2、 R3 的 Loopback0 配置为 Silent-Interfac

[R2]ospf1
[R2-ospf-1] silent-interface LoopBack 0
[R3]ospf1
[R3-ospf-1] silent-interface LoopBack 0

在 R1 上查看 OSPF 路由表

<R1>display ospf routing 

	 OSPF Process 1 with Router ID 10.0.1.1
		  Routing Tables 

 Routing for Network 
 Destination        Cost  Type       NextHop         AdvRouter       Area
 10.0.1.0/24        0     Stub       10.0.1.1        10.0.1.1        0.0.0.0
 10.0.123.0/24      20    Transit    10.0.123.1      10.0.1.1        0.0.0.0
 10.0.2.2/32        20    Stub       10.0.123.2      10.0.2.2        0.0.0.0
 10.0.3.3/32        20    Stub       10.0.123.3      10.0.3.3        0.0.0.0
 Total Nets: 4  
 Intra Area: 4  Inter Area: 0  ASE: 0  NSSA: 0 
 10.0.2.2/32        20    Stub       10.0.123.2      10.0.2.2        0.0.0.0
 10.0.3.3/32        20    Stub       10.0.123.3      10.0.3.3        0.0.0.0

可以看到R2、R3 Loopback 依旧存在

在实际的网络中,哪些接口可以配置为 Silent-Interface?

  1. Loopback 接口(最典型场景)
    Loopback 是虚拟接口,不可能有邻居。
    你只想把 10.0.1.1/32 宣告进 OSPF,用于 Router ID 或管理。
    如果不设 silent,OSPF 会尝试在 Loopback 上发 Hello(虽然无意义)。
  2. 管理接口(Management Interface)
    比如专用的 Mgmt 接口或 Ethernet0/0/0,用于连接网管服务器。
    你希望该网段被路由学习到,但不允许其他设备建立 OSPF 邻居(防止攻击或误配置)。
  3. 连接终端用户的接口(如 LAN 接口)
    接口连接的是 PC、打印机、IP 电话、摄像头 等终端设备。
    这些设备不会运行 OSPF。
    如果不设 silent,OSPF 会不断发送 Hello 报文,浪费资源,也可能被恶意设备利用。
  4. 连接防火墙或安全设备的接口(非动态路由对接)
    如果防火墙不运行 OSPF(或使用静态路由),但你想让其他路由器知道这个网段。
    例如:10.1.200.0/24 是 DMZ 网段,由防火墙保护。
  5. 备份或未使用的物理接口
    某些接口暂时不用,但 IP 已规划。
    为了避免误接设备后形成邻居,提前设为 silent。
posted @ 2025-09-19 23:11  Soren_Luo  阅读(40)  评论(0)    收藏  举报