详解配置静态路由实现路由负载分担(基于路由的负载分担)

小编:迷魂冰 更新时间:2022-04-15
详解配置静态路由实现路由负载分担(基于路由的负载分担)

组网要求:PC1和PC2通过4台三层交换机相连,从拓扑图中可以看出,数据从PC1到PC2有两条路径可以到达,分别是PC1-SW1-SW2-SW4-PC2和PC1-SW3-SW4-PC2,为了有效利用链路,要求从PC1到PC2的数据流平均分配到两条链路上,而且当一条链路故障之后数据流自动切换到另一条链路上去。


视频加载中...

一、本节主要知识点:

静态路由:静态路由是一种需要管理员手工配置的特殊路由。静态路由比动态路由使用更少的带宽,并且不占用CPU资源来计算和分析路由更新。但是当网络发生故障或者拓扑发生变化后,静态路由不会自动更新,必须手动重新配置。静态路由有5个主要的参数:目的地址和掩码、出接口和下一跳、优先级。

使用静态路由的好处是配置简单、可控性高,当网络结构比较简单时,只需配置静态路由就可以使网络正常工作。在复杂网络环境中,还可以通过配置静态路由改进网络的性能,并且可以为重要的应用保证带宽。

注意事项:一般情况下两个设备之间的通信是双向的,因此路由也必须是双向的,在本端配置完静态路由以后,请不要忘记在对端设备上配置回程路由。

在企业网络双出口的场景中,通过配置两条等价的静态路由可以实现负载分担,流量可以均衡地分配到两条不同的链路上;通过配置两条不等价的静态路由可以实现主备份,当主用链路故障的时候流量切换到备用链路上。

重点注意:请确保该场景下互联接口的STP处于未使能状态。因为在使能STP的环形网络中,如果用交换机的VLANIF接口构建三层网络,会导致某个端口被阻塞,从而导致三层业务不能正常运行。

二、配置思路:

1、创建VLAN并配置各接口所属VLAN,配置各VLANIF接口的IP地址。

2、配置数据流来回两个方向的静态路由。

3、在各主机上配置IP地址和默认网关。

三、IP设置:

1、SW1:

VLANif10:192.168.10.254/24 ,vlan10

VLANif20:192.168.20.1/24 ,vlan20

VLANif30:192.168.30.1/24 ,vlan30

PC1:192.168.10.1/24

2、SW2:

VLANif20:192.168.20.2/24 ,vlan20

VLANif50:192.168.50.1/24 ,vlan50

3、SW3:

VLANif30:192.168.30.2/24 ,vlan30

VLANif40:192.168.40.1/24 ,vlan 50

4、SW4:

VLANif40:192.168.40.2/24 ,vlan40

VLANif50:192.168.50.2/24 ,vlan50

VLANif60:192.168.60.254/24 ,vlan60

PC2:192.168.60.1/24

四、SW1交换机的主要配置文件:

#

sysname SW1

#

vlan batch 10 20 30

#

interface Vlanif10

ip address 192.168.10.254 255.255.255.0

#

interface Vlanif20

ip address 192.168.20.1 255.255.255.0

#

interface Vlanif30

ip address 192.168.30.1 255.255.255.0

#

interface MEth0/0/1

#

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 2 to 4094

#

interface GigabitEthernet0/0/3

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

ip route-static 192.168.60.0 255.255.255.0 192.168.30.2

ip route-static 192.168.60.0 255.255.255.0 192.168.20.2

#

return

五、SW2交换机的主要配置文件:

#

sysname SW2

#

vlan batch 20 50

#

interface Vlanif20

ip address 192.168.20.2 255.255.255.0

#

interface Vlanif50

ip address 192.168.50.1 255.255.255.0

#

interface MEth0/0/1

#

interface GigabitEthernet0/0/1

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

interface GigabitEthernet0/0/2

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

ip route-static 192.168.10.0 255.255.255.0 192.168.20.1

ip route-static 192.168.60.0 255.255.255.0 192.168.50.2

#

return

六、SW3交换机的主要配置文件:

#

sysname SW3

#

vlan batch 30 40

#

stp disable //关闭stp破环协议,否则三层业务不能正常运行

#

interface Vlanif30

ip address 192.168.30.2 255.255.255.0

#

interface Vlanif40

ip address 192.168.40.1 255.255.255.0

#

interface MEth0/0/1

#

interface GigabitEthernet0/0/1

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

interface GigabitEthernet0/0/2

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

ip route-static 192.168.10.0 255.255.255.0 192.168.30.1

ip route-static 192.168.60.0 255.255.255.0 192.168.40.2

#

return

七、SW4交换机的主要配置文件:

#

sysname SW4

#

vlan batch 40 50 60

#

interface Vlanif40

ip address 192.168.40.2 255.255.255.0

#

interface Vlanif50

ip address 192.168.50.2 255.255.255.0

#

interface Vlanif60

ip address 192.168.60.254 255.255.255.0

#

interface MEth0/0/1

#

interface GigabitEthernet0/0/1

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

interface GigabitEthernet0/0/2

port link-type trunk

port trunk allow-pass vlan 2 to 4094

#

interface GigabitEthernet0/0/3

port link-type access

port default vlan 60

#

ip route-static 192.168.10.0 255.255.255.0 192.168.40.1

ip route-static 192.168.10.0 255.255.255.0 192.168.50.1

#

return

八、验证配置结果:

1、查看SW1的IP路由表。

[SW1]disp ip routing-table

Route Flags: R - relay, D - download to fib

------------------------------------------------------------------------------

Routing Tables: Public

Destinations : 9 Routes : 10


Destination/Mask Proto Pre Cost Flags NextHop Interface


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.10.0/24 Direct 0 0 D 192.168.10.254 Vlanif10

192.168.10.254/32 Direct 0 0 D 127.0.0.1 Vlanif10

192.168.20.0/24 Direct 0 0 D 192.168.20.1 Vlanif20

192.168.20.1/32 Direct 0 0 D 127.0.0.1 Vlanif20

192.168.30.0/24 Direct 0 0 D 192.168.30.1 Vlanif30

192.168.30.1/32 Direct 0 0 D 127.0.0.1 Vlanif30

192.168.60.0/24 Static 60 0 RD 192.168.30.2 Vlanif30

Static 60 0 RD 192.168.20.2

2、在PC1使用ping命令验证连通性。

PC>ping 192.168.60.1

Ping 192.168.60.1: 32 data bytes, Press Ctrl_C to break

From 192.168.60.1: bytes=32 seq=1 ttl=125 time=94 ms

From 192.168.60.1: bytes=32 seq=2 ttl=125 time=93 ms

From 192.168.60.1: bytes=32 seq=3 ttl=125 time=79 ms

From 192.168.60.1: bytes=32 seq=4 ttl=125 time=62 ms

From 192.168.60.1: bytes=32 seq=5 ttl=125 time=63 ms