配置OSPF负载分担

组网需求:网络

    OSPF网络中有四台交换机,同属于区域0。要求配置负载分担,使得SwitchA流量,能够分别经过SwitchB和SwitchC送到SwitchD。负载均衡

拓扑:ide

wKioL1l37cGw11A0AABMC5XrSLU164.jpg-wh_50

配置思路oop

采用以下的思路配置OSPF的负载分担:ui

  1. 在各交换机上配置OSPF基本功能,实现OSPF网络的基本互通。spa

  2. 在SwitchA配置负载分担,实现负载均衡的目的。router

操做步骤blog

  • 配置各接口所属VLAN接口

# 配置SwitchA。SwitchB、SwitchC和SwitchD的配置与SwitchA相似ip

<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan batch 10 20 50
[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
[SwitchA] interface gigabitethernet 1/0/3
[SwitchA-GigabitEthernet1/0/3] port link-type trunk
[SwitchA-GigabitEthernet1/0/3] port trunk allow-pass vlan 50
[SwitchA-GigabitEthernet1/0/3] quit

  • 配置各VLANIF接口的IP地址

# 配置SwitchA。SwitchB、SwitchC和SwitchD的配置与SwitchA相似。

[SwitchA] interface vlanif 10
[SwitchA-Vlanif10] ip address 10.1.1.1 24
[SwitchA-Vlanif10] quit
[SwitchA] interface vlanif 20
[SwitchA-Vlanif20] ip address 10.1.2.1 24
[SwitchA-Vlanif20] quit
[SwitchA] interface vlanif 50
[SwitchA-Vlanif50] ip address 172.16.1.1 24
[SwitchA-Vlanif50] quit

  • 配置OSPF基本功能

# 配置SwitchA。

[SwitchA] ospf 1 router-id 10.10.10.1
[SwitchA-ospf-1] area 0
[SwitchA-ospf-1-area-0.0.0.0] network 172.16.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] network 10.1.2.0 0.0.0.255
[SwitchA-ospf-1-area-0.0.0.0] quit
[SwitchA-ospf-1] quit

# 配置SwitchB。

[SwitchB] ospf 1 router-id 10.10.10.2
[SwitchB-ospf-1] area 0
[SwitchB-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[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] quit
[SwitchB-ospf-1] quit

# 配置SwitchC。

[SwitchC] ospf 1 router-id 10.10.10.3
[SwitchC-ospf-1] area 0
[SwitchC-ospf-1-area-0.0.0.0] network 10.1.2.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
[SwitchC-ospf-1-area-0.0.0.0] quit
[SwitchC-ospf-1] quit

# 配置SwitchD。

[SwitchD] ospf 1 router-id 10.10.10.4
[SwitchD-ospf-1] area 0
[SwitchD-ospf-1-area-0.0.0.0] network 192.168.0.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.0] network 172.17.1.0 0.0.0.255
[SwitchD-ospf-1-area-0.0.0.0] quit
[SwitchD-ospf-1] quit

# 查看SwitchA的路由表。

[SwitchA] display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 11       Routes : 12

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.1.1.0/24  Direct  0    0           D   10.1.1.1        Vlanif10
       10.1.1.1/32  Direct  0    0           D   127.0.0.1       Vlanif10
       10.1.2.0/24  Direct  0    0           D   10.1.2.1        Vlanif20
       10.1.2.1/32  Direct  0    0           D   127.0.0.1       Vlanif20
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Direct  0    0           D   172.16.1.1      Vlanif50
     172.16.1.1/32  Direct  0    0           D   127.0.0.1       Vlanif50
     172.17.1.0/24  OSPF    10   3           D   10.1.1.2        Vlanif10
                    OSPF    10   3           D   10.1.2.2        Vlanif20
    192.168.0.0/24  OSPF    10   2           D   10.1.1.2        Vlanif10
    192.168.1.0/24  OSPF    10   2           D   10.1.2.2        Vlanif20

从路由表能够看出,因为最大等价路由条数的缺省值为16,所以SwitchA的两个下一跳10.1.1.2(SwitchB)和10.1.2.2(SwitchC)均成为有效路由。

  • SwitchA上配置等价路由优先级

若是不但愿SwitchB和SwitchC造成负载分担,能够配置等价路由优先级,指定下一跳。

[SwitchA] ospf 1
[SwitchA-ospf-1] nexthop 10.1.2.2 weight 1
[SwitchA-ospf-1] quit

# 查看SwitchA的路由表

[SwitchA] display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 11       Routes : 11

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.1.1.0/24  Direct  0    0           D   10.1.1.1        Vlanif10
       10.1.1.1/32  Direct  0    0           D   127.0.0.1       Vlanif10
       10.1.2.0/24  Direct  0    0           D   10.1.2.1        Vlanif20
       10.1.2.1/32  Direct  0    0           D   127.0.0.1       Vlanif20
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Direct  0    0           D   172.16.1.1      Vlanif50
     172.16.1.1/32  Direct  0    0           D   127.0.0.1       Vlanif50
     172.17.1.0/24  OSPF    10   3           D   10.1.2.2        Vlanif20
    192.168.0.0/24  OSPF    10   2           D   10.1.1.2        Vlanif10
    192.168.1.0/24  OSPF    10   2           D   10.1.2.2        Vlanif20

从路由表中能够看出,当配置等价路由的优先级后,因为下一跳为10.1.2.2(SwitchC)的优先级(权值为1)高于下一跳为10.1.1.2(SwitchB)的优先级,因此OSPF优先选择下一跳为10.1.2.2为惟一最优路由。