debugコマンドとは

debugコマンドとは、ルータ/スイッチの動作をリアルタイムに確認するためのコマンドです。debugコマンドによって、ルータ/スイッチの動作を詳細に把握できます。ただ、debugコマンドはルータ/スイッチへ大きな負荷をかけてしまいます。実稼働中のルータ/スイッチでdebugコマンドを利用することは避けた方がよいです。

debugコマンドの例

debugコマンドは特権EXECモードで入力します。debugコマンドで確認できる動作はとてもたくさんあります。コマンドラインからdebugコマンドのヘルプを表示すると、次のようにいろんな指定ができます。

R1#debug ?
  IUA                       ISDN adaptation Layer options
  aaa                       AAA Authentication, Authorization and Accounting
  aal2_xgcpspi              AAL2_XGCP Service Provider Interface.
  access-expression         Boolean access expression
  acircuit                  Attachment Circuit information
  adjacency                 adjacency
  alarm-interface           Alarm Interface Card events
  all                       Enable all debugging
  alps                      ALPS debug information
  apple                     Appletalk information
  arap                      Appletalk Remote Access
  archive                   debug archive commands
  arp                       IP ARP and HP Probe transactions
  asnl                      Application Subscribe Notify Layer
  aspp                      ASPP information
  async                     Async interface information
  backhaul-session-manager  Backhaul SM options
  backup                    Backup events
  bcm560x                   BCM560X L2 Driver
  bgp                       BGP information
  bsc                       BSC information
  bstun                     BSTUN information
 --More—
-- omitted --

たくさんあるdebugコマンドのうち、以下の2つについて解説します。

  • debug ip packet
  • debug ip routing

debug ip packet

debug ip packetはルータが送受信するIPパケットの情報をリアルタイムにコンソールに表示します。

debug ip packet

#debug ip packet [<ACL>] [detail]

<ACL> : 関連付けるACL番号
detail : パケットの詳細な情報を表示

debug ip packetを実行すると、送受信するIPパケットすべての情報がコンソール上に表示されてしまい、コマンドラインの操作に支障をきたす可能性が高くなります。ACLを関連付けることで、表示するIPパケットを限定したほうがよいです。detailを付けると、IPヘッダのプロトコル番号やTCP/UDPのポート番号などの詳細な情報まで表示されるようになります。debug ip packetの例は、次の通りです。

R1#debug ip packet
IP packet debugging is on
R1#
*Mar  1 00:13:15.451: IP: s=192.168.12.1 (local), d=224.0.0.5 (Serial2/0), len 80, sending broad/multicast
R1#
*Mar  1 00:13:17.903: IP: s=192.168.12.2 (FastEthernet0/0), d=224.0.0.5, len 76, rcvd 0
*Mar  1 00:13:17.907: IP: s=192.168.12.1 (local), d=192.168.12.2 (FastEthernet0/0), len 80, sending
*Mar  1 00:13:17.907: IP: s=192.168.12.1 (local), d=192.168.12.2 (FastEthernet0/0), len 80, encapsulation failed
R1#
*Mar  1 00:13:19.463: IP: s=192.168.12.2 (Serial2/0), d=224.0.0.5, len 80, rcvd 0
~省略~

debug ip routing

debug ip routingコマンドで、ルーティングテーブルへのルート情報の登録、更新、削除のイベントをリアルタイムに表示できます。

debug ip routing

#debug ip routing [<ACL>]

<ACL> : 関連付けるACL番号

ACLを関連付けることで、ルーティングテーブルの特定のルート情報のみを対象とすることもできます。以下は、debug ip routingを有効にしている状態で、インタフェースをshutdown→no shutdownしたときの例です。

R1#debug ip routing
IP routing debugging is on
R1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#interface serial 2/0
R1(config-if)#shutdown
R1(config-if)#
*Mar  1 00:20:22.383: RT: is_up: Serial2/0 0 state: 6 sub state: 1 line: 0 has_route: True
*Mar  1 00:20:22.383: RT: interface Serial2/0 removed from routing table
*Mar  1 00:20:22.383: RT: del 192.168.21.0/30 via 0.0.0.0, connected metric [0/0]
*Mar  1 00:20:22.383: RT: delete subnet route to 192.168.21.0/30
*Mar  1 00:20:22.387: RT: NET-RED 192.168.21.0/30
*Mar  1 00:20:22.387: RT: delete network route to 192.168.21.0
*Mar  1 00:20:22.387: RT: NET-RED 192.168.21.0/24
R1(config-if)#
*Mar  1 00:20:24.371: %LINK-5-CHANGED: Interface Serial2/0, changed state to administratively down
R1(config-if)#
*Mar  1 00:20:24.379: RT: is_up: Serial2/0 0 state: 6 sub state: 1 line: 0 has_route: False
*Mar  1 00:20:25.371: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to down
R1(config-if)#
*Mar  1 00:20:25.371: RT: is_up: Serial2/0 0 state: 6 sub state: 1 line: 0 has_route: False
R1(config-if)#no shutdown
R1(config-if)#
*Mar  1 00:20:29.947: RT: is_up: Serial2/0 0 state: 4 sub state: 1 line: 0 has_route: False
R1(config-if)#
*Mar  1 00:20:31.931: %LINK-3-UPDOWN: Interface Serial2/0, changed state to up
R1(config-if)#
*Mar  1 00:20:31.935: RT: is_up: Serial2/0 0 state: 4 sub state: 1 line: 0 has_route: False
*Mar  1 00:20:31.979: RT: is_up: Serial2/0 1 state: 4 sub state: 1 line: 0 has_route: False
*Mar  1 00:20:31.979: RT: SET_LAST_RDB for 192.168.21.0/30
  NEW rdb: is directly connected

