华为交换机典型配置命令手册

目录

  1. 基础配置命令
  2. VLAN 配置
  3. 链路聚合
  4. 生成树协议
  5. 路由配置
  6. ACL 访问控制
  7. QoS 配置
  8. 安全配置
  9. 管理与维护

1. 基础配置命令

1.1 登录与视图切换

1
2
3
4
5
6
7
8
9
10
11
12
# 通过 Console 口登录
<Huawei> system-view # 进入系统视图
[Huawei] sysname SW1 # 修改设备名称
[SW1] quit # 退出当前视图
[SW1] return # 直接返回用户视图

# 视图层级
用户视图 <Huawei> # 查看状态,不能配置
系统视图 [Huawei] # 全局配置
接口视图 [Huawei-GigabitEthernet0/0/1]
VLAN 视图 [Huawei-vlan10]
协议视图 [Huawei-stp]

1.2 接口基础配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 进入接口视图
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1]

# 配置接口描述
[SW1-GigabitEthernet0/0/1] description To_PC1

# 配置接口速率和双工模式
[SW1-GigabitEthernet0/0/1] speed 1000 # 10/100/1000/auto
[SW1-GigabitEthernet0/0/1] duplex full # full/half/auto

# 开启/关闭接口
[SW1-GigabitEthernet0/0/1] undo shutdown
[SW1-GigabitEthernet0/0/1] shutdown

# 查看接口状态
[SW1] display interface GigabitEthernet 0/0/1
[SW1] display interface brief # 查看简要信息

1.3 接口类型配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Access 端口(连接终端)
[SW1-GigabitEthernet0/0/1] port link-type access
[SW1-GigabitEthernet0/0/1] port default vlan 10

# Trunk 端口(连接交换机)
[SW1-GigabitEthernet0/0/2] port link-type trunk
[SW1-GigabitEthernet0/0/2] port trunk allow-pass vlan 10 20 30
[SW1-GigabitEthernet0/0/2] port trunk pvid vlan 1

# Hybrid 端口(灵活 tagging)
[SW1-GigabitEthernet0/0/3] port link-type hybrid
[SW1-GigabitEthernet0/0/3] port hybrid pvid vlan 10
[SW1-GigabitEthernet0/0/3] port hybrid untagged vlan 10 20
[SW1-GigabitEthernet0/0/3] port hybrid tagged vlan 30 40

# 恢复接口默认配置
[SW1] clear configuration interface GigabitEthernet 0/0/1

1.4 设备管理配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 配置系统时间
[SW1] clock timezone Beijing add 08:00:00
[SW1] clock datetime 14:30:00 2024-01-15

# 配置设备名称和描述
[SW1] sysname Core-SW1
[SW1] info-center enable # 开启信息中心

# 保存配置
<SW1> save
<SW1> save config.cfg # 指定文件名

# 查看配置
<SW1> display current-configuration # 查看当前配置
<SW1> display saved-configuration # 查看保存的配置

2. VLAN 配置

2.1 创建 VLAN

1
2
3
4
5
6
7
8
9
10
11
12
13
# 创建单个 VLAN
[SW1] vlan 10
[SW1-vlan10] description HR_Department
[SW1-vlan10] quit

# 批量创建 VLAN
[SW1] vlan batch 10 20 30 # 创建多个不连续 VLAN
[SW1] vlan batch 10 to 50 # 创建连续 VLAN

# 查看 VLAN 信息
[SW1] display vlan # 查看所有 VLAN
[SW1] display vlan 10 # 查看特定 VLAN
[SW1] display vlan summary # 查看 VLAN 摘要

2.2 将端口加入 VLAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Access 端口加入 VLAN
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] port link-type access
[SW1-GigabitEthernet0/0/1] port default vlan 10

