不同网段的任意两台主机之间能够互通之静态路由命令
一般情况下两个设备之间的通信是双向的,因此路由也必须是双向的,在本端配置完静态路由以后,请不要忘记在对端设备上配置回程路由。
在不同网段的主机通过几台Switch相连,要求不配置动态路由协议,使不同网段的任意两台主机之间能够互通。
网络拓扑图
1.创建VLAN并配置各接口所属VLAN,配置各VLANIF接口的IP地址,实现相邻设备网络互通。
2.在各主机上配置IP缺省网关,在各台Switch上配置IPv4静态路由或者静态缺省路由,使不同网段的任意两台主机之间能够互通。
操作步骤
1.配置各接口所属VLAN
# 配置SwitchA
<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan batch 10 30
[SwitchA] interface gigabitethernet 0/0/1
[SwitchA-GigabitEthernet0/0/1] port link-type trunk
[SwitchA-GigabitEthernet0/0/1] port trunk allow-pass vlan 10
[SwitchA-GigabitEthernet0/0/1] quit
[SwitchA] interface gigabitethernet 0/0/2
[SwitchA-GigabitEthernet0/0/2] port link-type access
[SwitchA-GigabitEthernet0/0/2] port default vlan 30
[SwitchA-GigabitEthernet0/0/2] quit
# 配置SwitchB
<HUAWEI> system-view
[HUAWEI] sysname SwitchB
[SwitchB] vlan batch 10 20 40
[SwitchB] interface gigabitethernet 0/0/1
[SwitchB -GigabitEthernet0/0/1] port link-type trunk
[SwitchB -GigabitEthernet0/0/1] port trunk allow-pass vlan 10
[SwitchB -GigabitEthernet0/0/1] quit
[SwitchB] interface gigabitethernet 0/0/3
[SwitchB -GigabitEthernet0/0/2] port link-type access
[SwitchB -GigabitEthernet0/0/2] port default vlan 40
[SwitchB -GigabitEthernet0/0/2] quit
[SwitchB] interface gigabitethernet 0/0/2
[SwitchB -GigabitEthernet0/0/1] port link-type trunk
[SwitchB -GigabitEthernet0/0/1] port trunk allow-pass vlan 30
[SwitchB -GigabitEthernet0/0/2] quit
# 配置SwitchC
<UAWEI> system-view
[HUAWEI] sysname SwitchC
[SwitchC] vlan batch 20 50
[SwitchC] interface gigabitethernet 0/0/1
[SwitchC-GigabitEthernet0/0/1] port link-type trunk
[SwitchC-GigabitEthernet0/0/1] port trunk allow-pass vlan 20
[SwitchC-GigabitEthernet0/0/1] quit
[SwitchC] interface gigabitethernet 0/0/2
[SwitchC-GigabitEthernet0/0/2] port link-type access
[SwitchC-GigabitEthernet0/0/2] port default vlan 50
[SwitchC-GigabitEthernet0/0/2] quit
2.配置各VLANIF接口的IP地址
# 配置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] quit
# 配置SwitchB
[SwitchB] interface vlanif 10
[SwitchB-Vlanif10] ip address 10.1.4.2 30
[SwitchB-Vlanif10] quit
[SwitchB] interface vlanif 40
[SwitchB-Vlanif30] ip address 10.1.2.1 24
[SwitchB-Vlanif30] quit
[SwitchB] interface vlanif 20
[SwitchB-Vlanif30] ip address 10.1.4.5 30
# 配置SwitchC
[SwitchC] interface vlanif 20
[SwitchC-Vlanif10] ip address 10.1.4.6 30
[SwitchC-Vlanif10] quit
[SwitchC] interface vlanif 50
[SwitchC-Vlanif30] ip address 10.1.3.1 24
[SwitchC-Vlanif30] quit
3.配置主机
配置主机PC1的缺省网关为10.1.1.1,主机PC2的缺省网关为10.1.2.1,主机PC3的缺省网关为10.1.3.1。
4.配置静态路由
# 在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.5
5.验证配置结果
#使用Tracert命令查看主机10.1.3.2到主机10.1.1.2经过的路径
到10.1.1.2主机经过的路径
#使用ping命令检查主机10.1.3.2到其他主机的连通性
测试结果
#使用Tracert命令查看主机10.1.1.2到主机10.1.3.2经过的路径
测试结果