Huawei 交换机配置命令速查手册
1. 基础环境准备
前提条件
- 已连接控制台(Console)或远程登录
- 拥有 Admin 或更高权限
- 重要:对于新设备,建议先禁用 ZTP(零配置上线)以避免配置冲突
禁用 ZTP (新设备/重置后推荐)
⚠️ 注意:S6750 等较新设备默认开启 ZTP,会锁定配置导致报错
The system is busy in building system configurations
bash
<HUAWEI> set ztp disable
<HUAWEI> reboot系统基本参数
bash
# 进入系统视图
system-view
# 设置设备名称
sysname Switch-Core
# 设置时区 (北京时间)
clock timezone Beijing add 08:00:00
# 配置NTP (建议配置)
ntp-service server-client
ntp-service unicast-server 192.168.1.1232. 端口与 VLAN 配置
创建 VLAN
bash
# 单个创建
vlan 10
name Management
quit
# 批量创建
vlan batch 20 30 40端口类型配置
Access 端口 (连接终端)
bash
interface GigabitEthernet 1/0/1
description Link-to-PC
port link-type access
port default vlan 10
quitTrunk 端口 (连接交换机/AP)
bash
interface GigabitEthernet 1/0/24
description Link-to-Core
port link-type trunk
port trunk allow-pass vlan 10 20 30
# 注意:默认VLAN1通常允许通过,视安全需求修剪
quitVLANIF 接口 (三层网关)
bash
interface Vlanif 10
description Gateway_VLAN10
ip address 192.168.10.254 255.255.255.0
quit3. 链路聚合 (Eth-Trunk)
创建 LACP 聚合组
bash
interface Eth-Trunk 1
mode lacp
description Link-Aggregation-Uplink
# 配置负载分担方式 (根据源目的MAC)
load-balance src-dst-mac
quit物理成员加入
bash
# 方法一:在物理接口下加入
interface GigabitEthernet 1/0/1
eth-trunk 1
quit
interface GigabitEthernet 1/0/2
eth-trunk 1
quit聚合口业务配置
bash
interface Eth-Trunk 1
port link-type trunk
port trunk allow-pass vlan 10 20
quit4. 智能堆叠 (iStack) 配置
实战经验总结
- 硬件要求:确认端口是否支持堆叠(如 S6750 需用 25GE/40GE/100GE,不支持普通 10GE)
- 物理拓扑:必须采用交叉连接(Switch1-Port1 连接 Switch2-Port2)
- 配置顺序:先软配置,保存,关机,连线,开机
第一步:主交换机配置 (Master)
bash
# 1. 配置优先级 (值越大越优先,默认100)
stack member 1 priority 200
# 2. 创建堆叠口并加入物理成员
interface stack-port 1/1
port member-group interface 25GE 1/0/7
quit
interface stack-port 1/2
port member-group interface 25GE 1/0/8
quit
# 3. 保存
save第二步:备交换机配置 (Standby)
bash
# 1. 修改堆叠ID (避免冲突,重启生效)
stack member 1 renumber 2
quit
# 需要先重启一次使ID生效,再进行后续配置
reboot
# --- 重启后登录 ---
# 2. 配置堆叠口 (注意此时Slot ID已变为2)
interface stack-port 2/1
port member-group interface 25GE 2/0/7
quit
interface stack-port 2/2
port member-group interface 25GE 2/0/8
quit
# 3. 保存并重启
save
reboot第三步:多主检测 (BFD-MAD) 配置
防止堆叠线断开后出现"脑裂"(两台设备IP MAC冲突)
bash
# 1. 配置主设备检测口
interface 10GE 1/0/14
dual-active detect mode direct
quit
# 2. 配置备设备检测口
interface 10GE 2/0/14
dual-active detect mode direct
quit
# 3. (可选) 配置备份管理IP
interface meth 0/0/0
dual-active backup ip address 192.168.254.1 24 member 1
dual-active backup ip address 192.168.254.2 24 member 2
quit5. 路由配置
静态路由
bash
# 默认路由
ip route-static 0.0.0.0 0.0.0.0 192.168.10.1
# 指向特定网段
ip route-static 10.0.0.0 255.0.0.0 192.168.10.254OSPF 动态路由
bash
# 启动进程
ospf 1 router-id 1.1.1.1
# 区域配置与网段宣告
area 0.0.0.0
network 192.168.10.0 0.0.0.255
quit
# (可选) 接口下直接启用
interface Vlanif 20
ospf enable 1 area 0.0.0.0
quit6. 安全与远程管理
SSH 远程登录 (推荐)
bash
# 开启服务
stelnet server enable
# 创建用户
aaa
local-user admin password cipher YourStrongPass@123
local-user admin privilege level 15
local-user admin service-type ssh terminal
quit
# 配置认证模式
ssh user admin authentication-type password
ssh user admin service-type stelnet
# 应用到 VTY 线路
user-interface vty 0 4
authentication-mode aaa
protocol inbound ssh
quit端口安全 (Port Security)
bash
interface GigabitEthernet 1/0/10
# 限制MAC地址数量并粘滞学习
port-security enable
port-security max-mac-count 5
port-security mac-address sticky
quitDHCP Snooping (防私接路由)
bash
# 全局开启
dhcp snooping enable
# 接入侧配置
vlan 10
dhcp snooping enable
quit
# 上联/服务器侧配置信任
interface GigabitEthernet 1/0/1
dhcp snooping trusted
quitACL 访问控制
bash
# 定义规则
acl number 3000
rule 5 permit ip source 192.168.10.0 0.0.0.255 destination 10.0.0.0 0.255.255.255
rule 10 deny ip source any
quit
# 应用规则 (Outbound/Inbound)
interface GigabitEthernet 1/0/24
traffic-filter outbound acl 3000
quit7. 高级功能 (MSTP & QoS)
MSTP (多生成树)
bash
stp mode mstp
stp region-configuration
region-name Huawei-Net
instance 1 vlan 10 20
instance 2 vlan 30 40
active region-configuration
quit
# 配置根桥优先级
stp instance 1 priority 4096
stp instance 2 priority 8192QoS (限速示例)
bash
# 1. 流分类
traffic classifier C1
if-match vlan-id 10
quit
# 2. 流行为 (限宽 20Mbps)
traffic behavior B1
car cir 20480
quit
# 3. 流策略
traffic policy P1
classifier C1 behavior B1
quit
# 4. 接口应用
interface GigabitEthernet 1/0/1
traffic-policy P1 inbound
quit8. 维护与排错
常用查看命令
bash
# 状态概览
display device # 查看硬件状态/堆叠成员
display interface brief # 接口简要状态
display ip routing-table # 路由表
# 堆叠专用
display stack # 查看堆叠拓扑
display stack peers # 查看邻居信息
display stack port # 查看堆叠口状态
# 业务信息
display vlan
display mac-address
display arp
display eth-trunk故障诊断
bash
# 连通性测试
ping -c 5 192.168.10.1
tracert 192.168.10.1
# 日志与告警
display logbuffer # 查看日志缓冲区
display alarm active # 查看当前活动告警
display diagnostic-information # 收集所有诊断信息(慎用,输出量大)配置文件管理
bash
# 保存配置
save
# 备份配置
display current-configuration > backup_2023.cfg
# 恢复/设置下次启动配置
startup saved-configuration backup_2023.cfg
# 重启设备
reboot