技术 · 思考 · 实践 · 成长

首页/计算机网络/正文

华为交换机基础配置完全指南:从开局到 VLAN、聚合与备份

计算机网络10 次阅读

华为交换机(S 系列)用的是 VRP 系统,配置逻辑和路由器一致:Console 登录 → 基础参数 → 管理地址 → 业务配置 → 验收备份。这篇把开局常用命令按顺序讲全,附带典型模板与排错。参考:华为 S 系列交换机配置指南。

华为交换机开局配置流程

一、VRP 与视图体系

视图提示符能做什么
用户视图<Huawei>查看、保存、重启
系统视图[Huawei]全局配置
接口视图[Huawei-GigabitEthernet0/0/1]端口配置
VLAN 视图[Huawei-vlan10]VLAN 属性
协议视图[Huawei-ospf-1]协议参数
<Huawei> system-view          # 用户视图 → 系统视图
[Huawei] interface GigabitEthernet 0/0/1   # 进入接口视图
[Huawei-GigabitEthernet0/0/1] quit         # 退回上一级
[Huawei] return                # 直接回到用户视图(或 Ctrl+Z)

二、Console 登录与常用快捷键

# 终端参数:9600-8-N-1,无流控
# 上电后看到 Press ENTER to get started,按回车进入 <Huawei>
快捷键作用
Tab补全命令
?查看帮助
Ctrl+Z回到用户视图
Ctrl+A光标移到行首
Ctrl+E光标移到行尾
Ctrl+C中断当前命令
↑ / ↓历史命令

三、基础参数

<Huawei> system-view
[Huawei] sysname SW1                              # 改设备名

[SW1] clock timezone BJ add 08:00:00              # 设置东八区
[SW1] clock datetime 2026-11-26 10:00:00          # 手动设时间(可选)

[SW1] ntp-service unicast-server 192.168.1.100    # 配 NTP 服务器,自动对时

[SW1] header login information "Authorized access only"   # 登录提示语

[SW1] quit
<SW1> save                                        # 保存配置(关键)

很多设备重启后配置丢失,就是因为只改了配置没 save。

四、管理地址与 SSH 登录

[SW1] vlan 10                                     # 建管理 VLAN(也可以直接用 VLAN1)
[SW1-vlan10] quit

[SW1] interface Vlanif 10                         # 三层接口
[SW1-Vlanif10] ip address 192.168.10.2 24         # 管理地址
[SW1-Vlanif10] quit

[SW1] interface GigabitEthernet 0/0/24            # 上联口
[SW1-GigabitEthernet0/0/24] port link-type trunk
[SW1-GigabitEthernet0/0/24] port trunk allow-pass vlan 10
[SW1-GigabitEthernet0/0/24] quit

[SW1] stelnet server enable                       # 开启 SSH
[SW1] aaa
[SW1-aaa] local-user admin password irreversible-cipher 强密码
[SW1-aaa] local-user admin privilege level 15
[SW1-aaa] local-user admin service-type ssh
[SW1-aaa] quit

[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-ui-vty0-4] quit

[SW1] display ssh server status                   # 确认 SSH 已开
# 从电脑测试
ssh admin@192.168.10.2

五、VLAN 基础

[SW1] vlan batch 10 20 30                         # 批量创建

[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] port link-type access  # 接终端
[SW1-GigabitEthernet0/0/1] port default vlan 10
[SW1-GigabitEthernet0/0/1] description PC-财务-01  # 写描述,方便维护
[SW1-GigabitEthernet0/0/1] quit

[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] quit

[SW1] display vlan                                # 查看 VLAN 与端口
[SW1] display port vlan                           # 查看每个口的类型与 PVID

Hybrid 口(可选)

[SW1] interface GigabitEthernet 0/0/2
[SW1-GigabitEthernet0/0/2] port link-type hybrid
[SW1-GigabitEthernet0/0/2] port hybrid pvid vlan 10
[SW1-GigabitEthernet0/0/2] port hybrid untagged vlan 10 20   # 这些 VLAN 出去不打标签
[SW1-GigabitEthernet0/0/2] port hybrid tagged vlan 30        # 这个 VLAN 带标签
[SW1-GigabitEthernet0/0/2] quit

Hybrid 能同时承载「多个 VLAN 去标签」,接服务器或 AP 时常用;普通办公场景 Access + Trunk 足够。

六、端口常用配置

[SW1] interface GigabitEthernet 0/0/3
[SW1-GigabitEthernet0/0/3] description AP-3F-01
[SW1-GigabitEthernet0/0/3] undo negotiation auto   # 关闭自协商
[SW1-GigabitEthernet0/0/3] speed 1000              # 固定速率(光口常用)
[SW1-GigabitEthernet0/0/3] duplex full             # 固定全双工
[SW1-GigabitEthernet0/0/3] undo shutdown
[SW1-GigabitEthernet0/0/3] quit

# 端口隔离:同 VLAN 内互访控制(接酒店/宿舍常用)
[SW1] interface GigabitEthernet 0/0/4
[SW1-GigabitEthernet0/0/4] port-isolate enable group 1
[SW1-GigabitEthernet0/0/4] quit

# 端口安全:限制 MAC 数量,防私接
[SW1] interface GigabitEthernet 0/0/5
[SW1-GigabitEthernet0/0/5] port-security enable
[SW1-GigabitEthernet0/0/5] port-security max-mac-num 2
[SW1-GigabitEthernet0/0/5] port-security protect-action restrict
[SW1-GigabitEthernet0/0/5] quit

七、链路聚合 Eth-Trunk

