詳解配置靜態路由實現路由負載分擔(基于路由的負載分擔)

組網要求: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