
組網需求
如圖1所示,屬于不同網段的主機通過幾台Switch相連,要求不配置動态路由協定,使不同網段的任意兩台主機之間能夠互通。
圖1配置IP靜态路由組網圖
采用如下的思路配置IPv4靜态路由:
- 建立VLAN并配置各接口所屬VLAN,配置各VLANIF接口的IP位址,實作相鄰裝置網絡互通。
- 在各主機上配置IP預設網關,在各台Switch上配置IPv4靜态路由或者靜态預設路由,實作不配置動态路由協定,使不同網段的任意兩台主機之間能夠互通。
-
配置各接口所屬VLAN
# 配置SwitchA。SwitchB和SwitchC的配置與SwitchA類似。
1. <HUAWEI>
system-view2. [HUAWEI]
sysname SwitchA3. [SwitchA]
vlan batch 10 304. [SwitchA]
interface gigabitethernet 0/0/15. [SwitchA-GigabitEthernet0/0/1]
port link-type trunk6. [SwitchA-GigabitEthernet0/0/1]
port trunk allow-pass vlan 107. [SwitchA-GigabitEthernet0/0/1]
quit8. [SwitchA]
interface gigabitethernet 0/0/29. [SwitchA-GigabitEthernet0/0/2]
port link-type access10. [SwitchA-GigabitEthernet0/0/2]
port default vlan 3011. [SwitchA-GigabitEthernet0/0/2]
quit12. 配置各VLANIF接口的IP位址
# 配置SwitchA。SwitchB和SwitchC的配置與SwitchA類似。
[SwitchA]
interface vlanif 10[SwitchA-Vlanif10]
ip address 10.1.4.1 30[SwitchA-Vlanif10]
quit[SwitchA]
interface vlanif 30[SwitchA-Vlanif30]
ip address 10.1.1.1 24[SwitchA-Vlanif30]
quit13. 配置主機
配置主機PC1的預設網關為10.1.1.1,主機PC2的預設網關為10.1.2.1,主機PC3的預設網關為10.1.3.1。
14. 配置靜态路由
# 在SwitchA配置IP預設路由。
[SwitchA]
ip route-static 0.0.0.0 0.0.0.0 10.1.4.2# 在SwitchB配置兩條IP靜态路由。
[SwitchB]
ip route-static 10.1.1.0 255.255.255.0 10.1.4.1[SwitchB]
ip route-static 10.1.3.0 255.255.255.0 10.1.4.6# 在SwitchC配置IP預設路由。
[SwitchC]
ip route-static 0.0.0.0 0.0.0.0 10.1.4.515. 驗證配置結果
#檢視SwitchA的IP路由表。
[SwitchA]
display ip routing-tableRoute Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 Static 60 0 RD 10.1.4.2 Vlanif10
10.1.1.0/24 Direct 0 0 D 10.1.1.1 Vlanif30
10.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif30
10.1.4.0/30 Direct 0 0 D 10.1.4.1 Vlanif10
10.1.4.1/32 Direct 0 0 D 127.0.0.1 Vlanif10
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
# 使用
ping指令驗證連通性。
[SwitchA]
ping 10.1.3.1PING 10.1.3.1: 56 data bytes, press CTRL_C to break
Reply from 10.1.3.1: bytes=56 Sequence=1 ttl=253 time=62 ms
Reply from 10.1.3.1: bytes=56 Sequence=2 ttl=253 time=63 ms
Reply from 10.1.3.1: bytes=56 Sequence=3 ttl=253 time=63 ms
Reply from 10.1.3.1: bytes=56 Sequence=4 ttl=253 time=62 ms
Reply from 10.1.3.1: bytes=56 Sequence=5 ttl=253 time=62 ms
--- 10.1.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/62/63 ms
# 使用Tracert指令驗證連通性。
[SwitchA]
tracert 10.1.3.1traceroute to 10.1.3.1(10.1.3.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 10.1.4.2 31 ms 32 ms 31 ms
2 10.1.3.1 62 ms 63 ms 62 ms
配置檔案SwitchA的配置檔案
#
sysname SwitchA
#
vlan batch 10 30
#
interface Vlanif10
ip address 10.1.4.1 255.255.255.252
#
interface Vlanif30
ip address 10.1.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 30
#
ip route-static 0.0.0.0 0.0.0.0 10.1.4.2
#
return
SwitchB的配置檔案
#
sysname SwitchB
#
vlan batch 10 20 40
#
interface Vlanif10
ip address 10.1.4.2 255.255.255.252
#
interface Vlanif20
ip address 10.1.4.5 255.255.255.252
#
interface Vlanif40
ip address 10.1.2.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 20
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 40
#
ip route-static 10.1.1.0 255.255.255.0 10.1.4.1
ip route-static 10.1.3.0 255.255.255.0 10.1.4.6
#
return
SwitchC的配置檔案
#
sysname SwitchC
#
vlan batch 20 50
#
interface Vlanif20
ip address 10.1.4.6 255.255.255.252
#
interface Vlanif50
ip address 10.1.3.1 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 20
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 50
#
ip route-static 0.0.0.0 0.0.0.0 10.1.4.5
#
return
PS:華為ENSP模拟器下載下傳位址(提取碼:f651 有任何下載下傳安裝問題可以在評論區讨論)