Cisco IOSで設定のロールバック

先日のメモではIOSでのアーカイブについて触れたけど,今回は安全にロールバックを行う方法ついて確認。

そもそもCisco IOSでの設定即時反映は便利である反面,ミスったときの影響が大きいという問題があると感じていた。その点,JunosやVyOSのようなその他のNW OSで実装されている,設定反映前の比較やロールバックタイマーは運用を担っている人達からすると非常に助かる機能だと思う。
IOSはどうしてこの機能を盛り込まないのだろうと思っていたけれど,結構前からそれに類するコマンドはあったようで,私は知りませんでした。(12.2位からあったようで・・・)
<configure replace コマンド>
設定をロールバックするときはこのコマンドを使う。
こちらによると,稼働中のConfigとの差分のみを適用してくれるとのことで,copy xxx running-conifg のようにまるっと上書きよりも安全に変更できるそうだ。(コマンドリファレンスには置き換えるとしか書いていないけど,そうなのか)

試しにホスト名を変えてロールバックをしてみる。

R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#hostname Router1
Router1(config)#end
Router1#show archive
The maximum archive configurations allowed is 10.
The next archive file will be named ftp://10.10.10.10/Router1--3605
Archive # Name
1 ftp://10.10.10.10/R1-May--8-01-53-04.568-3595
2 ftp://10.10.10.10/R1-May--8-01-56-04.701-3596
3 ftp://10.10.10.10/R1-May--8-01-59-04.848-3597
4 ftp://10.10.10.10/R1-May--8-02-02-04.993-3598
5 ftp://10.10.10.10/R1-May--8-02-05-05.127-3599
6 ftp://10.10.10.10/R1-May--8-02-08-05.277-3600
7 ftp://10.10.10.10/R1-May--8-02-11-05.411-3601
8 ftp://10.10.10.10/R1-May--8-02-14-05.568-3602
9 ftp://10.10.10.10/R1-May--8-02-17-06.489-3603
10 ftp://10.10.10.10/R1-May--8-02-20-07.340-3604 <- Most Recent

ホスト名がR1からRouter1へ変わったので一つ前のArchive9へロールバックする。

Router1#configure replace ftp://10.10.10.10/R1-May--8-02-17-06.489-3603
This will apply all necessary additions and deletions
to replace the current running configuration with the
contents of the specified configuration file, which is
assumed to be a complete configuration, not a partial
configuration. Enter Y if you are sure you want to proceed. ? [no]: yes # 確認で「yes」と入力
Loading R1-May--8-02-17-06.489-3603 !
[OK - 1105/4096 bytes]

Loading R1-May--8-02-17-06.489-3603 !
[OK - 1105/4096 bytes]

Total number of passes: 1
Rollback Done

R1#

R1へ戻った。戻したい状態が明確なので,hostname R1 と設定を変更するよりも安全に戻せる。
ただし,これは即時反映のため,一定時間で元に戻したい場合は,さらにオプションで「 trigger timer <1-120(min)> 」をつけて何分後に元に戻すかを指定する。
これで,「うわぁ!ロールバック元間違えた!」という時にも安心していられる(?)。

trigger timer オプションをつけて実行し,問題なければ,「configure confirm」で確定してロールバック完了となる。

以下は,ロールバック実行/1分後にロールバック自体を元に戻す流れ。

Switch1#configure replace ftp://10.10.10.10/R1-May--8-02-47-14.947-3616 revert trigger timer 1    # 1分後にロールバックを元にもどす
Writing Switch1-May--8-02-47-53.701-3618 Rollback Confirmed Change: Backing up current running config to ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618

This will apply all necessary additions and deletions
to replace the current running configuration with the
contents of the specified configuration file, which is
assumed to be a complete configuration, not a partial
configuration. Enter Y if you are sure you want to proceed. ? [no]: yes
Loading R1-May--8-02-47-14.947-3616 !
[OK - 1105/4096 bytes]

