調試命令是故障定位的「顯微鏡」,但濫用會導致 CPU 100%、設備無響應。本文系統講解思科路由器全局調試架構、協議調試 (ARP/RIP)、接口調試、VTY 會話輸出重定向、安全調試守則,助您精準排錯不傷業務。
默認調試輸出僅發送到 Console 口。遠程 Telnet/SSH 會話必須執行:
Router# terminal monitor
! 當前 VTY 會話將顯示 logging monitor 級別的日志與 debug 輸出
! 退出會話自動失效,不影響其他會話

debug ip arp)Router# clear ip arp ! 清空 ARP 緩存觸發重學習
Router# debug ip arp
IP ARP: sent req src 192.168.1.1 0011.2233.4455, dst 192.168.1.2 0000.0000.0000 FastEthernet0/0
IP ARP: rcvd reply src 192.168.1.2 00aa.bbcc.ddee, dst 192.168.1.1 FastEthernet0/0
Router# undebug all ! 及時關閉
! 或
Router# no debug ip arp
debug ip rip)Router# debug ip rip
RIP: sending v2 update to 224.0.0.9 via FastEthernet0/0 (192.168.1.1)
RIP: build update entries
192.168.2.0/24 via 0.0.0.0, metric 1, tag 0
RIP: received v2 update from 192.168.1.2 on FastEthernet0/0
10.0.0.0/8 via 192.168.1.2, metric 2
Router# undebug all
提示: RIP 每 30 秒自動更新,無需強制觸發。調試輸出量大時建議配合 access-list 過濾:debug ip rip 100 (ACL 100 匹配特定網段)。
debug ip icmp : ICMP 請求/回應debug ip packet [acl] [detail] : IP 包處理 (極其耗 CPU,必須配合 ACL 限制範圍)debug ip routing : 路由表變更debug ppp negotiation : PPP 協商 (撥號/專線)debug crypto isakmp / ipsec : VPN 隧道協商Router# debug serial interface
Serial0/0: HDLC myseq 123, mineseen 122, yourseen 124, DTE
Serial0/0: HDLC myseq 124, mineseen 123, yourseen 125, DTE
! 每 10 秒交換一次保活包,序列號遞增雙向確認
! 連續 3 次未收到回應 → 接口 Line Protocol Down
Router# show interface serial 0/0
Serial0/0 is up, line protocol is up
Hardware is HD64570
...
Keepalive set (10 sec)
Last input 00:00:00, output 00:00:00, output hang never
Router# undebug all
debug serial packet : 串行封包詳情debug frame-relay lmi : 帧中繼 LMI 狀態debug ppp negotiation : PPP 協商階段debug isdn q921 / q931 : ISDN 信令Router# debug cdp packets
CDP-PK: Sending packet on FastEthernet0/0
CDP-PK: Received packet from Switch-Core on FastEthernet0/0
Router# undebug all
| 原則 | 執行標準 |
|---|---|
| 最小範圍 | 必須配合 ACL 限制調試範圍:debug ip packet 100 |
| 最短時間 | 捕獲足夠信息立即 undebug all (或 u all) |
| 非高峰時段 | 業務低峰期操作,避開早晚高峰 |
| 預留退出 | 打開第二個 Console/VTY 會話,防主會話卡死無法輸入關閉命令 |
| CPU 監控 | 調試前後執行 show processes cpu sorted,CPU>70% 立即停止 |
| 輸出緩衝 | 配置 logging buffered 131072 避免 Console 阻塞 |
| 記錄歸檔 | 關鍵調試輸出重定向至 Syslog 服務器或本地文件 |
! 僅調試特定條件觸發的事件
Router# debug condition interface FastEthernet0/0
Router# debug condition username admin
Router# debug condition vlan 100
Router# debug ip packet condition
! 只有滿足條件時才產生調試輸出,大幅降低開銷
Router# show debug condition
Condition 1: interface Fa0/0 (Flags: 0x1)
Condition 2: username admin (Flags: 0x1)
...
Router# no debug condition all ! 清除條件
調試是雙刃劍,善用則斬斷故障迷霧,濫用則斬斷業務生命線。請將「條件調試 + ACL 過濾 + 限時自動關閉」作為標準操作規程。