三台交换机三张路由表各写各的?华为OSPF基本功能一次配通

本文整理自华为官方发布的典型配置案例,命令与步骤均按原始文档呈现,供现场实施参考。

网络设备一多,静态路由就开始变成灾难:三台交换机两两之间要互指路由,加一台新设备,已有设备全得回头改一遍,漏一条就是一片业务不通。这种"设备会变、网络会长"的环境,正该用动态路由协议 OSPF:每台设备宣告自己的网段,协议自动把路由扩散给邻居,拓扑变了路由跟着自动收敛,人只需要管好"宣告"这一件事。

本文场景:三台交换机要互相通,且计划后续以 SwitchA 和 SwitchB 为主要业务设备继续扩展网络。配置思路是:先在各交换机的 VLANIF 接口配 IP 实现直连网段互通,再配 OSPF 基本功能,并以 SwitchA 为 ABR(区域边界路由器)把 OSPF 网络划成 Area0 和 Area1 两个区域——A、B 所在的骨干区域留着以后扩展,结构一开始就立正。

第一步,配各接口所属 VLAN(以 SwitchA 为例,B、C 类似):

<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan batch 10 20
[SwitchA] interface gigabitethernet 1/0/1
[SwitchA-GigabitEthernet1/0/1] port link-type trunk
[SwitchA-GigabitEthernet1/0/1] port trunk allow-pass vlan 10
[SwitchA-GigabitEthernet1/0/1] quit
[SwitchA] interface gigabitethernet 1/0/2
[SwitchA-GigabitEthernet1/0/2] port link-type trunk
[SwitchA-GigabitEthernet1/0/2] port trunk allow-pass vlan 20
[SwitchA-GigabitEthernet1/0/2] quit

第二步,配 VLANIF 接口 IP:

[SwitchA] interface vlanif 10
[SwitchA-Vlanif10] ip address 192.168.0.1 24
[SwitchA-Vlanif10] quit
[SwitchA] interface vlanif 20
[SwitchA-Vlanif20] ip address 192.168.1.1 24
[SwitchA-Vlanif20] quit

第三步,配 OSPF。SwitchA 上宣告两个网段到两个区域:

[SwitchA] ospf 1 router-id 10.1.1.1
[SwitchA-ospf-1] area 0
[SwitchA-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] quit
[SwitchA-ospf-1] area 1
[SwitchA-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.1] return

SwitchB 只在 Area0:

[SwitchB] ospf 1 router-id 10.2.2.2
[SwitchB-ospf-1] area 0
[SwitchB-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[SwitchB-ospf-1-area-0.0.0.0] return

SwitchC 只在 Area1:

[SwitchC] ospf 1 router-id 10.3.3.3
[SwitchC-ospf-1] area 1
[SwitchC-ospf-1-area-0.0.0.1] network 192.168.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.1] return

两个注意点:router-id 三台必须各不相同,建议手工指定便于排障时一眼认人;network 后面的掩码是反掩码写法,0.0.0.255 对应 24 位。

验证分三层走。第一层看邻居,SwitchA 应与 B、C 各有一条 Full 状态的邻居:

<SwitchA> display ospf peer
          OSPF Process 1 with Router ID 10.1.1.1
                  Neighbors
 Area 0.0.0.0 interface 192.168.0.1(Vlanif10)'s neighbors
Router ID: 10.2.2.2      Address: 192.168.0.2
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 192.168.0.2  BDR: 192.168.0.1   MTU: 0
   Dead timer due in 36  sec
   Retrans timer interval: 5
   Neighbor is up for 00:15:04
   Authentication Sequence: [ 0 ]
                  Neighbors
 Area 0.0.0.1 interface 192.168.1.1(Vlanif20)'s neighbors
Router ID: 10.3.3.3       Address: 192.168.1.2
   State: Full  Mode:Nbr is  Master  Priority: 1
   DR: 192.168.1.2  BDR: 192.168.1.1   MTU: 0
   Dead timer due in 39  sec
   Retrans timer interval: 5
   Neighbor is up for 00:07:32
   Authentication Sequence: [ 0 ]

第二层看路由,SwitchC 应学到区域间路由 192.168.0.0/24:

<SwitchC> display ospf routing
          OSPF Process 1 with Router ID 10.3.3.3
                   Routing Tables
 Routing for Network
 Destination      Cost  Type         NextHop         AdvRouter       Area
 192.168.1.0/24    1    Transit      192.168.1.2     10.3.3.3        0.0.0.1
 192.168.0.0/24    2    Inter-area   192.168.1.1     10.1.1.1        0.0.0.1
 Total Nets: 2
 Intra Area: 1  Inter Area: 1  ASE: 0  NSSA: 0

第三层 ping 通断,SwitchB 打 SwitchC 的 VLANIF 地址:

<SwitchB> ping 192.168.1.2
  PING 192.168.1.2: 56  data bytes, press CTRL_C to break
    Reply from 192.168.1.2: bytes=56 Sequence=1 ttl=253 time=62 ms
    Reply from 192.168.1.2: bytes=56 Sequence=2 ttl=253 time=16 ms
    Reply from 192.168.1.2: bytes=56 Sequence=3 ttl=253 time=62 ms
    Reply from 192.168.1.2: bytes=56 Sequence=4 ttl=253 time=94 ms
    Reply from 192.168.1.2: bytes=56 Sequence=5 ttl=253 time=63 ms
  --- 192.168.1.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 16/59/94 ms

邻居 Full、路由在表、ping 通,三层验证齐了,OSPF 就算配通。这套"宣告即通"的模式往后加设备,只需新设备配好接口和自己的宣告,全网路由自动生成。中小企业多设备组网选动态路由是省心之选,区域怎么划分、以后怎么扩,欢迎找贵州诚鑫致达科技一起把骨架搭稳。

企业存储选型参考|贵州诚鑫致达

做备份容灾一体机方案,群晖机型参考:DP7400 · DP520 · DP320。需要选型建议或上门评估,搜「诚鑫致达」即可找到我们。

服务区域|贵州诚鑫致达

贵州群晖NAS、贵阳存储、数据备份、信创云盘或 IT 集成服务,可联系贵州诚鑫致达科技,服务范围覆盖贵州全省各市州。西南地区多分支企业:跨区域数据集中存储与统一备份。