OSPF协议单区域配置

OSPF协议单区域配置

项目要求:

中小企业网络规模不大,路由设备数量有限,可以考虑将所有设备都放在同一个OSPF区域。大型企业网络规模大,路由器设备数量很多,网络层次分明,建议采用OSPF多区域的方式部署。

1.OSPF协议单区域配置
2.OSPF协议多区域配置
3.查看OSPF协议的3张表
4.在区域边界路由器上进行路由汇总
配置这些路由器运行OSPF协议,将这些路由器配置在一个区域。
虽然只有一个区域,该区域只能是骨干区域,区域编号是0.0.0.0,也可以写成0。

1.前期准备

image-20250523104354539

image-20250523121444090

AR3

<Huawei>sys
[Huawei]user-interface console 0
[Huawei-aaa]local-user zhao password cipher 123456
[Huawei-aaa]local-user zhao privilege level 3    
[Huawei-aaa]local-user wong password cipher 123456
[Huawei-aaa]local-user wong privilege level 3    
[Huawei-aaa]local-user wong service-type ssh
[Huawei-aaa]quit
[Huawei]ssh user wong authentication-type password    
[Huawei]stelnet server enable 
[Huawei]user-interface vty 0 4
[Huawei-ui-vty0-4]authentication-mode aaa
[Huawei-ui-vty0-4]protocol inbound ssh
[Huawei-ui-vty0-4]quit
[Huawei]interface GigabitEthernet 0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 172.16.1.1 24
[Huawei-GigabitEthernet0/0/0]quit
[Huawei]interface Serial 1/0/1
[Huawei-Serial1/0/1]ip address 172.16.0.1 30
[Huawei-Serial1/0/1]quit
[Huawei]interface Serial 1/0/0
[Huawei-Serial1/0/0]ip address 172.16.0.17 30
[Huawei-Serial1/0/0]return
<Huawei>save

AR4

<Huawei>sy    
[Huawei]user-interface console 0
[Huawei-ui-console0]authentication-mode aaa
[Huawei-aaa]local-user zhao password cipher 123456    
[Huawei-aaa]local-user zhao privilege level 3
[Huawei-aaa]quit
[Huawei]interface Serial 2/0/0
[Huawei-Serial2/0/0]ip address 172.16.0.2 30
[Huawei-Serial2/0/0]quit
[Huawei]interface Serial 2/0/1
[Huawei-Serial2/0/1]ip address 172.16.0.5 30
[Huawei-Serial2/0/1]quit
[Huawei]return
<Huawei>save

AR5

<Huawei>sys
[Huawei]user-interface console 0
[Huawei-ui-console0]authentication-mode aaa
[Huawei-aaa]local-user zhao password cipher 123456
[Huawei-aaa]local-user zhao privilege level 3
[Huawei-aaa]quit

[Huawei]interface Serial 1/0/1
[Huawei-Serial1/0/1]ip address 172.16.0.6 30
[Huawei-Serial1/0/1]quit

