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.

こういうことが防げる。

IOSの設定ファイルをFTPサーバへ保存して世代管理する。

Cisco IOSでConfigの世代管理をターミナルソフトでログ出力してローカル保存することから脱却したいと考え,AnsibleやNetconfなども考えたが今の現場では人力設定変更からの脱却がなかなかに難しい。(政治的にも運用的にもスキルセット的にも)

ということで,現行の環境をできるだけそのままに新しい機能では無いけど,「archive」コマンドで少しは幸せになれそうな気がしたので検証。

今回の検証環境はシンプルに,ルータ2台,FTPサーバ1台とする。

FTPサーバ(10.10.10.10)へConfigをアーカイブする

「archive」コマンドはマニュアルでも実行でき,設定しておけば自動で指定した場所へConfigを保存してくれる。デフォルトでは10世代まで保存となっており,maximumオプションで1~14まで指定ができる。

IOSのコンフィギュレーション アーカイブ

図のR1とR2に以下定義を入れる。

! FTPの基本設定
ip ftp source-interface Ethernet0/0
ip ftp username user
ip ftp password Test123

! アーカイブ設定
archive
path ftp://10.10.10.10/$h # $h は機器のホスト名
write-memory # 設定保存時にアーカイブ実行
time-period 3 # アーカイブを実行するタイミングの指定。今回は検証なので3分とした。

設定保存時と定期的にアーカイブをする設定を入れたが,time-periodはアーカイブをしたタイミングを起点に何分後という説明だったので,自動と手動のどちらも見るのか気になり確認をしたところ,archiveを設定した時点から定期的に取得するらしく,「archive config」コマンドで手動で実行したアーカイブは無視されていた。

R1#show archive
The maximum archive configurations allowed is 10.
The next archive file will be named ftp://10.10.10.10/R1--9
Archive # Name
1 ftp://10.10.10.10/R1-Apr-30-14-27-36.582-0
2 ftp://10.10.10.10/R1-Apr-30-14-28-49.035-1 # archiveコマンド設定後,最初の自動アーカイブ
3 ftp://10.10.10.10/R1-Apr-30-14-31-50.160-2 # 初回から3分後,2回目のアーカイブ
4 ftp://10.10.10.10/R1-Apr-30-14-34-51.091-3 # 3回目の自動アーカイブ
5 ftp://10.10.10.10/R1-Apr-30-14-34-59.006-4 # 「archive config」コマンドで手動でアーカイブを実行
6 ftp://10.10.10.10/R1-Apr-30-14-35-09.006-5 # 「archive config」コマンドで手動でアーカイブを実行
7 ftp://10.10.10.10/R1-Apr-30-14-37-52.197-6 # 4回目の自動アーカイブ
8 ftp://10.10.10.10/R1-Apr-30-14-39-17.723-7 # 「archive config」コマンドで手動でアーカイブを実行
9 ftp://10.10.10.10/R1-Apr-30-14-40-53.180-8 < -- Most Recent

この構成にすることでアーカイブと対となるロールバックも可能になる。

例えば,LAN側インタフェースの設定を入れたあと,誤って設定を消してしまった場合,「configure replace」コマンドでロールバックを行うことができる。

R1#show ip
*Apr 30 14:51:51.064: %LINK-3-UPDOWN: Interface Ethernet0/1, changed state to up
*Apr 30 14:51:52.072: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/1, changed state to up
R1#show ip int brie
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 10.10.10.1 YES manual up up
Ethernet0/1 192.168.1.1 YES manual up up
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down
R1#
R1#copy run startup-config
Destination filename [startup-config]?
Building configuration...
[OK]
Writing R1-Apr-30-14-51-57.355-12
R1#
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#default interface e0/1 #やっちまった!!!
Interface Ethernet0/1 set to default configuration
R1(config)#do show ip int brie
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 10.10.10.1 YES manual up up
Ethernet0/1 unassigned YES TFTP up up
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down

手動で簡単に戻せるレベルだが,せっかくアーカイブをとっているので一つ前の設定へロールバックする。

R1#show archive
The maximum archive configurations allowed is 10.
The next archive file will be named ftp://10.10.10.10/R1-<timestamp>-15
Archive # Name
1 ftp://10.10.10.10/R1-Apr-30-14-35-09.006-5
2 ftp://10.10.10.10/R1-Apr-30-14-37-52.197-6
3 ftp://10.10.10.10/R1-Apr-30-14-39-17.723-7
4 ftp://10.10.10.10/R1-Apr-30-14-40-53.180-8
5 ftp://10.10.10.10/R1-Apr-30-14-43-54.061-9
6 ftp://10.10.10.10/R1-Apr-30-14-46-54.980-10
7 ftp://10.10.10.10/R1-Apr-30-14-49-56.023-11
8 ftp://10.10.10.10/R1-Apr-30-14-51-57.355-12
9 ftp://10.10.10.10/R1-Apr-30-14-52-56.856-13
10 ftp://10.10.10.10/R1-Apr-30-14-55-58.039-14 <- Most Recent

一つ前は「ftp://10.10.10.10/R1-Apr-30-14-52-56.856-13」なので,これを指定してロールバックを実行する。

R1#configure replace ftp://10.10.10.10/R1-Apr-30-14-52-56.856-13
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-Apr-30-14-52-56.856-13 !
[OK - 1106/4096 bytes]

Loading R1-Apr-30-14-52-56.856-13 !
[OK - 1106/4096 bytes]

Total number of passes: 1
Rollback Done