*Mar  1 00:20:31.983: RT: add 192.168.21.0/30 via 0.0.0.0, connected metric [0/0]
*Mar  1 00:20:31.983: RT: NET-RED 192.168.21.0/30
*Mar  1 00:20:31.983: RT: interface Serial2/0 added to routing table
*Mar  1 00:20:32.955: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
R1(config-if)#
*Mar  1 00:20:32.959: RT: is_up: Serial2/0 1 state: 4 sub state: 1 line: 0 has_route: True

インタフェースをshutdownすると、直接接続のルート情報(192.168.21.0/24)がルーティングテーブルから削除されています。そして、no shutdownすると、直接接続のルート情報(192.168.12.0/24)がルーティングテーブルに登録されていることがわかります。

条件付きデバッグ(Conditional Debugging)

条件付きデバッグは、debugコマンドの出力をフィルタして確認したい内容だけを表示します。debugコマンドの出力は、とても大量になってしまう可能性があります。効率よくdebugコマンドで動作を確認するためには、debugコマンドの出力をフィルタします。

debugコマンドの出力をフィルタする条件を決めるには、特権EXECモードで次のコマンドを入力します。

debugコマンドの出力をフィルタする条件#debug condition <condition>

<condition> : debugコマンドの出力をフィルタする条件

フィルタする条件はとてもたくさん設定できます。CLIからヘルプを見ると、以下のようにたくさんの設定ができることがわかります。

SW1#debug condition ?
  application  Application
  called       called number
  calling      calling
  card         card
  glbp         interface group
  interface    interface
  ip           IP address
  mac-address  MAC address
  match-list   apply the match-list
  standby      interface group
  username     username
  vcid         VC ID
  vlan         vlan
  voice-port   voice-port number
  xconnect     Xconnect conditional debugging on segment pair

一番よく使うわかりやすい条件はインタフェースでしょう。以下の設定でdebugコマンドの出力から特定のインタフェースに関するものだけを表示します。

特定のインタフェースのdebugコマンドの出力を表示#debug condition interface <interface-name>

<interface-name> : debugコマンドの出力を表示したいインタフェース名

debug condition interfaceの例

debug condition interfaceで特定のインタフェースについてのdebugコマンドの出力だけを表示する例をあげます。debug ip ripコマンドでRIPパケットの定期的な送受信がコンソール上にリアルタイムに表示されます。

R2#debug ip rip
RIP protocol debugging is on
R2#
*Mar  1 00:12:58.331: RIP: received v2 update from 192.168.12.1 on FastEthernet0/0
*Mar  1 00:12:58.331:      10.1.1.0/24 via 0.0.0.0 in 1 hops
R2#
*Mar  1 00:13:06.435: RIP: received v2 update from 192.168.23.3 on FastEthernet0/1
*Mar  1 00:13:06.435:      10.3.3.0/24 via 0.0.0.0 in 1 hops
R2#
*Mar  1 00:13:18.711: RIP: sending v2 update to 224.0.0.9 via FastEthernet0/0 (192.168.12.2)
*Mar  1 00:13:18.711: RIP: build update entries
*Mar  1 00:13:18.711:   10.3.3.0/24 via 0.0.0.0, metric 2, tag 0
*Mar  1 00:13:18.715:   192.168.23.0/24 via 0.0.0.0, metric 1, tag 0
R2#
*Mar  1 00:13:21.659: RIP: sending v2 update to 224.0.0.9 via FastEthernet0/1 (192.168.23.2)
*Mar  1 00:13:21.659: RIP: build update entries
*Mar  1 00:13:21.659:   10.1.1.0/24 via 0.0.0.0, metric 2, tag 0
*Mar  1 00:13:21.663:   192.168.12.0/24 via 0.0.0.0, metric 1, tag 0

FastEthernet0/0で送受信するRIPパケットのみを表示するために、以下の条件を設定します。

R2#debug condition interface FastEthernet 0/0
Condition 1 set

そうすると、debug ip ripコマンドの出力は、FastEthernet0/0についてのものだけとなります。

*Mar  1 00:15:35.767: RIP: sending v2 update to 224.0.0.9 via FastEthernet0/0 (192.168.12.2)
*Mar  1 00:15:35.767: RIP: build update entries
*Mar  1 00:15:35.767:   10.3.3.0/24 via 0.0.0.0, metric 2, tag 0
*Mar  1 00:15:35.771:   192.168.23.0/24 via 0.0.0.0, metric 1, tag 0
R2#
*Mar  1 00:15:52.115: RIP: received v2 update from 192.168.12.1 on FastEthernet0/0
*Mar  1 00:15:52.115:      10.1.1.0/24 via 0.0.0.0 in 1 hops

debugの確認

有効化しているdebugコマンドを確認するためには、特権EXECモードで以下のコマンドを入力します。

debugの確認#show debugging

debugコマンドの出力をフィルタする条件を設定している場合は、show debuggingコマンドであわせて表示されます。条件のみを確認したい場合は、show debugging conditionコマンドを利用します。

以下は、show debuggingのサンプルです。

R2#show debugging
IP routing:
  RIP protocol debugging is on





Condition 1: interface Fa0/0 (1 flags triggered)
        Flags: Fa0/0

R2#show debugging condition

Condition 1: interface Fa0/0 (1 flags triggered)
        Flags: Fa0/0

debugの停止

debugを停止するには、有効にしたdebugコマンドの前に「no」をつけて入力すればOKです。または、undeug allコマンドですべてのdebugコマンドを停止させます。

debugの停止

#no <有効にしたdeubコマンド>

または

#undebug all

R1#debug ip packet
IP packet debugging is on
R1#undebug all
All possible debugging has been turned off
「undebug all」は省略して「u all」だけで認識されます。

Ciscoのキホン