[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 172.16.2.1 24
[Huawei-GigabitEthernet0/0/1]quit

[Huawei]interface Serial 1/0/0
[Huawei-Serial1/0/0]ip address 172.16.0.9 30
[Huawei-Serial1/0/0]return
<Huawei>save

AR7

<Huawei>sys
[Huawei]user-interface console 0
[Huawei-ui-console0]authentication-mode aaa
[Huawei-ui-console0]aaa
[Huawei-aaa]local-user zhao password cipher 123456
[Huawei-aaa]local-user zhao privilege level 3
[Huawei-aaa]quit
[Huawei]interface Serial 2/0/0
[Huawei-Serial2/0/0]ip address 172.16.0.18 30
[Huawei-Serial2/0/0]quit
[Huawei]interface Serial 2/0/1
[Huawei-Serial2/0/1]ip address 172.16.0.13 30
[Huawei-Serial2/0/1]return
<Huawei>save

AR8

<Huawei>sys
[Huawei]user-interface console 0
[Huawei-ui-console0]authentication-mode aaa
[Huawei-ui-console0]aaa
[Huawei-aaa]local-user zhao password cipher 123456
[Huawei-aaa]local-user zhao privilege level 3
[Huawei-aaa]quit
[Huawei]interface Serial 2/0/1
[Huawei-Serial2/0/1]ip address 172.16.0.10 30
[Huawei-Serial2/0/1]quit
[Huawei]interface Serial 2/0/0
[Huawei-Serial2/0/0]ip address 172.16.0.14 30
[Huawei-Serial2/0/0]return
<Huawei>save

2.配置OSPF

AR3

[Huawei]ospf 1 router-id 1.1.1.1
[Huawei-ospf-1]area 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]network 172.168.0.0 0.0.255.255
[Huawei-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher Huwei
[Huawei-ospf-1-area-0.0.0.0]quit

AR4

[Huawei]ospf 1 router-id 1.1.1.2
[Huawei-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.0.3
[Huawei-ospf-1-area-0.0.0.0]network 172.16.0.4 0.0.0.3
[Huawei-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher Huwei
[Huawei-ospf-1-area-0.0.0.0]quit

AR5

[Huawei]ospf 1 router-id 1.1.1.3
[Huawei-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[Huawei-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher Huwei
[Huawei-ospf-1-area-0.0.0.0]quit

AR7

[Huawei]ospf 1 router-id 1.1.1.4
[Huawei-ospf-1]area 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[Huawei-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher Huwei

AR8

[Huawei]ospf 1 router-id 1.1.1.5
[Huawei-ospf-1]area 0.0.0.0
[Huawei-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255
[Huawei-ospf-1-area-0.0.0.0]authentication-mode md5 1 cipher Huwei

3.测试

image-20250523153517840

image-20250523153603466

断开上面得0.5的链路

image-20250523153622052

image-20250523153650042

image-20250523153710498

4.验证OSPF工作过程

image-20250523163257858

#基本上是通过224.0.0.5来交换信息

image-20250523163412756

image-20250523163539542

OSPF组播地址 224.0.0.5 的作用
在OSPF协议中,组播地址 224.0.0.5(称为 AllSPFRouters)用于本地网络内的OSPF路由器间通信,具体作用如下:

1. 核心功能
发送OSPF协议报文:
所有运行OSPF的路由器(无论是否为DR/BDR)通过该地址发送以下报文:
Hello报文:发现并维护邻居关系(关键用于邻居发现)。
LSU(链路状态更新):泛洪链路状态信息(当网络类型为广播时,DR通过此地址向所有路由器泛洪更新)。
其他协议报文:包括DD(数据库描述)、LSR(链路状态请求)、LSAck(确认)等。
目标设备:
仅本地网络内运行OSPF的路由器会监听此地址,非OSPF设备直接丢弃。

2. 使用场景
广播网络(如以太网):
非DR/BDR的路由器向DR发送LSU时,使用 224.0.0.6(AllDRouters)。
DR收到后,通过 224.0.0.5 将LSU泛洪给所有路由器。
点对点网络(如PPP链路):
直接通过 224.0.0.5 通信,无需DR/BDR选举。

3. 对比 224.0.0.6(AllDRouters)
组播地址    用途
224.0.0.5    所有OSPF路由器监听,用于泛洪全局更新和邻居通信(如Hello、DR的LSU泛洪)。
224.0.0.6    仅DR/BDR监听,非DR路由器通过此地址向DR/BDR发送LSU(仅在广播网络中使用)。
4. 技术细节
TTL=1:报文仅在本地网络传输,不会跨路由器转发,保证协议报文的安全性。
网络类型影响:
在广播网络中必须通过组播通信(依赖DR/BDR)。
在点对点网络中虽然使用组播地址,但实际等同于单播(仅两个路由器)。

组播地址:
224.0.0.5(AllSPFRouters):所有OSPF路由器监听。
224.0.0.6(AllDRouters):仅DR/BDR监听。
协议报文类型:
Hello报文使用 224.0.0.5 建立邻居关系。
DR在广播网络中通过 224.0.0.5 泛洪LSU。

网络类型与DR角色:
广播网络需要DR/BDR,非DR路由器通过 224.0.0.6 向DR发送更新。
点对点网络无需DR,直接通过 224.0.0.5 通信。

示例场景
场景1:以太网中两台非DR路由器建立邻居:
互相发送Hello报文到 224.0.0.5。

场景2:DR收到非DR的LSU(通过 224.0.0.6)后:
DR通过 224.0.0.5 将LSU泛洪给所有路由器。

5.其他补充

[Huawei]display ospf brief    #查看OSPF的状态
RouterID: 1.1.1.3          Border Router: 
 Multi-VPN-Instance is not enabled
 Global DS-TE Mode: Non-Standard IETF Mode
 Graceful-restart capability: disabled
 Helper support capability  : not configured
 Applications Supported: MPLS Traffic-Engineering 
 Spf-schedule-interval: max 10000ms, start 500ms, hold 1000ms
 Default ASE parameters: Metric: 1 Tag: 1 Type: 2   #外部路由类型2
 Route Preference: 10                #内部优先级
 ASE Route Preference: 150           #外部优先级
 SPF Computation Count: 18    
 RFC 1583 Compatible
 Retransmission limitation is disabled
 Area Count: 1   Nssa Area Count: 0 
 ExChange/Loading Neighbors: 0
 Process total up interface count: 3
 Process valid up interface count: 3
 
 Area: 0.0.0.0          (MPLS TE not enabled)
 Authtype: MD5 #MD4认证   Area flag: Normal
 SPF scheduled Count: 18    
 ExChange/Loading Neighbors: 0
 Router ID conflict state: Normal
 Area interface up count: 3

 Interface: 172.16.0.9 (Serial1/0/0) --> 172.16.0.10
 Cost: 48      State: P-2-P     Type: P2P       MTU: 1500  
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 

 Interface: 172.16.0.6 (Serial1/0/1) --> 172.16.0.5
 Cost: 48      State: P-2-P     Type: P2P       MTU: 1500  
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 

 Interface: 172.16.2.1 (GigabitEthernet0/0/1)
 Cost: 1       State: DR        Type: Broadcast    MTU: 1500  
 Priority: 1      #DR选举优先级
 Designated Router: 172.16.2.1
 Backup Designated Router: 0.0.0.0
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 
#HELLO定时器10秒
#dead定时器10秒
[Huawei]display ospf peer  #查看邻居
[Huawei]display ospf peer

     OSPF Process 1 with Router ID 1.1.1.4
         Neighbors 

 Area 0.0.0.0 interface 172.16.0.18(Serial2/0/0)'s neighbors
 Router ID: 1.1.1.1          Address: 172.16.0.17     
   State: Full  Mode:Nbr is  Slave  Priority: 1
   DR: None   BDR: None   MTU: 0    
   Dead timer due in 33  sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:20:53     
   Authentication Sequence: [ 1626] 

         Neighbors 

 Area 0.0.0.0 interface 172.16.0.13(Serial2/0/1)'s neighbors
 Router ID: 1.1.1.5          Address: 172.16.0.14     
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: None   BDR: None   MTU: 0    
   Dead timer due in 35  sec 
   Retrans timer interval: 0 
   Neighbor is up for 00:19:06     
   Authentication Sequence: [ 1634] 
[Huawei]display ospf lsdb  #查看链路数据库 可以看到链路上的所有路由器
[Huawei]display ospf lsdb

     OSPF Process 1 with Router ID 1.1.1.3
         Link State Database 

                 Area: 0.0.0.0
 Type      LinkState ID    AdvRouter          Age  Len   Sequence   Metric
 Router    1.1.1.3         1.1.1.3           1064  84    8000000A      48
 Router    1.1.1.2         1.1.1.2           1065  72    8000000A      48
 Router    1.1.1.1         1.1.1.1           1410  84    80000006       1
 Router    1.1.1.5         1.1.1.5           1302  72    80000003      48
 Router    1.1.1.4         1.1.1.4           1304  72    80000003      48
[Huawei]display ospf lsdb router #链路数据库里面更详细的信息
[Huawei]display ospf lsdb router

     OSPF Process 1 with Router ID 1.1.1.3
                 Area: 0.0.0.0
         Link State Database 


  Type      : Router
  Ls id     : 1.1.1.3
  Adv rtr   : 1.1.1.3  
  Ls age    : 1207 
  Len       : 84 
  Options   :  E  
  seq#      : 8000000a 
  chksum    : 0x99d2
  Link count: 5                #5条链路状态(3个网段,2个P2P)
   * Link ID: 1.1.1.5      
     Data   : 172.16.0.9       #使用的主机IP
     Link Type: P-2-P          #点对点连接 (包含OSPF设备)  
     Metric : 48               #开销48
   * Link ID: 172.16.0.8       #网段地址
     Data   : 255.255.255.252  #网段
     Link Type: StubNet        #末梢网络(非OSPF设备)
     Metric : 48 
     Priority : Low
   * Link ID: 1.1.1.2      
     Data   : 172.16.0.6   
     Link Type: P-2-P        
     Metric : 48
   * Link ID: 172.16.0.4   
[Huawei]display ip routing-table protocol ospf  #仅显示OSPF的路由表

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注