*May 8 02:47:53.814: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_BACKUP: Backing up current running config to ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618
Loading R1-May--8-02-47-14.947-3616 !
[OK - 1105/4096 bytes]

Total number of passes: 1
Rollback Done

R1#Rollback Confirmed Change: Rollback will begin in one minute. # ホスト名がR1に戻った。ロールバック完了。
Enter "configure confirm" if you wish to keep what you've configured
*May 8 02:47:55.655: Rollback:Acquired Configuration lock.
R1#
*May 8 02:47:55.771: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_START_ABSTIMER: User: console(Priv: 15, View: 0): Scheduled to rollback to config ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618 in 1 minutes
*May 8 02:47:55.775: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_WARNING_ABSTIMER: System will rollback to config ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618 in one minute. Enter "configure confirm" if you wish to keep what you've configured
R1#Rollback Confirmed Change: rolling to:ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618

Loading Switch1-May--8-02-47-53.701-3618 !
[OK - 1110/4096 bytes]

Loading Switch1-May--8-02-47-53.701-3618 !
[OK - 1110/4096 bytes]

!Pass 1
!List of Rollback Commands:
no hostname R1
hostname Switch1
end


Total number of passes: 1
Rollback Done

*May 8 02:48:55.776: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_ROLLBACK_START: Start rolling to: ftp://10.10.10.10/Switch1-May--8-02-47-53.701-3618
*May 8 02:48:55.852: Rollback:Acquired Configuration lock.
R1#
Switch1# # 1分経過したためロールバックがもどされ,ホスト名が Switch1 に戻った。

ロールバックを確定する流れは以下のようになる。

Switch1#configure replace ftp://10.10.10.10/R1-May--8-02-47-14.947-3616 revert trigger timer 1
Writing Switch1-May--8-02-55-47.783-3621 Rollback Confirmed Change: Backing up current running config to ftp://10.10.10.10/Switch1-May--8-02-55-47.783-3621

This will apply all necessary additions and deletions
to replace the current running configuration with the
contents of the specified configuration file, which is
assumed to be a complete configuration, not a partial
configuration. Enter Y if you are sure you want to proceed. ? [no]: yes
Loading R1-May--8-02-47-14.947-3616 !
[OK - 1105/4096 bytes]

*May 8 02:55:47.855: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_BACKUP: Backing up current running config to ftp://10.10.10.10/Switch1-May--8-02-55-47.783-3621
Loading R1-May--8-02-47-14.947-3616 !
[OK - 1105/4096 bytes]

Total number of passes: 1
Rollback Done

R1#Rollback Confirmed Change: Rollback will begin in one minute.
Enter "configure confirm" if you wish to keep what you've configured

*May 8 02:55:49.323: Rollback:Acquired Configuration lock.
R1#
R1#
*May 8 02:55:49.427: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_START_ABSTIMER: User: console(Priv: 15, View: 0): Scheduled to rollback to config ftp://10.10.10.10/Switch1-May--8-02-55-47.783-3621 in 1 minutes
*May 8 02:55:49.431: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_WARNING_ABSTIMER: System will rollback to config ftp://10.10.10.10/Switch1-May--8-02-55-47.783-3621 in one minute. Enter "configure confirm" if you wish to keep what you've configured
R1#
R1#configure confirm
R1#
*May 8 02:55:55.567: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_CONFIRM: User: console: Confirm the configuration change
R1#

今後はこれを活用していきたい。

もう1点良いと思うところは,ロールバック手順で設定変更を行えば,Configの投入順序を気にしなくても良いという点。
例えばIPSecの設定で,transform-set を先に設定してからcrypto mapの中で定義しなくてはならないが,そういったところを意識しなくても良い。
流し込みミスと併せて,事前に流し込みの順序を考える必要がないというのは結構利点だと思う。
R1(config-crypto-map)#set transform-set TS
%ERROR: transform set with tag "TS" does not exist.

こういうことが防げる。