R1#
*Apr 30 15:00:31.984: Rollback:Acquired Configuration lock.
R1#show ip int brie
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 10.10.10.1 YES manual up up
Ethernet0/1 192.168.1.1 YES TFTP up up
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down
R1#show arc
R1#show archive
The maximum archive configurations allowed is 10.
The next archive file will be named ftp://10.10.10.10/R1-<timestamp>-16
Archive # Name
1 ftp://10.10.10.10/R1-Apr-30-14-37-52.197-6
2 ftp://10.10.10.10/R1-Apr-30-14-39-17.723-7
3 ftp://10.10.10.10/R1-Apr-30-14-40-53.180-8
4 ftp://10.10.10.10/R1-Apr-30-14-43-54.061-9
5 ftp://10.10.10.10/R1-Apr-30-14-46-54.980-10
6 ftp://10.10.10.10/R1-Apr-30-14-49-56.023-11
7 ftp://10.10.10.10/R1-Apr-30-14-51-57.355-12
8 ftp://10.10.10.10/R1-Apr-30-14-52-56.856-13
9 ftp://10.10.10.10/R1-Apr-30-14-55-58.039-14
10 ftp://10.10.10.10/R1-Apr-30-14-58-59.227-15 <- Most Recent
R1#

無事に設定はもどり,アーカイブ番号は戻るのではなく更新される。

いちいちどの定義を入れ直さなくてはダメなのか,という確認が不要なので便利だと思うし,運用に入った環境では人的ミスの削減にもつながるはず。
ちなみにアーカイブの差分も以下コマンドで確認できる。

R11#$R11-Apr-30-15-25-28.087-24 ftp://10.10.10.10/R1-Apr-30-15-23-03.315-23
Loading R11-Apr-30-15-25-28.087-24 !
[OK - 1106/4096 bytes]

Loading R1-Apr-30-15-23-03.315-23 !
[OK - 1105/4096 bytes]
!Contextual Config Diffs:
+hostname R1
-hostname R11

なお,FTPサーバ側にもちゃんとファイルが保存されている。

[user@localhost ~]$ ls -lrt
合計 128
-rw-r--r--. 1 user user 1093 4月 30 10:27 R1-Apr-30-14-27-36.582-0
-rw-r--r--. 1 user user 1073 4月 30 10:28 R2-Apr-30-14-28-22.973-1
-rw-r--r--. 1 user user 1093 4月 30 10:28 R1-Apr-30-14-28-49.035-1
-rw-r--r--. 1 user user 1073 4月 30 10:29 R2-Apr-30-14-29-06.901-2
-rw-r--r--. 1 user user 1093 4月 30 10:31 R1-Apr-30-14-31-50.160-2
-rw-r--r--. 1 user user 1073 4月 30 10:32 R2-Apr-30-14-32-08.023-3
-rw-r--r--. 1 user user 1093 4月 30 10:34 R1-Apr-30-14-34-51.091-3
-rw-r--r--. 1 user user 1093 4月 30 10:34 R1-Apr-30-14-34-59.006-4
-rw-r--r--. 1 user user 1093 4月 30 10:35 R1-Apr-30-14-35-09.006-5
-rw-r--r--. 1 user user 1073 4月 30 10:35 R2-Apr-30-14-35-08.939-4
-rw-r--r--. 1 user user 1093 4月 30 10:37 R1-Apr-30-14-37-52.197-6
-rw-r--r--. 1 user user 1073 4月 30 10:38 R2-Apr-30-14-38-09.972-5
-rw-r--r--. 1 user user 1093 4月 30 10:39 R1-Apr-30-14-39-17.723-7
-rw-r--r--. 1 user user 1093 4月 30 10:40 R1-Apr-30-14-40-53.180-8
-rw-r--r--. 1 user user 1073 4月 30 10:41 R2-Apr-30-14-41-10.819-6
-rw-r--r--. 1 user user 1093 4月 30 10:43 R1-Apr-30-14-43-54.061-9
-rw-r--r--. 1 user user 1073 4月 30 10:44 R2-Apr-30-14-44-10.959-7
-rw-r--r--. 1 user user 1093 4月 30 10:46 R1-Apr-30-14-46-54.980-10
-rw-r--r--. 1 user user 1073 4月 30 10:47 R2-Apr-30-14-47-11.101-8
-rw-r--r--. 1 user user 1093 4月 30 10:49 R1-Apr-30-14-49-56.023-11
-rw-r--r--. 1 user user 1073 4月 30 10:50 R2-Apr-30-14-50-11.460-9
-rw-r--r--. 1 user user 1106 4月 30 10:51 R1-Apr-30-14-51-57.355-12
-rw-r--r--. 1 user user 1106 4月 30 10:52 R1-Apr-30-14-52-56.856-13
-rw-r--r--. 1 user user 1073 4月 30 10:53 R2-Apr-30-14-53-11.594-10
-rw-r--r--. 1 user user 1083 4月 30 10:55 R1-Apr-30-14-55-58.039-14
-rw-r--r--. 1 user user 1073 4月 30 10:56 R2-Apr-30-14-56-11.761-11
-rw-r--r--. 1 user user 1083 4月 30 10:58 R1-Apr-30-14-58-59.227-15
-rw-r--r--. 1 user user 1073 4月 30 10:59 R2-Apr-30-14-59-11.901-12
-rw-r--r--. 1 user user 1105 4月 30 11:02 R1-Apr-30-15-02-00.102-16
-rw-r--r--. 1 user user 1073 4月 30 11:02 R2-Apr-30-15-02-12.252-13
-rw-r--r--. 1 user user 1105 4月 30 11:05 R1-Apr-30-15-05-00.981-17
-rw-r--r--. 1 user user 1073 4月 30 11:05 R2-Apr-30-15-05-12.392-14