# Trunk 端口允许 VLAN 通过
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] port link-type trunk
[SW1-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20 30
[SW1-GigabitEthernet0/0/24] port trunk pvid vlan 1

# 批量配置端口 VLAN
[SW1] port-group 1
[SW1-port-group-1] group-member GigabitEthernet 0/0/1 to 0/0/10
[SW1-port-group-1] port link-type access
[SW1-port-group-1] port default vlan 10

2.3 VLAN 间路由(三层交换)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建 VLANIF 接口
[SW1] interface Vlanif 10
[SW1-Vlanif10] ip address 192.168.10.1 255.255.255.0
[SW1-Vlanif10] quit

[SW1] interface Vlanif 20
[SW1-Vlanif20] ip address 192.168.20.1 255.255.255.0
[SW1-Vlanif20] quit

# 启用 IP 路由
[SW1] ip routing

# 查看路由表
[SW1] display ip routing-table

2.4 Super VLAN 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 创建 Super VLAN
[SW1] vlan 100
[SW1-vlan100] description Super_VLAN
[SW1-vlan100] quit

# 创建 Sub VLAN
[SW1] vlan batch 101 102 103

# 配置 Sub VLAN
[SW1] vlan 101
[SW1-vlan101] subvlan
[SW1-vlan101] quit

# 关联 Super VLAN 和 Sub VLAN
[SW1] vlan 100
[SW1-vlan100] aggregate-vlan
[SW1-vlan100] access-vlan 101 to 103

# 配置 VLANIF
[SW1] interface Vlanif 100
[SW1-Vlanif100] ip address 192.168.100.1 255.255.255.0

3. 链路聚合

3.1 手工负载分担模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 创建 Eth-Trunk 接口
[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] description To_SW2
[SW1-Eth-Trunk1] quit

# 将物理接口加入 Eth-Trunk
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] eth-trunk 1
[SW1-GigabitEthernet0/0/1] quit

[SW1] interface GigabitEthernet 0/0/2
[SW1-GigabitEthernet0/0/2] eth-trunk 1

# 配置 Eth-Trunk 为 Trunk
[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] port link-type trunk
[SW1-Eth-Trunk1] port trunk allow-pass vlan 10 20 30

# 查看 Eth-Trunk 状态
[SW1] display eth-trunk 1
[SW1] display interface Eth-Trunk 1

3.2 LACP 模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 创建 LACP 模式 Eth-Trunk
[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] mode lacp
[SW1-Eth-Trunk1] quit

# 配置系统优先级(可选,越小优先级越高)
[SW1] lacp priority 100

# 将接口加入 Eth-Trunk
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] eth-trunk 1
[SW1-GigabitEthernet0/0/1] lacp priority 100 # 接口优先级

# 配置活动接口数上限
[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] max active-linknumber 4

# 查看 LACP 信息
[SW1] display eth-trunk 1
[SW1] display lacp statistics eth-trunk 1

3.3 Eth-Trunk 负载分担方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 配置负载分担模式
[SW1] load-balance ?
dst-ip 目的 IP
dst-mac 目的 MAC
src-ip 源 IP
src-mac 源 MAC
src-dst-ip 源 + 目的 IP
src-dst-mac 源 + 目的 MAC

# 配置全局负载分担
[SW1] load-balance src-dst-ip

# 查看负载分担配置
[SW1] display load-balance

4. 生成树协议

4.1 STP 基础配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启用 STP
[SW1] stp enable

# 配置 STP 模式
[SW1] stp mode stp # 标准 STP
[SW1] stp mode rstp # 快速 STP(推荐)
[SW1] stp mode mstp # 多实例 STP

# 配置交换机优先级(越小越优先成为根桥)
[SW1] stp priority 0 # 0, 4096, 8192... 61440
[SW1] stp root primary # 设为根桥
[SW1] stp root secondary # 设为备份根桥

# 查看 STP 状态
[SW1] display stp
[SW1] display stp brief

4.2 RSTP 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启用 RSTP
[SW1] stp mode rstp

# 配置边缘端口(连接终端)
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] stp edged-port enable

# 配置防 BPDU 攻击
[SW1-GigabitEthernet0/0/1] stp bpdu-protection

# 配置根保护
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] stp root-protection

# 查看 RSTP 状态
[SW1] display stp

4.3 MSTP 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 启用 MSTP
[SW1] stp mode mstp

# 进入 MST 域配置
[SW1] stp region-configuration
[SW1-mst-region] region-name RG1
[SW1-mst-region] instance 1 vlan 10 20
[SW1-mst-region] instance 2 vlan 30 40
[SW1-mst-region] revision-level 1
[SW1-mst-region] active region-configuration

# 配置实例优先级
[SW1] stp instance 1 priority 0
[SW1] stp instance 2 priority 4096

