配置IPv4静态路由示例组网需求
如图1所示,属于不同网段的主机通过几台Switch相连,要求不配置动态路由协议,使不同网段的任意两台主机之间能够互通 。
图1 配置IP静态路由组网图

文章插图
【华为交换机如何配置IPv4静态路由】配置思路
采用如下的思路配置IPv4静态路由:
- 创建VLAN并配置各接口所属VLAN,配置各VLANIF接口的IP地址,实现相邻设备网络互通 。
- 在各主机上配置IP缺省网关,在各台Switch上配置IPv4静态路由或者静态缺省路由,实现不配置动态路由协议,使不同网段的任意两台主机之间能够互通 。
操作步骤
- 配置各接口所属VLAN
- # 配置SwitchA 。SwitchB和SwitchC的配置与SwitchA类似 。
<HUAWEI> system-view[HUAWEI] sysname SwitchA[SwitchA] vlan batch 10 30[SwitchA] interface gigabitethernet 1/0/1[SwitchA-GigabitEthernet1/0/1] port link-type trunk[SwitchA-GigabitEthernet1/0/1] port trunk allow-pass vlan 10[SwitchA-GigabitEthernet1/0/1] quit[SwitchA] interface gigabitethernet 1/0/2[SwitchA-GigabitEthernet1/0/2] port link-type access[SwitchA-GigabitEthernet1/0/2] port default vlan 30[SwitchA-GigabitEthernet1/0/2] quit
- 配置各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] quit
- 配置主机
- 配置主机PC1的缺省网关为10.1.1.1,主机PC2的缺省网关为10.1.2.1,主机PC3的缺省网关为10.1.3.1 。
- 配置静态路由
- # 在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
- 验证配置结果
- #查看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 Interface0.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.1 PING 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.1 traceroute 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配置文件
#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 GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10#interface GigabitEthernet1/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
#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 GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10#interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 20#interface GigabitEthernet1/0/3 port link-type access port default vlan 40#ip route-static 10.1.1.0 255.255.255.0 10.1.4.1ip route-static 10.1.3.0 255.255.255.0 10.1.4.6#return
#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 GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 20#interface GigabitEthernet1/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
推荐阅读
-
四季|海通策略荀玉根:坚持认为四季度市场的行情较好 中短期大金融地产更优
-
-
经济日报|宁德时代携手河南跃薪 打造电动智慧无人矿山新生态
-
-
累计|约翰斯·霍普金斯大学:全球累计新冠确诊病例超过3500万例
-
佳禾国际家政|建议少奶的宝妈收藏,适合坐月子吃的16种食物
-
科技美学:22款新品一同亮相,小米10周年米粉节开幕
-
一点美丽|Dunk 都炒到10w 了?,TS、周董钟爱的“牛仔系列”!这年头牛仔
-
热映电影票房榜,《八角笼中》破10亿,不敌《长安三万里》排第二
-
央视财经|涨涨涨!这里的房价创纪录!两年涨了近三成!咋回事?
-
【小何美食屋】鲜甜脆嫩,美味可口,让味蕾来一次全新的体验,孩子们很抢手的菜
-
波丰娱乐|“我们考虑了每平方毫米”设计出的越野车原来外观这么简单
-
小四的娱乐|林志玲康复后首现身!低扎马尾辫穿灰色连衣裙,46岁状态优雅美
-
制造业|行业唯一,欧派家居连续四年入选中国制造业民营企业500强
-
天冷吃面正合适,教你香气四溢的麻油鸡汤面,营养美味很过瘾
-
-
-
郑州的袁希福医术是真是假,网上水军太多,我想寻一答案?
-
-