三步搞清楚华为路由器配置文件保存原理

要想搞清楚华为路由器临时配置和永久性配置,其实这个问题非常简单。

所谓设备flash可以看成被精简后的Linux操作系统,如果是有Linux基础的朋友会更加容易理解。

在用户模式下甚至连基础命令都和Linux一样,这样看起来非常容。

在Linux中各类服务配置要想永久生效,都必须修改配置文件。

所谓的命令不过是临时生效而已。

所以,在华为的路由器和交换机中,所有的命令都只是临时生效,若是想要下次启动依旧生效,就必须将这些配置保存到配置文件中。

这里就涉及到文件的保存和导入的问题。

display  current-configuration命令可以查看当前生效的配置。

display  saved-configuration命令可以查看配置文件中永久生效的设置。设备启动一般都以此文件显示的为准。

步骤一:使用命令行配置设备名R1,查看当前临时生效的配置。

[Huawei]system-view

[Huawei]sysname R1

[R1]quit

<R1>display  current-configuration  | include  sysname

 sysname R1 //就可以看设备名称已经改变。

以上的命令行配置仅仅只是当前临时生效。

可从以下命令看出,配置文件中并没有永久性配置。

<R1>display saved-configuration | include  sysname

若想永久性生效,其实非常简单。保存一份配置文件,并且做备份。此时涉及另外两个命令。

save 命令将当前配置永久性保存到配置文件中。

startup saved-configuration命令就是将自定义保存的配置文件中的内容导入系统配置文件。

步骤二:创建joinlabs目录,存放自定义配置文件。这个文件可以作为备份文件使用,非常灵活高效。

<R1>mkdir joinlabs //创建joinlabs目录

<R1>dir  //查看当前目录下所有内容,可以看到有joinlabs目录

Directory of flash:/

  Idx  Attr     Size(Byte)  Date        Time(LMT)  FileName

    0  drw-              -  Aug 13 2024 06:28:54   dhcp

    1  -rw-        121,802  May 26 2014 09:20:58   portalpage.zip

    2  drw-              -  Aug 13 2024 07:21:07   joinlabs.cfg

    3  -rw-          2,263  Aug 13 2024 07:44:28   statemach.efs

    4  -rw-        828,482  May 26 2014 09:20:58   sslvpn.zip

    5  -rw-            352  Aug 13 2024 06:30:53   private-data.txt

    6  -rw-            598  Aug 13 2024 07:44:26   vrpcfg.zip

<R1>save joinlabs/joinlabs.cfg //将配置文件joinlabs.cfg保存到joinlabs目录下。

 Are you sure to save the configuration to joinlabs/joinlabs.cfg? (y/n)[n]:y

<R1>dir joinlabs //可以查看到指定目录下有配置文件。

Directory of flash:/

  Idx  Attr     Size(Byte)  Date        Time(LMT)  FileName

0  drw-              -  Aug 13 2024 08:19:41   joinlabs.cfg

有了joinlabs.cfg文件存在,一切都会变得容易起来,只要此文件不删除和清空,不论怎么玩,配置都能恢复。

第三步:测试与恢复。

<R1>reset saved-configuration //情况永久性配置文件。

  There is no correct configuration file in FLASH

<R1>reboot   //系统配置文件重启生效

Info: The system is comparing the configuration, please wait.

Warning: All the configuration will be saved to the next startup configuration.

Continue ? [y/n]:n   //所有配置是否保存到配置文件中。此时配置文件已是情况状态,必须要保存。选择n

System will reboot! Continue ? [y/n]:y //选择重启。

Info: system is rebooting ,please wait...

<Huawei>display current-configuration | include sysname

//重启后通过命令查看,当前配置中依旧没有设备名称设置,代表配置已经清空。

<Huawei>display saved-configuration | include  sysname

  There is no correct configuration file in FLASH 

//系统配置文件中依旧没有关于sysname的配置,证明以前的配置彻底清空了。

<Huawei>more joinlabs/joinlabs.cfg //但是在joinlab目录中依旧有备份文件。

[V200R003C00]

 sysname R1

<Huawei>pwd //查看当前路径。系统配置文件必须要在flash根目录下才生效。

flash:

<Huawei>cd flash: //如果不在flash根目录中,可使用cd命令切换。

<Huawei>copy joinlabs/joinlabs.cfg .  //拷贝备份文件到当前目录

Copy flash:/joinlabs/joinlabs.cfg to flash:/joinlabs.cfg? (y/n)[n]:y

The file flash:/joinlabs.cfg exists. Overwrite it? (y/n)[n]:

Deleting file permanently from flash will take a long time if needed...Done.

100%  complete

Info: Copied file flash:/joinlabs/joinlabs.cfg to flash:/joinlabs.cfg...Done

<R1>startup saved-configuration joinlabs.cfg //将配置文件导入系统文件中。

This operation will take several minutes, please wait.....

Info: Succeeded in setting the file for booting system

<Huawei>display saved-configuration | include sysname //看到系统文件中已经永久生效。

 sysname R1

<Huawei>display current-configuration | include sysname //查看当前依旧无效

<Huawei>reboot //系统配置文件内容重启生效。

Info: The system is comparing the configuration, please wait.

Warning: All the configuration will be saved to the next startup configuration.

Continue ? [y/n]:n

System will reboot! Continue ? [y/n]:y

Info: system is rebooting ,please wait...

<Huawei>###

<R1>

注意:以上“Warning: All the configuration will be saved to the next startup configuration. 千万不能选择y,y是将当前配置保存到系统配置文件中。当前配置已经恢复,毛都没有。如果导入会直接覆盖系统配置文件重启后配置依旧丢失。只能重新拷贝后的那些步骤再来一次才可以生效。

关注+点赞+评论+收藏,分享更多网工实验小技巧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值