# 查看 MSTP 配置
[SW1] display stp region-configuration
[SW1] display stp instance 1

4.4 STP 保护功能

1
2
3
4
5
6
7
8
9
10
11
12
13
# BPDU 保护(全局)
[SW1] stp bpdu-protection

# 根保护(接口)
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] stp root-protection

# 环路保护
[SW1-GigabitEthernet0/0/24] stp loop-protection

# TC 保护
[SW1] stp tc-protection enable
[SW1] stp tc-protection threshold 10

5. 路由配置

5.1 静态路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 启用 IP 路由
[SW1] ip routing

# 配置静态路由
[SW1] ip route-static 192.168.100.0 255.255.255.0 10.1.1.2
[SW1] ip route-static 0.0.0.0 0.0.0.0 10.1.1.1 # 默认路由

# 配置浮动静态路由(通过优先级实现备份)
[SW1] ip route-static 192.168.100.0 255.255.255.0 10.1.1.2 preference 60
[SW1] ip route-static 192.168.100.0 255.255.255.0 10.1.2.2 preference 100

# 查看路由表
[SW1] display ip routing-table
[SW1] display ip routing-table protocol static

5.2 OSPF 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 启用 OSPF
[SW1] ospf 1 router-id 1.1.1.1
[SW1-ospf-1] area 0
[SW1-ospf-1-area-0.0.0.0] network 192.168.10.0 0.0.0.255
[SW1-ospf-1-area-0.0.0.0] network 192.168.20.0 0.0.0.255

# 配置 OSPF 接口参数
[SW1] interface Vlanif 10
[SW1-Vlanif10] ospf cost 10
[SW1-Vlanif10] ospf priority 100

# 配置 OSPF 认证
[SW1-ospf-1-area-0.0.0.0] authentication-mode md5 1 cipher Huawei@123

# 查看 OSPF 信息
[SW1] display ospf brief
[SW1] display ospf peer
[SW1] display ospf routing

5.3 VRRP 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 配置 VRRP 组
[SW1] interface Vlanif 10
[SW1-Vlanif10] ip address 192.168.10.2 255.255.255.0
[SW1-Vlanif10] vrrp vrid 1 virtual-ip 192.168.10.1
[SW1-Vlanif10] vrrp vrid 1 priority 120 # 优先级(默认 100)
[SW1-Vlanif10] vrrp vrid 1 preempt-mode timer delay 20

# 配置 VRRP 认证
[SW1-Vlanif10] vrrp vrid 1 authentication-mode md5 Huawei@123

# 配置 VRRP 跟踪接口
[SW1-Vlanif10] vrrp vrid 1 track interface GigabitEthernet 0/0/24 reduced 30

# 查看 VRRP 状态
[SW1] display vrrp brief
[SW1] display vrrp

6. ACL 访问控制

6.1 基本 ACL(2000-2999)

1
2
3
4
5
6
7
8
9
10
11
12
13
# 创建基本 ACL
[SW1] acl 2000
[SW1-acl-basic-2000] rule 5 permit source 192.168.10.0 0.0.0.255
[SW1-acl-basic-2000] rule 10 deny source 192.168.20.0 0.0.0.255
[SW1-acl-basic-2000] rule 15 permit source any

# 应用 ACL 到接口(出方向)
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] traffic-filter outbound acl 2000

# 查看 ACL
[SW1] display acl 2000
[SW1] display acl all

6.2 高级 ACL(3000-3999)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建高级 ACL
[SW1] acl 3000
[SW1-acl-adv-3000] rule 5 permit ip source 192.168.10.0 0.0.0.255 destination 192.168.30.0 0.0.0.255
[SW1-acl-adv-3000] rule 10 permit tcp source 192.168.10.0 0.0.0.255 destination 192.168.30.0 0.0.0.255 destination-port eq 80
[SW1-acl-adv-3000] rule 15 deny ip source any destination any

# 应用 ACL
[SW1] interface Vlanif 10
[SW1-Vlanif10] traffic-filter inbound acl 3000

# 基于时间的 ACL
[SW1] time-range work-time 08:00 to 18:00 working-day
[SW1] acl 3001
[SW1-acl-adv-3001] rule 5 permit tcp source any destination any destination-port eq 80 time-range work-time

