华为交换机恢复出厂设置:三种方法与验证加固 - 夜莺博客

华为交换机恢复出厂设置:三种方法与验证加固

华为交换机恢复出厂设置有三种正规路径,很多工程师只知道其中一种,结果在设备被锁、无法登录或需要彻底交还给别人时卡住。本文按现场场景梳理三种方法的选择逻辑、真实命令、容易忽略的坑,以及恢复后必须立刻做的验证和安全加固——因为一台恢复出厂后仍连在网络上的交换机,是一台使用默认口令、没有任何策略的设备。

先选方法:按你的处境决定

场景 推荐方法 结果
能 CLI 登录,只是想清空配置 reset saved-configuration + reboot 只清启动配置文件,业务配置仍留在运行态直到重启
要交给别人/重新部署,要一份干净设备 reset factory-configuration 清空业务配置和数据文件,保留系统/补丁/许可文件
完全登录不上(口令丢失) BootROM/DIAG 菜单(Ctrl+B) 清除 console 口令,再按需重置
支持 PNP 按钮的型号,现场无人值守 长按 PNP 按钮 > 6 秒 等效 reset factory-configuration,无确认提示,直接重启

方法一:CLI 命令(有登录权限时首选)

第一步永远是留备份,恢复出厂没有撤销:

<HUAWEI> display current-configuration
<HUAWEI> display startup
<HUAWEI> display saved-configuration

然后二选一:

# 仅清启动配置(延迟生效,重启才真正擦除)
<HUAWEI> reset saved-configuration
Warning: The action will delete the saved configuration in the device.
The configuration will be erased to reconfigure. Continue? [Y/N]:y
Info: Succeeded in clearing the configuration in the device.
<HUAWEI> reboot
Warning: The configuration has been modified, and it will be saved to the
next startup saved-configuration file flash:/vrpcfg.zip. Continue? [Y/N]:n
System will reboot! Continue? [Y/N]:y

# 一键恢复出厂(清业务配置+数据文件,设备自动重启)
<HUAWEI> reset factory-configuration
Warning: The command will delete all the configurations and files
(except the startup, patch, module, and license files) from the device.
Continue? [Y/N]:y
Warning: The system will reboot after configurations and files are deleted.
Continue? [Y/N]:y

最大的坑:reboot 时问 "Save the current configuration? [Y/N]",一定要回答 N。回答 Y 会把当前运行配置写回 flash:/vrpcfg.zip,reset 等于白做——这就是很多人说的"恢复出厂没生效"。两个命令的区别可以再看 saved-configuration 与 factory-configuration 对比。

方法二:BootROM / DIAG 菜单(登录不上时)

  1. 用 console 线(9600-8-N-1)连接,重启设备。
  2. 出现 Press Ctrl+B to enter Boot Menu 时按 Ctrl+B。
  3. 输入 BootROM 口令(视版本为 Admin@huawei.com 或 huawei)。
  4. 选择 Clear password for console user(很多 S 系列是菜单 7),确认 Y,返回主菜单重启。
  5. 无口令登录后立刻设置新口令,再决定是否需要 reset saved-configuration。

注意这种方法只清单个 console 口令,配置本身还在——它是"恢复登录"而不是"恢复出厂"。完整步骤见 S5700 BootROM 口令恢复指南。

方法三:PNP 按钮(部分型号,免登录)

支持 PNP 按钮的型号(S5720-LI、S5731/S5735 系列、S6700S 等)长按按钮 6 秒以上即可恢复出厂并自动重启。三点必须知道:

  • 没有任何确认提示,配置和数据文件一次性清空。
  • 不会删除受保护目录和 protected/$_default.cfg;若该文件存在,下次启动会以它作为配置文件。
  • 堆叠场景下默认只把按按钮的那台设备恢复出厂;要清整个堆叠需 pnp-button mode reset-system。用专用堆叠线组网的,先把一端线缆拔掉,否则重启后会自动重新组堆叠。

恢复后立刻做验证

<HUAWEI> display startup
<HUAWEI> display saved-configuration
<HUAWEI> display factory-configuration reset-result
<HUAWEI> display version

判断标准:display saved-configuration 不应再打印出你的 VLAN、接口和 AAA 配置;如果你还能看到它们,说明清的不是你以为的东西。display factory-configuration reset-result 在支持的版本上直接给出上次恢复是否成功。

恢复后必须马上加固

出厂状态的默认账号(常见为 admin/admin@huawei.com)加上"没有策略",等于把设备暴露在网络里。返回生产前至少完成:

<HUAWEI> system-view
[HUAWEI] sysname SW-NEW
[HUAWEI] aaa
[HUAWEI-aaa] local-user admin password irreversible-cipher <强口令>
[HUAWEI-aaa] local-user admin privilege level 15
[HUAWEI-aaa] local-user admin service-type ssh
[HUAWEI-aaa] quit
[HUAWEI] stelnet server enable
[HUAWEI] undo telnet server enable
[HUAWEI] acl 2000
[HUAWEI-acl-basic-2000] rule 5 permit source 10.10.10.0 0.0.0.255
[HUAWEI-acl-basic-2000] rule 100 deny
[HUAWEI] user-interface vty 0 4
[HUAWEI-ui-vty0-4] acl 2000 inbound
[HUAWEI-ui-vty0-4] quit
[HUAWEI] save

最后别忘了时钟和固件:恢复出厂不保证版本是最新的,display version 后按需升级打补丁(校时和日志同样重要,否则下次故障排查时时间戳全是错的)。整套流程的对照版可参考 华为交换机恢复出厂完全指南 与 S5700 三种方法篇。

原文链接:https://support.huawei.com/enterprise/en/doc/EDOC1100277060/2d74840b/restoring-the-switch-to-factory-default