[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] mode lacp-static                 # LACP 模式,推荐
[SW1-Eth-Trunk1] port link-type trunk
[SW1-Eth-Trunk1] port trunk allow-pass vlan 10 20
[SW1-Eth-Trunk1] quit

# 把物理口加入聚合组
[SW1] interface GigabitEthernet 0/0/23
[SW1-GigabitEthernet0/0/23] eth-trunk 1
[SW1-GigabitEthernet0/0/23] quit
[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] eth-trunk 1
[SW1-GigabitEthernet0/0/24] quit

[SW1] display eth-trunk 1                         # 查看成员与状态

两端都要做聚合,成员口的速率、双工、VLAN 配置必须一致。

八、STP / RSTP

[SW1] stp mode rstp                               # 快速生成树
[SW1] stp root primary                            # 核心交换机设为根桥
[SW1] stp bpdu-protection                         # 边缘口收到 BPDU 自动关断(防私接)

[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] stp edged-port enable   # 接终端的边缘口
[SW1-GigabitEthernet0/0/1] quit

[SW1] display stp brief                           # 查看端口角色与状态

九、DHCP(交换机也能做)

# 方式一:交换机自己发地址
[SW1] dhcp enable
[SW1] ip pool office
[SW1-ip-pool-office] network 192.168.10.0 mask 255.255.255.0
[SW1-ip-pool-office] gateway-list 192.168.10.1
[SW1-ip-pool-office] dns-list 223.5.5.5
[SW1-ip-pool-office] excluded-ip-address 192.168.10.1
[SW1-ip-pool-office] quit
[SW1] interface Vlanif 10
[SW1-Vlanif10] dhcp select global
[SW1-Vlanif10] quit

# 方式二:DHCP 中继(服务器在别的网段)
[SW1] interface Vlanif 20
[SW1-Vlanif20] dhcp select relay
[SW1-Vlanif20] dhcp relay server-ip 192.168.10.100
[SW1-Vlanif20] quit

十、常用查看命令

命令用途
display version型号、VRP 版本、运行时长
display device板卡与电源状态
display interface brief所有端口速率、双工、up/down
display vlanVLAN 与成员端口
display port vlan端口类型、PVID、允许 VLAN
display mac-addressMAC 地址表
display stp briefSTP 端口角色
display eth-trunk 1聚合组状态
display ip interface brief三层接口地址
display current-configuration当前配置
display saved-configuration已保存配置

十一、备份、恢复与升级

# 备份:导出当前配置到 TFTP
<SW1> tftp 192.168.1.100 put vrpcfg.zip          # 需先 save
# 或查看后复制出来
<SW1> display current-configuration

# 恢复:把备份文件放回设备
<SW1> tftp 192.168.1.100 get vrpcfg.zip
<SW1> startup saved-configuration vrpcfg.zip
<SW1> reboot

# 升级系统
<SW1> tftp 192.168.1.100 get S5700-V200R019.cc
<SW1> startup system-software S5700-V200R019.cc
<SW1> reboot

升级前务必:备份配置、备份旧系统文件、确认 Flash 空间足够、准备回滚方案。

十二、恢复出厂与密码恢复

# 恢复出厂(会清空配置,谨慎)
<SW1> reset saved-configuration
<SW1> reboot
# 重启时提示是否保存,选 N

# 密码恢复:Console 下重启,出现提示时按 Ctrl+B 进入 BootROM
# 选择清除密码或跳过配置启动,进入后重新设置密码并保存

十三、典型开局模板

接入交换机

sysname ACC-3F
vlan batch 10 20
interface Vlanif 10
 ip address 192.168.10.3 24
interface GigabitEthernet 0/0/24
 port link-type trunk
 port trunk allow-pass vlan 10 20
interface GigabitEthernet 0/0/1
 port link-type access
 port default vlan 10
 description PC-财务-01
quit
save

核心交换机(简版)

sysname CORE
vlan batch 10 20 30
interface Vlanif 10
 ip address 192.168.10.1 24
interface Vlanif 20
 ip address 192.168.20.1 24
interface Eth-Trunk 1
 mode lacp-static
 port link-type trunk
 port trunk allow-pass vlan 10 20 30
interface GigabitEthernet 0/0/23
 eth-trunk 1
interface GigabitEthernet 0/0/24
 eth-trunk 1
stp mode rstp
stp root primary
quit
save

十四、常见错误与排错

现象原因解决
SSH 连不上没开 stelnet、没配 VTY、VLANIF down逐项检查 display ssh server status
跨交换机同 VLAN 不通Trunk 没放行该 VLANdisplay port vlan 核对
配置重启后丢失没 save改完立即保存
聚合口只有一个成员 up对端没配聚合或参数不一致两端核对 display eth-trunk
接终端口被 STP 阻塞没设边缘口stp edged-port enable
私接路由器导致环路无 BPDU 保护开 stp bpdu-protection
VLANIF 起不来该 VLAN 没有 up 端口先接终端或配 Trunk
改了 IP 失联管理 VLAN 与上联不一致Console 回退

十五、总结

华为交换机开局记住五步:Console 进得去、参数改得对、管理地址通得了、VLAN 划得清、配置存得下。业务配置前先备份,改一段存一段;SSH 验证通过后再拔 Console。把这套流程走顺,接入层和核心层的基本配置都能独立完成。

所谓坚持,就是从种子种下到开花结果需要等待的时间。

评论交流

0 条评论 · 支持多级回复
验证码
暂无评论,来说说你的想法吧

相关文章

继续阅读