6.3 二层 ACL(4000-4999)

1
2
3
4
5
6
7
8
# 创建二层 ACL
[SW1] acl 4000
[SW1-acl-link-4000] rule 5 permit vlan-id 10
[SW1-acl-link-4000] rule 10 deny source-mac 00e0-fc00-0001 ffff-ffff-ffff

# 应用二层 ACL
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] traffic-filter inbound acl 4000

6.4 ACL 日志记录

1
2
3
4
5
6
7
# 启用 ACL 日志
[SW1] acl 3000
[SW1-acl-adv-3000] rule 5 deny ip source any destination any logging

# 查看 ACL 匹配统计
[SW1] display acl 3000
[SW1] display traffic-filter applied-record

7. QoS 配置

7.1 流量分类

1
2
3
4
5
6
7
8
9
10
11
12
# 创建 ACL 定义流量
[SW1] acl 3000
[SW1-acl-adv-3000] rule 5 permit tcp destination-port eq 80
[SW1-acl-adv-3000] rule 10 permit tcp destination-port eq 443

# 创建流分类
[SW1] traffic classifier WEB
[SW1-classifier-WEB] if-match acl 3000

# 创建流分类(基于 DSCP)
[SW1] traffic classifier VOIP
[SW1-classifier-VOIP] if-match dscp ef

7.2 流量行为

1
2
3
4
5
6
7
8
9
10
11
# 创建流行为(重标记)
[SW1] traffic behavior WEB_MARK
[SW1-behavior-WEB_MARK] remark dscp af21

# 创建流行为(限速)
[SW1] traffic behavior LIMIT
[SW1-behavior-LIMIT] car cir 10000 pir 20000

# 创建流行为(队列)
[SW1] traffic behavior VOICE
[SW1-behavior-VOICE] queue ef bandwidth pct 30

7.3 流策略

1
2
3
4
5
6
7
8
9
10
11
# 创建流策略并绑定分类和行为
[SW1] traffic policy WEB_POLICY
[SW1-trafficpolicy-WEB_POLICY] classifier WEB behavior WEB_MARK

# 应用流策略到接口
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] traffic-policy WEB_POLICY inbound

# 查看流策略
[SW1] display traffic-policy WEB_POLICY
[SW1] display traffic-policy applied-record

7.4 端口限速

1
2
3
4
5
6
7
8
9
10
11
# 配置端口入方向限速
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] qos lr inbound cir 10000 pir 20000

# 配置端口出方向限速
[SW1-GigabitEthernet0/0/1] qos lr outbound cir 50000 pir 100000

# 配置风暴抑制
[SW1-GigabitEthernet0/0/1] storm-control broadcast min-rate 1000 max-rate 2000
[SW1-GigabitEthernet0/0/1] storm-control multicast min-rate 1000 max-rate 2000
[SW1-GigabitEthernet0/0/1] storm-control unicast min-rate 1000 max-rate 2000

8. 安全配置

8.1 端口安全

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启用端口安全
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] port-security enable

# 配置最大 MAC 地址数
[SW1-GigabitEthernet0/0/1] port-security max-mac-count 5

# 配置保护动作
[SW1-GigabitEthernet0/0/1] port-security protect-action restrict # protect/restrict/shutdown

# 配置 Sticky MAC
[SW1-GigabitEthernet0/0/1] port-security mac-address sticky

# 查看端口安全
[SW1] display port-security
[SW1] display mac-address

8.2 802.1X 认证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 启用 802.1X
[SW1] dot1x enable

# 配置认证方案
[SW1] aaa
[SW1-aaa] authentication-scheme dot1x
[SW1-aaa-authen-dot1x] authentication-mode radius

# 配置 RADIUS 服务器
[SW1] radius-server template radius1
[SW1-radius-radius1] radius-server authentication 192.168.100.10 1812
[SW1-radius-radius1] radius-server shared-key cipher Huawei@123
[SW1-radius-radius1] quit

# 在接口启用 802.1X
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] dot1x enable

# 查看 802.1X 状态
[SW1] display dot1x
[SW1] display dot1x connections

8.3 DHCP Snooping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启用 DHCP Snooping
[SW1] dhcp enable
[SW1] dhcp snooping enable

