🧭 引言:这是一份救命的交换机运维秘籍
在交换机配置与故障排查过程中,不论你是初入网络世界的小白,还是年资数年的资深工程师,总会遇到那些“关键时刻靠得住的命令”。
这篇文章,我将整理一份覆盖华为 + 思科双平台的实战命令手册,从最基础的设备状态查看,到 VLAN、STP、防环、LACP、QOS、抓包、限速、安全加固等操作,通通囊括。
关键时刻,拿来即用,就是这篇的全部意义。
01️⃣ 基础生存命令:先活下来再说
场景 | 华为命令 | 思科命令 |
---|---|---|
查看接口状态 | display interface brief | show ip interface brief |
查看运行配置 | display current-configuration | show running-config |
查看设备版本 | display version | show version |
查看 ARP 表 | display arp | show arp |
查看 MAC 表 | display mac-address | show mac address-table |
💡 小技巧:
华为命令起手就是 display
,思科几乎都是 show
,命令输错就看不到结果,小心别混了!
02️⃣ VLAN操作四神技:配置没它不行
✅ 1. 创建 VLAN + 分配端口
华为:
[Huawei] vlan 10
[Huawei-vlan10] description IT_DEPT
[Huawei] interface GigabitEthernet0/0/1
[Huawei-GigabitEthernet0/0/1] port link-type access
[Huawei-GigabitEthernet0/0/1] port default vlan 10
思科:
Switch(config)# vlan 10
Switch(config-vlan)# name IT_DEPT
Switch(config)# interface GigabitEthernet1/0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
✅ 2. 批量端口配置(华为独家)
[Huawei] port-group 1
[Huawei-port-group-1] group-member GigabitEthernet 0/0/1 to 0/0/24
[Huawei-port-group-1] port link-type trunk
[Huawei-port-group-1] port trunk allow-pass vlan 10 20
03️⃣ 端口安全三板斧:防住最常见的端口事故
✅ 1. MAC泛洪防护
华为:
[Huawei] interface GigabitEthernet0/0/1
[Huawei-GigabitEthernet0/0/1] port-security enable
[Huawei-GigabitEthernet0/0/1] port-security max-mac-num 5
思科:
Switch(config-if)# switchport port-security
Switch(config-if)# switchport port-security maximum 5
✅ 2. 意外关闭端口紧急恢复
华为:
[Huawei-GigabitEthernet0/0/1] undo shutdown
思科:
Switch(config-if)# no shutdown
04️⃣ STP防环:预防网络自爆的关键机制
✅ 1. 根桥优先选举
华为:
[Huawei] stp root primary # 设置主根桥
[Huawei] stp root secondary # 设置备份根桥
思科:
Switch(config)# spanning-tree vlan 1 root primary
✅ 2. 查看 STP 状态
华为:
display stp brief
思科:
show spanning-tree brief
🎯 重点状态:
Forwarding
:转发正常Blocking
:端口被阻塞,注意是否配置合理
05️⃣ 链路聚合 LACP:提速+备份,一招两用
✅ 华为配置:
[Huawei] interface Eth-Trunk1
[Huawei-Eth-Trunk1] mode lacp
[Huawei-Eth-Trunk1] trunkport GigabitEthernet 0/0/23 to 0/0/24
[Huawei-Eth-Trunk1] port link-type trunk
[Huawei-Eth-Trunk1] port trunk allow-pass vlan 10
✅ 思科配置:
Switch(config)# interface port-channel1
Switch(config-if)# channel-group 1 mode active
Switch(config-if)# switchport mode trunk
Switch(config)# interface range Gig1/0/23-24
Switch(config-if-range)# channel-group 1 mode active
06️⃣ QOS限速:为关键业务“让路”
✅ 华为:基于端口
[Huawei] interface GigabitEthernet0/0/1
[Huawei-GigabitEthernet0/0/1] qos lr outbound cir 10000 # 10Mbps
✅ 思科:基于ACL策略
Switch(config)# access-list 100 permit ip any any
Switch(config)# class-map CLASS_10M
Switch(config-cmap)# match access-group 100
Switch(config)# policy-map POLICE_10M
Switch(config-pmap)# class CLASS_10M
Switch(config-pmap-c)# police 10000000 1500 conform-action transmit exceed-action drop
Switch(config)# interface Gig1/0/1
Switch(config-if)# service-policy input POLICE_10M
07️⃣ 排错神命令合集:抓住问题根源才是高手
✅ 网络环路检测
- 华为:
display loop-detect
- 思科:
show spanning-tree inconsistentports
✅ 查看错误包
- 华为:
display interface GigabitEthernet0/0/1 | include errors
- 思科:
show interfaces Gig1/0/1 | include errors
✅ 抓包配置(SPAN)
华为镜像端口配置:
[Huawei] observe-port 1 interface GigabitEthernet0/0/24
[Huawei] interface GigabitEthernet0/0/1
[Huawei-GigabitEthernet0/0/1] mirror to observe-port 1
思科SPAN配置:
Switch(config)# monitor session 1 source interface Gig1/0/1
Switch(config)# monitor session 1 destination interface Gig1/0/24
08️⃣ 安全加固:交换机的“隐形盾牌”
✅ 关闭高风险服务(如 telnet / http)
华为:
[Huawei] undo http server enable
[Huawei] undo telnet server enable
思科:
Switch(config)# no ip http server
Switch(config)# line vty 0 4
Switch(config-line)# transport input ssh
✅ 登录失败锁定机制
华为:
[Huawei] user-interface console 0
[Huawei-ui-console0] authentication-mode password
[Huawei-ui-console0] set authentication password cipher Admin@2024
思科:
Switch(config)# login block-for 300 attempts 3 within 60
🚨 高危命令提示 ⚠️
- 🧨
reset saved-configuration
(华为) &write erase
(思科) = 清空配置,慎用! - 💾 变更前记得保存:
- 华为:
save
- 思科:
copy running-config startup-config
- 华为:
- 🔒 三类高危操作:端口关闭、VLAN 删除、ACL 应用,执行前务必三思!
✅ 写在最后:做运维,不怕出事,怕的是没准备
很多时候,真正拉你一把的不是“高深理论”,而是你手里有没有一份靠得住的命令速查表。
这篇文章,希望能成为你“进可调试,退可排障”的一份救命卡片。
📌免费备考资料分享(华为数通IA、IP、IE)
为了帮助更多考生高效备考,我根据自己的学习经验,整理了以下几个核心备考资料:
-
考试大纲:
覆盖HCIE笔试和实验考试的所有重点知识,帮助你精准掌握考试范围,避免盲目学习。 -
培训教材:
详细的理论知识和案例分析,核心技术的深入解析,是夯实基础的不二之选。 -
实验手册:
实验考试配置命令速查手册和模拟实验案例集,涵盖关键场景,助你在实验环节高效应对。
💬获取方式:
如果你需要这些备考资料,可以在评论区留言或者私信我,我会将资料打包发给你,希望对你的备考有所帮助!