詳解配置靜態(tài)路由實現(xiàn)路由負載分擔(基于路由的負載分擔)

組網(wǎng)要求:PC1和PC2通過4臺三層交換機相連,從拓撲圖中可以看出,數(shù)據(jù)從PC1到PC2有兩條路徑可以到達,分別是PC1-SW1-SW2-SW4-PC2和PC1-SW3-SW4-PC2,為了有效利用鏈路,要求從PC1到PC2的數(shù)據(jù)流平均分配到兩條鏈路上,而且當一條鏈路故障之后數(shù)據(jù)流自動切換到另一條鏈路上去。
一、本節(jié)主要知識點:
靜態(tài)路由:靜態(tài)路由是一種需要管理員手工配置的特殊路由。靜態(tài)路由比動態(tài)路由使用更少的帶寬,并且不占用CPU資源來計算和分析路由更新。但是當網(wǎng)絡(luò)發(fā)生故障或者拓撲發(fā)生變化后,靜態(tài)路由不會自動更新,必須手動重新配置。靜態(tài)路由有5個主要的參數(shù):目的地址和掩碼、出接口和下一跳、優(yōu)先級。
使用靜態(tài)路由的好處是配置簡單、可控性高,當網(wǎng)絡(luò)結(jié)構(gòu)比較簡單時,只需配置靜態(tài)路由就可以使網(wǎng)絡(luò)正常工作。在復雜網(wǎng)絡(luò)環(huán)境中,還可以通過配置靜態(tài)路由改進網(wǎng)絡(luò)的性能,并且可以為重要的應(yīng)用保證帶寬。
注意事項:一般情況下兩個設(shè)備之間的通信是雙向的,因此路由也必須是雙向的,在本端配置完靜態(tài)路由以后,請不要忘記在對端設(shè)備上配置回程路由。
在企業(yè)網(wǎng)絡(luò)雙出口的場景中,通過配置兩條等價的靜態(tài)路由可以實現(xiàn)負載分擔,流量可以均衡地分配到兩條不同的鏈路上;通過配置兩條不等價的靜態(tài)路由可以實現(xiàn)主備份,當主用鏈路故障的時候流量切換到備用鏈路上。
重點注意:請確保該場景下互聯(lián)接口的STP處于未使能狀態(tài)。因為在使能STP的環(huán)形網(wǎng)絡(luò)中,如果用交換機的VLANIF接口構(gòu)建三層網(wǎng)絡(luò),會導致某個端口被阻塞,從而導致三層業(yè)務(wù)不能正常運行。
二、配置思路:
1、創(chuàng)建VLAN并配置各接口所屬VLAN,配置各VLANIF接口的IP地址。
2、配置數(shù)據(jù)流來回兩個方向的靜態(tài)路由。
3、在各主機上配置IP地址和默認網(wǎng)關(guān)。
三、IP設(shè)置:
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 //關(guān)閉stp破環(huán)協(xié)議,否則三層業(yè)務(wù)不能正常運行
#
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
八、驗證配置結(jié)果:
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