# 配置信任接口(连接 DHCP 服务器)
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] dhcp snooping trusted

# 配置非信任接口限速
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] dhcp snooping check dhcp-request enable
[SW1-GigabitEthernet0/0/1] dhcp snooping check dhcp-chaddr enable

# 查看 DHCP Snooping
[SW1] display dhcp snooping
[SW1] display dhcp snooping binding

8.4 DAI(动态 ARP 检测)

1
2
3
4
5
6
7
8
9
10
11
12
13
# 启用 DAI
[SW1] arp anti-attack check user-bind enable

# 在 VLAN 启用 DAI
[SW1] vlan 10
[SW1-vlan10] arp anti-attack dynamic-check enable

# 配置信任接口
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] arp anti-attack trust enable

# 查看 DAI
[SW1] display arp anti-attack statistics

9. 管理与维护

9.1 SSH 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 生成本地密钥对
[SW1] rsa local-key-pair create

# 启用 SSH 服务
[SW1] stelnet server enable
[SW1] sftp server enable

# 创建本地用户
[SW1] aaa
[SW1-aaa] local-user admin password irreversible-cipher Huawei@123
[SW1-aaa] local-user admin privilege level 15
[SW1-aaa] local-user admin service-type ssh

# 配置 SSH 用户认证
[SW1] ssh user admin authentication-type password
[SW1] ssh user admin service-type stelnet

# 配置 VTY 支持 SSH
[SW1] user-interface vty 0 4
[SW1-ui-vty0-4] authentication-mode aaa
[SW1-ui-vty0-4] protocol inbound ssh

# 查看 SSH 信息
[SW1] display ssh server status
[SW1] display ssh user-information

9.2 SNMP 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 启用 SNMP
[SW1] snmp-agent

# 配置 SNMP 版本
[SW1] snmp-agent sys-info version v3

# 配置团体名(v2c)
[SW1] snmp-agent community read cipher public
[SW1] snmp-agent community write cipher private

# 配置 SNMPv3 用户
[SW1] snmp-agent usm-user v3 admin
[SW1] snmp-agent usm-user v3 admin authentication-mode sha
[SW1] snmp-agent usm-user v3 admin privacy-mode aes128

# 配置 Trap 目标
[SW1] snmp-agent target-host trap address udp-domain 192.168.100.100 params securityname public v2c

# 查看 SNMP
[SW1] display snmp-agent sys-info

9.3 NTP 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 启用 NTP
[SW1] ntp enable

# 配置 NTP 服务器
[SW1] ntp-server 192.168.100.10

# 配置 NTP 认证
[SW1] ntp-service authentication enable
[SW1] ntp-service authentication-keyid 1 authentication-mode md5 Huawei@123
[SW1] ntp-service trusted authentication-keyid 1

# 查看 NTP 状态
[SW1] display ntp-service status
[SW1] display ntp-service sessions

9.4 日志配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 启用日志中心
[SW1] info-center enable

# 配置日志主机
[SW1] info-center loghost 192.168.100.100

# 配置日志级别
[SW1] info-center source DHCP log level warning

# 配置日志缓冲区
[SW1] info-center logbuffer size 1024
[SW1] info-center logbuffer level informational

# 查看日志
[SW1] display logbuffer
[SW1] display trapbuffer
[SW1] terminal monitor
[SW1] terminal logging

9.5 设备维护命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 查看设备信息
<SW1> display device # 查看硬件信息
<SW1> display version # 查看版本信息
<SW1> display elabel # 查看电子标签

# 查看 CPU 和内存
<SW1> display cpu-usage # CPU 使用率
<SW1> display memory-usage # 内存使用率

# 查看温度和环境
<SW1> display environment # 环境信息
<SW1> display fan # 风扇状态
<SW1> display power # 电源状态

# 诊断命令
<SW1> ping 192.168.1.1 # Ping 测试
<SW1> tracert 192.168.1.1 # 路由追踪
<SW1> telnet 192.168.1.1 # Telnet 测试

# 重启设备
<SW1> reboot # 重启
<SW1> reset saved-configuration # 清除保存配置

文档版本: 1.0
最后更新: 2026-02-27
适用设备: 华为 S5700/S6700/S7700/S9700 系列交换机