华为交换机典型配置命令手册
目录
- 基础配置命令
- VLAN 配置
- 链路聚合
- 生成树协议
- 路由配置
- ACL 访问控制
- QoS 配置
- 安全配置
- 管理与维护
1. 基础配置命令
1.1 登录与视图切换
1 2 3 4 5 6 7 8 9 10 11 12
| <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 [SW1-GigabitEthernet0/0/1] duplex full
[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
| [SW1-GigabitEthernet0/0/1] port link-type access [SW1-GigabitEthernet0/0/1] port default vlan 10
[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
[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
| [SW1] vlan 10 [SW1-vlan10] description HR_Department [SW1-vlan10] quit
[SW1] vlan batch 10 20 30 [SW1] vlan batch 10 to 50
[SW1] display vlan [SW1] display vlan 10 [SW1] display vlan summary
|
2.2 将端口加入 VLAN
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 link-type access [SW1-GigabitEthernet0/0/1] port default vlan 10
[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
[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
| [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
[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
| [SW1] vlan 100 [SW1-vlan100] description Super_VLAN [SW1-vlan100] quit
[SW1] vlan batch 101 102 103
[SW1] vlan 101 [SW1-vlan101] subvlan [SW1-vlan101] quit
[SW1] vlan 100 [SW1-vlan100] aggregate-vlan [SW1-vlan100] access-vlan 101 to 103
[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
| [SW1] interface Eth-Trunk 1 [SW1-Eth-Trunk1] description To_SW2 [SW1-Eth-Trunk1] quit
[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
[SW1] interface Eth-Trunk 1 [SW1-Eth-Trunk1] port link-type trunk [SW1-Eth-Trunk1] port trunk allow-pass vlan 10 20 30
[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
| [SW1] interface Eth-Trunk 1 [SW1-Eth-Trunk1] mode lacp [SW1-Eth-Trunk1] quit
[SW1] lacp priority 100
[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
[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
| [SW1] stp enable
[SW1] stp mode stp [SW1] stp mode rstp [SW1] stp mode mstp
[SW1] stp priority 0 [SW1] stp root primary [SW1] stp root secondary
[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
| [SW1] stp mode rstp
[SW1] interface GigabitEthernet 0/0/1 [SW1-GigabitEthernet0/0/1] stp edged-port enable
[SW1-GigabitEthernet0/0/1] stp bpdu-protection
[SW1] interface GigabitEthernet 0/0/24 [SW1-GigabitEthernet0/0/24] stp root-protection
[SW1] display stp
|
4.3 MSTP 配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [SW1] stp mode mstp
[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
[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
| [SW1] stp bpdu-protection
[SW1] interface GigabitEthernet 0/0/24 [SW1-GigabitEthernet0/0/24] stp root-protection
[SW1-GigabitEthernet0/0/24] stp loop-protection
[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
| [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
| [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
[SW1] interface Vlanif 10 [SW1-Vlanif10] ospf cost 10 [SW1-Vlanif10] ospf priority 100
[SW1-ospf-1-area-0.0.0.0] authentication-mode md5 1 cipher Huawei@123
[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
| [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 [SW1-Vlanif10] vrrp vrid 1 preempt-mode timer delay 20
[SW1-Vlanif10] vrrp vrid 1 authentication-mode md5 Huawei@123
[SW1-Vlanif10] vrrp vrid 1 track interface GigabitEthernet 0/0/24 reduced 30
[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
| [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
[SW1] interface GigabitEthernet 0/0/1 [SW1-GigabitEthernet0/0/1] traffic-filter outbound acl 2000
[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
| [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
[SW1] interface Vlanif 10 [SW1-Vlanif10] traffic-filter inbound acl 3000
[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
| [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
[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
| [SW1] acl 3000 [SW1-acl-adv-3000] rule 5 deny ip source any destination any logging
[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
| [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
[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
[SW1-GigabitEthernet0/0/1] port-security max-mac-count 5
[SW1-GigabitEthernet0/0/1] port-security protect-action restrict
[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
| [SW1] dot1x enable
[SW1] aaa [SW1-aaa] authentication-scheme dot1x [SW1-aaa-authen-dot1x] authentication-mode 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
[SW1] interface GigabitEthernet 0/0/1 [SW1-GigabitEthernet0/0/1] dot1x enable
[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
| [SW1] dhcp enable [SW1] dhcp snooping enable
[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
[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
| [SW1] arp anti-attack check user-bind enable
[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
[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
[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
[SW1] ssh user admin authentication-type password [SW1] ssh user admin service-type stelnet
[SW1] user-interface vty 0 4 [SW1-ui-vty0-4] authentication-mode aaa [SW1-ui-vty0-4] protocol inbound 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
| [SW1] snmp-agent
[SW1] snmp-agent sys-info version v3
[SW1] snmp-agent community read cipher public [SW1] snmp-agent community write cipher private
[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
[SW1] snmp-agent target-host trap address udp-domain 192.168.100.100 params securityname public v2c
[SW1] display snmp-agent sys-info
|
9.3 NTP 配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [SW1] ntp enable
[SW1] ntp-server 192.168.100.10
[SW1] ntp-service authentication enable [SW1] ntp-service authentication-keyid 1 authentication-mode md5 Huawei@123 [SW1] ntp-service trusted authentication-keyid 1
[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
<SW1> display cpu-usage <SW1> display memory-usage
<SW1> display environment <SW1> display fan <SW1> display power
<SW1> ping 192.168.1.1 <SW1> tracert 192.168.1.1 <SW1> telnet 192.168.1.1
<SW1> reboot <SW1> reset saved-configuration
|
文档版本: 1.0
最后更新: 2026-02-27
适用设备: 华为 S5700/S6700/S7700/S9700 系列交换机