靜態路由
1)特點:
由管理員手工配置的,是單向的,因此需要在兩個網絡之間的邊緣路由器上需要雙方對指,否則就會造成流量有去無回,缺乏靈活性,適用於小型網絡。
2)配置
全局模式:
ip route-static 目標網絡ID 子網掩碼 下一跳IP
實驗目的:
實現兩個不同網絡間互通
實驗拓撲: //今天的拓撲圖可能有點亂,因爲害怕有人看不懂,所以做了些標註,望諒解 0^0
實驗思路:
兩網絡間通信,任意一網絡數據到達網關處需在路由器中查找路由表,找到通往目標網段的最佳路徑。但顯然現路由器中沒有通往另一網絡的路由條目,所以作爲管理員我們可以手動添加。此處我們可以爲路由器配置靜態路由。
實驗步驟:
#華爲
PC機:PC1:192.168.1.1
255.255.255.0
192.168.1.254
PC2:192.168.4.1
255.255.255.0
192.168.4.254
路由器:
R1:
將路由器重命名爲R1
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R1
給端口g0/0/2配置IP地址:192.168.1.254/24
[R1]interface GigabitEthernet 0/0/2
[R1-GigabitEthernet0/0/2]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
給端口g0/0/0配置IP地址:192.168.2.1/24
[R1-GigabitEthernet0/0/2]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.2.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]quit
配置靜態路由:0.0.0.0 0.0.0.0 192.168.2.254
[R1]ip route-static 0.0.0.0 0.0.0.0 192.168.2.254
R2:
將路由器重命名爲R2
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2
給端口g0/0/0配置IP地址:192.168.2.254/24
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.2.254 24
[R2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
給端口g0/0/1配置IP地址:192.168.3.1/24
[R2-GigabitEthernet0/0/0]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.3.1 24
[R2-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R2-GigabitEthernet0/0/1]quit
配置靜態路由:192.168.1.0 255.255.255.0 192.168.2.1 (華爲也可用24代替255.255.255.0)
192.168.4.0 24 192.168.3.254
[R2]ip route-static 192.168.1.0 255.255.255.0 192.168.2.1
192.168.4.0 24 192.168.3.254
R3:
將路由器重命名爲R3
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R3
給端口g0/0/1配置IP地址:192.168.3.254/24
[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 192.168.3.254 24
[R3-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
給端口g0/0/2配置IP地址:192.168.4.254/24
[R3-GigabitEthernet0/0/1]interface GigabitEthernet 0/0/2
[R3-GigabitEthernet0/0/2]ip address 192.168.4.254 24
[R3-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[R3-GigabitEthernet0/0/2]quit
配置靜態路由:0.0.0.0 0.0.0.0 192.168.3.1
[R3]ip route-static 0.0.0.0 0.0.0.0 192.168.3.1
驗證,測試,保存
驗證:<R1>display ip routing-table //查看路由表
<R2>display ip routing-table
<R3>display ip routing-table
測試: PC1:ping 192.168.4.1
PC2:ping 192.168.1.1
保存: <R1>save
Are you sure to continue?(y/n)[n]: y
#思科
PC配置同華爲;
路由器:
R1:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
給端口g0/2配置IP地址:192.168.1.254/24
R1(config)#interface gigabitEthernet 0/2
R1(config-if)#ip address 192.168.1.254 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
給端口g0/0配置IP地址:192.168.2.1/24
R1(config)#interface gigabitEthernet 0/0
R1(config-if)#ip address 192.168.2.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
配置靜態路由
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.254
R2:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R2
給端口g0/0配置IP地址:192.168.2.254/24
R2(config)#interface gigabitEthernet 0/0
R2(config-if)#ip address 192.168.2.254 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
給端口g0/1配置IP地址:192.168.3.1/24
R2(config)#interface gigabitEthernet 0/1
R2(config-if)#ip address 192.168.3.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
配置靜態路由
R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.254
R3:
重命名
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R3
給端口g0/1配置IP地址:192.168.3.254/24
R3(config)#interface gigabitEthernet 0/1
R3(config-if)#ip address 192.168.3.254 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
給端口g0/2配置IP地址:192.168.4.254/24
R3(config)#interface gigabitEthernet 0/2
R3(config-if)#ip address 192.168.4.254 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
配置靜態路由
R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.1
驗證,測試,保存
驗證:<R1>show ip route //查看路由表
<R2>show ip route //查看路由表
<R3>show ip route //查看路由表
測試:PC1:ping 192.168.4.1
PC2 : ping 192.168.1.1
保存:<R1>write
<R2>write
<R3>write