Cisco IOS Operation Tips.
[追記]
- id:stereocat:20091124:1259075105
はじめに
えーと。秋葉原の某ショップで Catalyst3750 を購入してしまいました。もともと Cisco 1812 or 1841 を買って自宅のルータに使おうかなーと思っていたのだけど、いざ店に見に行ってみたら中古 C3750-24TS-E が 10 万切ってるんだよね。FastEther のスイッチだからかな? それにしたって ipservices がデフォルトで入ってるし。これは、と思って衝動買いしましたよ。これで自宅でも VLAN 切り放題だぜー、とか言ったって、FastEther で VLAN 切るだけなら別に Cat2950 だって今や中古で 2 万円とかで買えちゃう訳よ。L3買ったんだったら何かしないと買った意味がないなーと思っていたのです。
とりあえずは、最近のIOSのFeatureとして運用上使えそうな機能がいくつか入ってるのでその辺をみてみたいと思う。
- Contextual Configuration Diff Utility
- Configuration Replace and Configuration Rollback
なお Cat3750E の場合、Cisco Feature Navigator で確認すると、上記の Feature は IOS/12.2(44)SE2 以降で使えるようになっている。
まずは、現場で役立つ運用管理機能 IOS Operation Tips. を元に、基本的な使い方の確認をする。各機能がどんなものかについてはこの資料を参照してください。文献自体はいくつかピックアップしておくけど、まだ読み切れていない…。
参考文献
Configuration Archive
コマンド確認
core#archive ? config Archive the running config download-sw Download a new copy of software from a server download-ucode Download a new copy of microcode from a server log Manage archive log tar List or extract files in a tar image upload-sw Upload an existing copy of the software to a server core(config)#archive core(config-archive)#? Archive configuration commands: default Set a command to its defaults exit Exit from archive configuration mode log Logging commands maximum maximum number of backup copies no Negate a command or set its defaults path path for backups rollback Rollback parameters time-period Period of time in minutes to automatically archive the running-config write-memory Enable automatic backup generation during write memory
基本設定。
core(config)#archive core(config-archive)#log config core(config-archive-log-cfg)#exit core(config-archive)#path flash:/archive/Router core(config-archive)#maximum 10 core(config-archive)#write-memory core(config-archive)#time-period 1440 core#sh run | begin archive archive path flash:/archive/Router write-memory time-period 1440
Archiveをとる。
core#archive config core#show archive The maximum archive configurations allowed is 14. There are currently 1 archive configurations saved. The next archive file will be named flash:/archive/Router-<timestamp>-1 Archive # Name 1 :Error - Bad file number <- Most Recent 2 :Error - Bad file number 3 4 5 6 7 8 9 10 core#
エラーになってた。保存先のディレクトリは作っておかないといけない。
core#mkdir flash:archive Create directory filename [archive]? Created dir flash:archive core# core#show archive The maximum archive configurations allowed is 14. There are currently 2 archive configurations saved. The next archive file will be named flash:/archive/Router-<timestamp>-2 Archive # Name 1 :Error - Bad file number 2 flash:/archive/RouterNov-22-10-36-23-1 <- Most Recent 3 4 5 6 7 8 9 10 core#
参考文献を見るとファイル名は連番がつくだけなのだけど、実際にはタイムスタンプが入るようだ。service timestamp とかの設定によるのか?
ちなみに、ログのタイムスタンプの設定をいじるとファイル名もかわる。
core(config)#service timestamps log datetime msec localtime year
Archiveのファイル名が途中から変わっていることがわかる。
Building configuration... [OK] core#show archive The maximum archive configurations allowed is 14. There are currently 6 archive configurations saved. The next archive file will be named flash:/archive/Router-<timestamp>-6 Archive # Name 1 :Error - Bad file number 2 flash:/archive/RouterNov-22-10-36-23-1 3 flash:/archive/RouterNov-22-10-41-09-2 4 flash:/archive/RouterNov-22-10-48-57-3 5 flash:/archive/RouterNov-22-2009-19-52-12.571-4 6 flash:/archive/RouterNov-22-2009-19-54-43.020-5 <- Most Recent 7 8 9 10 core#
なお、各 Archive の中身は以下のコマンドで読める。扱いとしては普通のファイルと変わらない。
core#more flash:/archive/RouterNov-22-2009-19-54-43.020-5
個々では参考文献ベースでやってるので Archive のベースファイル名を Router にしちゃってるけど、実際には [ホスト名-(timestamp)-(N)] とかにしておくのが良さそうだ。
Contexitual Configuration Diff Utility
適当に設定変更してみる。
core(config)#int fa1/0/24 core(config-if)#no switchport core(config-if)#ip add 10.0.0.1 2w3d: %LINK-3-UPDOWN: Interface FastEthernet1/0/24, changed state to down core(config-if)#ip add 10.0.0.1 255.255.255.0 core(config-if)#end core#sh run int 2w3d: %SYS-5-CONFIG_I: Configured from console by console core#sh run int fa1/0/24 Building configuration... Current configuration : 142 bytes ! interface FastEthernet1/0/24 no switchport ip address 10.0.0.1 255.255.255.0 spanning-tree portfast spanning-tree bpduguard enable end core#wr mem Building configuration... [OK] core#sh archive The maximum archive configurations allowed is 14. There are currently 3 archive configurations saved. The next archive file will be named flash:/archive/Router-<timestamp>-3 Archive # Name 1 :Error - Bad file number 2 flash:/archive/RouterNov-22-10-36-23-1 3 flash:/archive/RouterNov-22-10-41-09-2 <- Most Recent 4 5 6 7 8 9 10 core#
Archiveされたコンフィグを元に、世代差分を取ってみる
core#show archive config differences flash:archive/RouterNov-22-10-36-2 flash:archive/RouterNov-22-10-41-09-2 ! !Contextual Config Diffs: interface FastEthernet1/0/24 +no switchport +ip address 10.0.0.1 255.255.255.0 +ntp clock-period 36028651 interface FastEthernet1/0/24 -switchport mode access -ntp clock-period 36028655
参考文献にあるよくやるであろうコマンド。Startup/Running の比較。
core#show archive config differences nvram:startup-config system:running-config ! !Contextual Config Diffs: +ntp clock-period 36028652 -ntp clock-period 36028651 core#
あ、write-memory で archive 取ってるからほとんど差分がないや。まあ、差分とれるということはわかる。
Configuration Replace and Rollback
Basic Operation
まずはリプレースの方から試す。今の設定を捨てて、古い Archive に戻すというのをやってみる。
世代間の設定差分の確認。
core#show archive config differences flash:/archive/RouterNov-22-2009-12.571-4 flash:/archive/RouterNov-22-2009-19-54-43.020-5 ! !Contextual Config Diffs: interface FastEthernet1/0/24 +no switchport +ip address 10.0.0.1 255.255.255.0 core#
Fa1/0/24 の中身を追加して最新のコンフィグにしてある。
リプレース実行。1世代前のに戻す。
core#configure replace flash:/archive/RouterNov-22-2009-19-52-12.571-4 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 2w3d: Rollback:Acquired Configuration lock. Total number of passes: 1 Rollback Done core# Nov 22 2009 20:16:37.451: %LINK-3-UPDOWN: Interface FastEthernet1/0/24, changed state to down core# core#sh run int fa1/0/24 Building configuration... Current configuration : 36 bytes ! interface FastEthernet1/0/24 end core#
戻っていることがわかる。
Time Based Rollback
ロールバックはリプレースコマンドの時限オプションで実行する。一定時間、confirm コマンドが発行されなければ、指定したコンフィグにリプレースするという操作をする。
状態確認。時限ロールバック設定をしていないときはこういう出力。
core#show archive config rollback timer %No Rollback Confirmed Change pending
Config/Archive確認。変更前は Archive#7, Fa1/0/24 には IP 10.0.0.1/24 が設定されている。
core#show archive The maximum archive configurations allowed is 14. There are currently 7 archive configurations saved. The next archive file will be named flash:/archive/Router-<timestamp>-7 Archive # Name 1 :Error - Bad file number 2 flash:/archive/RouterNov-22-10-36-23-1 3 flash:/archive/RouterNov-22-10-41-09-2 4 flash:/archive/RouterNov-22-10-48-57-3 5 flash:/archive/RouterNov-22-2009-19-52-12.571-4 6 flash:/archive/RouterNov-22-2009-19-54-43.020-5 7 flash:/archive/RouterNov-22-2009-20-27-38.085-6 <- Most Recent 8 9 10 core#sh run int fa1/0/24 Building configuration... Current configuration : 86 bytes ! interface FastEthernet1/0/24 no switchport ip address 10.0.0.1 255.255.255.0 end core#
時間指定をしてリプレースコマンドを実行する。今回は、リプレースコマンドを発行して 5 分間 confirm コマンドが発行されなければ、指定したコンフィグ (Archive#7) に戻す。
core#configure replace flash:/archive/RouterNov-22-2009-19-54-43.020-5 time ? <1-120> confirmation time in minutes core#configure replace flash:/archive/RouterNov-22-2009-19-54-43.020-5 time 5 Rollback Confirmed Change: Backing up current running config to flash:/archive/RouterNov-22-2009-21-04-08.568-7 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 Nov 22 2009 21:04:11.521: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_BACKUP: Backing up current running config to flash:/archive/RouterNov-22-2009-21-04-08.568-7 Total number of passes: 1 Rollback Done core# 2w3d: Rollback:Acquired Configuration lock. core# Nov 22 2009 21:04:16.546: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_START_ABSTIMER: User: console: Scheduled to rollback to config flash:/archive/RouterNov-22-2009-21-04-08.568-7 in 5 minutes core#
状態確認。カウントダウン中はこういう表示になる。
core#show archive config rollback timer Time configured(or reconfigured): 21:04:11 JST Sun Nov 22 2009 Timer type: absolute timer Timer value: 5 min User: console URL of saved config file: flash:/archive/RouterNov-22-2009-21-04-08.568-7 core#
カウントダウン中に設定変更をする。Fa1/0/24を消す。confirm はしないで放置してロールバックされるかどうかを確認する。
core#conf t Enter configuration commands, one per line. End with CNTL/Z. core(config)#default interface fa1/0/24 Interface FastEthernet1/0/24 set to default configuration core(config)#end core#sh run int fa 1/0/24 Building configuration... Current configuration : 36 bytes ! interface FastEthernet1/0/24 end core# Nov 22 2009 21:05:12.615: %SYS-5-CONFIG_I: Configured from console by console core# Nov 22 2009 21:05:14.586: %LINK-3-UPDOWN: Interface FastEthernet1/0/24, changed state to down core#
そのまま 5 分放置しておく。
指定した時間の1分前になると、"configure confirm" を発行して設定を確定しない場合はロールバックするよ、という警告メッセージが出る。
core# core#Rollback Confirmed Change: Rollback will begin in one minute. Enter "configure confirm" if you wish to keep what you've configured Nov 22 2009 21:08:16.551: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_WARNING_ABSTIMER: System will rollback to config flash:/archive/RouterNov-22-2009-21-04-08.568-7 in one minute. Enter "configure confirm" if you wish to keep what you've configured core#
さらに放置するとロールバックが実行される。設定差分を出して何をどう変えたのかを表示してくれる。
core#Rollback Confirmed Change: rolling to:flash:/archive/RouterNov-22-2009-21-04-08.568-7 Nov 22 2009 21:09:16.546: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_ROLLBACK_START: Start rolling to: flash:/archive/RouterNov-22-2009-21-04-08.568-7 core# !Pass 1 ! !List of Commands: no ntp clock-period 36028649 interface FastEthernet1/0/24 no switchport ip address 10.0.0.1 255.255.255.0 ntp clock-period 36028655 end Total number of passes: 1 Rollback Done 2w3d: Rollback:Acquired Configuration lock. Nov 22 2009 21:09:20.749: %LINK-3-UPDOWN: Interface FastEthernet1/0/24, changed state to down core# core#show run int fa1/0/24 Building configuration... Current configuration : 86 bytes ! interface FastEthernet1/0/24 no switchport ip address 10.0.0.1 255.255.255.0 end core#
こんな感じで勝手にロールバックする。
感想
コンフィグファイルを外部のサーバに集めて rcs/cvs とかでバージョン管理しているというところは多いだろうし、Rancid とかそういうコンフィグ管理ソフトウェアなんてのもある。とはいえ、ビル停電に伴うシステム変更とか、一部のネットワークが切れていてそういうシステムにうまくつなげない状態で障害が起きて早急に前のコンフィグにいったん戻さないといけない、という状況もあり得るわけですよ。まあ、作業用のノートPCとかにコンフィグ取っておいたりするんだけど。Config Archive はそういう状況を考えるとすごく使えるよな。Flashの容量とかにもよりけりだろうけど。
Config replace はメモリ容量の逼迫したスイッチ(やたらACLがたくさん書いてあるとか)だと要注意なのかもしれない。少なくとも、運用に際しては、リプレースしたときの挙動とか実際にどういう動きをするのかとか、運用担当者がある程度触ってみて、基本手順を起こさないといけないのだけど、使える機能であるというのは確かだろう。
Config Diff はこれはあれば普通に使うよな。diff startup running とかその場ですぐにやれるようになっているというのは大きいと思う。すばらしい。