概述

1
静态路由的路由备份,就是通过给链路设置优先级来实现的;优先级最大的作为主链路,其余的作为备用链路,当主链路出现故障或断开时,备用链路会自动添加到路由表中使用。

实验拓扑图

拓扑图

配置思路

采用如下的思路配置静态路由实现主备备份:

  • 创建VLAN并配置各接口所属VLAN,配置各VLANIF接口的IP地址。
  • 配置数据流来回两个方向的静态路由。
  • 在各主机上配置IP地址和默认网关。

操作步骤

配置各接口所属VLAN

配置SwitchA,SwitchB,SwitchCSwitchD的配置与SwitchA类似。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan batch 10 100 400
[SwitchA] interface gigabitethernet 0/0/1
[SwitchA-GigabitEthernet0/0/1] port link-type access
[SwitchA-GigabitEthernet0/0/1] port default vlan 10
[SwitchA-GigabitEthernet0/0/1] quit
[SwitchA] interface gigabitethernet 0/0/2
[SwitchA-GigabitEthernet0/0/2] port link-type trunk
[SwitchA-GigabitEthernet0/0/2] port trunk allow-pass vlan 100
[SwitchA-GigabitEthernet0/0/2] quit
[SwitchA] interface gigabitethernet 0/0/3
[SwitchA-GigabitEthernet0/0/3] port link-type trunk
[SwitchA-GigabitEthernet0/0/3] port trunk allow-pass vlan 400
[SwitchA-GigabitEthernet0/0/3] quit

1、配置各VLANIF接口的IP地址

配置SwitchASwitchB、SwitchCSwitchD的配置与SwitchA类似。

1
2
3
4
5
6
7
8
9
[SwitchA] interface vlanif 10
[SwitchA-Vlanif10] ip address 10.1.1.1 24
[SwitchA-Vlanif10] quit
[SwitchA] interface vlanif 100
[SwitchA-Vlanif100] ip address 192.168.12.1 24
[SwitchA-Vlanif100] quit
[SwitchA] interface vlanif 400
[SwitchA-Vlanif400] ip address 192.168.14.1 24
[SwitchA-Vlanif400] quit

2、配置PC1–PC2的去程的静态路由

配置SwitchA

配置两条优先级不同的静态路由,下一跳分别指向SwitchBSwitchD,实现数据流优先发往SwitchB,当去往SwitchB的链路发生故障的时候流量自动切换至SwitchD

1
2
[SwitchA] ip route-static 10.1.2.0 24 192.168.12.2
[SwitchA] ip route-static 10.1.2.0 24 192.168.14.2 preference 70

配置SwitchB

1
[SwitchB] ip route-static 10.1.2.0 24 192.168.23.2

配置SwitchD

1
[SwitchD] ip route-static 10.1.2.0 24 192.168.34.1

3、配置PC1–PC2的回程的静态路由,需要注意数据流来回的路径主备是一致的。

配置SwitchC,配置两条优先级不同的静态路由,下一跳分别指向SwitchBSwitchD,实现数据流优先发往SwitchB,当去往SwitchB的链路发生故障的时候流量自动切换至SwitchD

1
2
[SwitchC] ip route-static 10.1.1.0 24 192.168.23.1
[SwitchC] ip route-static 10.1.1.0 24 192.168.34.2 preference 70

配置SwitchB

1
[SwitchB] ip route-static 10.1.1.0 24 192.168.12.1

配置SwitchD

1
[SwitchD] ip route-static 10.1.1.0 24 192.168.14.1

4、配置主机

配置主机PC1的IP地址为10.1.1.2/24,默认网关为10.1.1.1;配置主机PC2IP地址为10.1.2.2/24,默认网关为10.1.2.1

验证配置结果

查看SwitchA的IP路由表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[SwitchA] display ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 9 Routes : 9

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 Static 60 0 RD 192.168.12.2 Vlanif100
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
192.168.12.0/24 Direct 0 0 D 192.168.12.1 Vlanif100
192.168.12.1/32 Direct 0 0 D 127.0.0.1 Vlanif100
192.168.14.0/24 Direct 0 0 D 192.168.14.1 Vlanif400
192.168.14.1/32 Direct 0 0 D 127.0.0.1 Vlanif400

查看SwitchA的IP路由表详细信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[SwitchA] display ip routing-table 10.1.2.0 24 verbose
Route Flags: R - relay, D - download to fib, T - to vpn-instance
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 2

Destination: 10.1.2.0/24
Protocol: Static Process ID: 0
Preference: 60 Cost: 0
NextHop: 192.168.12.2 Neighbour: 0.0.0.0
State: Active Adv Relied Age: 00h13m13s
Tag: 0 Priority: medium
Label: NULL QoSInfo: 0x0
IndirectID: 0x80000001
RelayNextHop: 0.0.0.0 Interface: Vlanif100
TunnelID: 0x0 Flags: RD

Destination: 10.1.2.0/24
Protocol: Static Process ID: 0
Preference: 70 Cost: 0
NextHop: 192.168.14.2 Neighbour: 0.0.0.0
State: Inactive Adv Relied Age: 00h00m45s
Tag: 0 Priority: medium
Label: NULL QoSInfo: 0x0
IndirectID: 0x80000002
RelayNextHop: 0.0.0.0 Interface: Vlanif400
TunnelID: 0x0 Flags: R
1
从SwitchA的IP路由表中可以看出,到达10.1.2.0/24这个网段仅有一条活跃的路由,链路正常情况下从PC1发往PC2的数据流会优先算则走经过SwitchB的这条路径。从SwitchA的IP路由表详细信可以看出,到达10.1.2.0/24这个网段除了有一条状态为Active的路由,还有一条状态为Inactive的路由,当主用链路故障的时候状态为Inactive的路由就会重新生效,这样流量就能切换到经过SwitchD的这条路径上。这样就能通过静态路由实现路由的主备备份。

配置文件

SwitchA的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
sysname SwitchA
#
vlan batch 10 100 400
#
interface Vlanif10
ip address 10.1.1.1 255.255.255.0
#
interface Vlanif100
ip address 192.168.12.1 255.255.255.0
#
interface Vlanif400
ip address 192.168.14.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 100
#
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan 400
#
ip route-static 10.1.2.0 255.255.255.0 192.168.12.2
ip route-static 10.1.2.0 255.255.255.0 192.168.14.2 preference 70
#
return

SwitchB的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
sysname SwitchB
#
vlan batch 100 200
#
interface Vlanif100
ip address 192.168.12.2 255.255.255.0
#
interface Vlanif200
ip address 192.168.23.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 100
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 200
#
ip route-static 10.1.1.0 255.255.255.0 192.168.12.1
ip route-static 10.1.2.0 255.255.255.0 192.168.23.2
#
return

SwitchC的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
sysname SwitchC
#
vlan batch 20 200 300
#
interface Vlanif20
ip address 10.1.2.1 255.255.255.0
#
interface Vlanif200
ip address 192.168.23.2 255.255.255.0
#
interface Vlanif300
ip address 192.168.34.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 20
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 200
#
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan 300
#
ip route-static 10.1.1.0 255.255.255.0 192.168.23.1
ip route-static 10.1.1.0 255.255.255.0 192.168.34.2 preference 70
#
return

SwitchD的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
sysname SwitchD
#
vlan batch 300 400
#
interface Vlanif300
ip address 192.168.34.2 255.255.255.0
#
interface Vlanif400
ip address 192.168.14.2 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 400
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 300
#
ip route-static 10.1.1.0 255.255.255.0 192.168.14.1
ip route-static 10.1.2.0 255.255.255.0 192.168.34.1
#
return!