教你使用IOS内置的排错命令

在平常进行网络配置的时候,一般来说除了路由器设备没有别的工具可以让你进行网络的排错,下面就介绍一些路由器内置的命令来进行网络排错,虽然有些命令很基本,但是一些扩展项还是很好玩的。

1.Ping命令
Ping是最基本的测试连通性的命令了,先来一个标准的Ping
Router#ping 10.123.123.7
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.123.123.7, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
再来一个扩展ping,只能在特权模式哦:
Router#ping
Protocol [ip]:
Target IP address: 10.123.123.7
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Source address or interface:
Set DF bit in IP header? [no]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Sending 5, 100-byte ICMP Echos to 10.123.123.7, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
然后以扩展Ping为基础,进行不同的选择来Ping的更猛烈
比如使用record选项来记录数据包路径
Router#ping
Protocol [ip]:
Target IP address: 131.108.1.115

Extended commands [n]: y

Loose, Strict, Record, Timestamp, Verbose[none]: r
Number of hops [ 9 ]:
Sending 5, 100-byte ICMP Echos to 131.108.1.115, timeout is 2 seconds:
Packet has IP options: Total option bytes= 39, padded length=40
Record route: <*>
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
   (0.0.0.0)
The following display is a detail of the Echo packet section:

0 in 4 ms. Received packet has options
    Total option bytes= 40, padded length=40
    Record route: 160.89.80.31 131.108.6.10 131.108.1.7 131.108.1.115
    131.108.1.115 131.108.6.7 160.89.80.240 160.89.80.31 <*> 0.0.0.0
End of list

1 in 6 ms. Received packet has options

使用这个选项的时候必须在路径上所有的路由器都打开ip source routing
再比如指定源接口,这个最有用,因为有时候对端有访问列表的限制,只能某个地址可以发起Ping,比如Loopback地址等
Router#ping
Protocol [ip]:
Target IP address: 10.123.123.7

Extended commands [n]: y
Source address or interface: loopback0 (or an actual local IP address)

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.123.123.7, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
是不是对老是输入这些选项有点厌烦了,来点捷径吧:
Router#ping 10.123.123.7 ?
data      specify data pattern
df-bit    enable do not fragment bit in IP header
repeat    specify repeat count
size      specify datagram size
source    specify source address or name
timeout   specify timeout interval
validate validate reply data
<cr>
看到上面很多选项了吧,下面一个命令就实现了源地址为以太口0/0,以480字节大小的数据包ping1000次,每次超时时间为3
router# ping 10.123.123.7 repeat 1000 size 480 source ethernet 0/0 timeout 3
最后来一个使用Ping来计算网络MTU的问题,可不要问我什么是MTU
router#ping
Target IP address: 10.123.123.7
Output Omitted…
Extended commands [n]: y
Set DF bit in IP header? [no]: y
Output Omitted…
Sweep range of sizes [n]: y
Sweep min size [36]: 64
Sweep max size [18024]: 1550
Sweep interval [1]: 10
Type escape sequence to abort.
Sending 745, [64..1550]-byte ICMP Echos to 10.123.123.7, timeout is 2 seconds:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!….     
Success rate is 96 percent (96/100), round-trip min/avg/max = 1/3/4 ms
最后MTU的计算公式为MTU=(success*interval)+min sweep value=(96*10)+64=1024

2.Telnet命令
最基本的登录命令:
router#telnet 10.123.123.254 或者
router#10.123.123.254
也可以使用多种选项:
router#telnet 10.123.123.254 ?
/debug               Enable telnet debugging mode
/ipv4                  Force use of IP version 4
/ipv6                  Force use of IP version 6
/line                   Enable telnet line mode
/noecho             Disable local echo
/quiet                 Suppress login/logout messages
/route:                Enable telnet source route mode
/source-interface     Specify source interface
/stream               Enable stream processing
/terminal-type        Set terminal type
<0-65535>              Port number
来一个组合Telnet
router#telnet 10.123.123.254 /source-interface ethernet 0/0 80

3.Debug命令
Debug信息由于是IOS产生的,所以相应的CPU占用就比较大,因此在使用上要倍加小心,输命令之前你要请求你到底在做什么。这条service timestamps debug datetime localtimedebug输出增加时间戳的命令一定要首先配上,一般不要在console或者aux口连接时使用debug命令,建议在telnet时使用,不过要增加下面命令:
router(config)#logging console 6
router#term mon   
最后一点,尽可能的使用过滤,下面介绍两个例子:
第一 使用ACL进行过滤
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#access-list 10 permit 10.123.123.7
router(config)#^Z
router#debug ip packet detail ?
<1-199>      Access list
<1300-2699> Access list (expanded range)
<cr>
router#debug ip packet detail 10
IP packet debugging is on (detailed) for access list 10
router#ping 10.123.123.7
03:16:57: IP: s=10.123.123.7 (Ethernet0/0), d=10.123.123.254 (Ethernet0/0), len 100, rcvd 3
03:16:57:     ICMP type=0, code=0
第二 接口过滤
router#debug list ?
<0-2699>            access list
Dialer              Dialer interface
Ethernet            IEEE 802.3
Multilink           Multilink-group interface

<cr>
router#debug list ethernet 0/0
router#debug ip packet detail
IP packet debugging is on
        for interface: Ethernet0/0
(detailed)

03:19:32: IP: s=10.123.123.7 (Ethernet0/0), d=10.123.123.254 (Ethernet0/0), len 100, rcvd 3
03:19:32:     ICMP type=0, code=0
最后合二为一
router#debug list ethernet 0/0 ?
<0-2699> access list
<cr>
router#debug list ethernet 0/0 10
router#debug ip packet detail
IP packet debugging is on
        for interface: Ethernet0/0   and access list: 10
(detailed)

03:21:38: IP: s=10.123.123.7 (Ethernet0/0), d=10.123.123.254 (Ethernet0/0), len 100, rcvd 3
03:21:38:     ICMP type=0, code=0

 

4.NBAR命令
NBARNetwork Based Application Recognition的缩写就是基于网络的应用识别,虽然从12.1.5T)就是开始支持了,但是使用的很少,在250026003600等设备上NBAR的功能比较有限,而对于新的180028003800等路由器则是NBAR的全面支持,利用这个特性可以了解网络现状,检测网络应用和进行网络保护等。
使用NBAR的前提是必须启用CEF,配置示例如下:
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#ip cef
router(config)#int e 0/0
router(config-if)#ip nbar protocol-discovery
router(config-if)#^Z
router#sh ip nbar protocol-discovery
用下面示例来查看当前网络现状
outer#sh ip nbar protocol-discovery
Ethernet0/0         Input                        Output
   Protocol            Packet Count           Packet Count
                            Byte Count               Byte Count
                            5 minute bit rate (bps) 5 minute bit rate (bps)
   ------------------------ ------------------------ ------------------------
   http                   2892                         3487
                            427198                     2930628
                            0                               0
   secure-http       2462                         2064
                            854207                     706349
                            0                               0
检测特定的应用
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#class-map nbar-detect
router(config-cmap)#match prot gnutella file-transfer “*”
router(config)#policy-map gnutella-detect
router(config-pmap)#class nbar-detect
router(config)#int e 2/0
router(config-if)#service-policy input gnutella-detect
router(config-if)#service-policy output gnutella-detect
router(config-if)#^Z
router#sh policy-map interface ethernet 2/0
限制特定的应用
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#class-map nbar-detect
router(config-cmap)#match prot gnutella file-transfer “*”
router(config)#policy-map gnutella-detect
router(config-pmap)#class nbar-detect
router(config-pmap)#set ip dscp 1
router(config)#access-list 101 deny ip any any dscp 1 log
router(config)#access-list 101 permit ip any any
router(config-if)#ip access-group 101 in
router(config-if)#ip access-group 101 out
router(config-if)#^Z
router#sh access-list 101

5.Test命令
IOS内置了很多测试命令,帮助下看看
router#test ?
aaa                   AAA Authentication, Authorization and Accounting
interfaces            Network interfaces
memory               Non-volatile and/or multibus memory
pas                   Port Adaptor Tests
sgbp
cac                  test the l2 cac functionality
call                  Call test commands
crypto               Test crypto functions

各取所需

6.SAARTR Responders
这个特性在10.3就有了,当时是为了SNA网络,后来增加了对TCP/UDP/IP测试的支持,最近又增加了对Voice的抖动,延迟等的支持,改成一个新名字叫IP SLA Monitors了。
先看个帮助
router(config)#ip sla monitor ?
<1-2147483647>          Entry Number
key-chain                       Use MD5 authentication for RTR control message
low-memory                      Configure low water memory mark
reaction-configuration     RTR Reaction Configuration
reaction-trigger                RTR Trigger Assignment
reset                         RTR Reset
responder                       Enable RTR Responder
restart                         Restart an Active Entry
schedule                       RTR Entry Scheduling
继续帮助,看看都支持那些类型的监控
router(config)#ip sla monitor 1
router(config-rtr)#type ?
dhcp         Perform DHCP Operation
dlsw         Perform DLSw Keepalive Operation
dns          Perform DNS Query
echo         Perform Point to Point Echo Operations
frame-relay Perform frame relay operation
ftp          Perform ftp operation
http         Perform HTTP Operations
jitter       Perform Jitter Operation
pathEcho     Perform Path Discovered Echo Operations
pathJitter   Perform Path Jitter Operation using ICMP
tcpConnect   Perform TCP Connect Operations
udpEcho      Perform UDP Echo Operations
使用ICMP来对××× SAA
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#ip sla monitor 1
router(config)#type pathEcho protocol ipIcmpEcho REMOTE source-ipaddr LOCAL
router(config-rtr)#frequency 60
router(config)#ip sla monitor schedule 1 ?
ageout      How long to keep this Entry when inactive
life        Length of time to execute in seconds
start-time When to start this entry
<cr>
router(config)#ip sla monitor schedule 1 life forever start-time now
router#sh ip sla monitor operational-state
Entry number: 1
Modification time: 16:48:53.060 mst Thu May 7 2007
Number of Octets Used by this Entry: 53808
Number of operations attempted: 434
Number of operations skipped: 0
Current seconds left in Life: Forever
Operational state of entry: Active
Last time this entry was reset: Never
Connection loss occurred: FALSE
Timeout occurred: FALSE
Over thresholds occurred: FALSE
Latest RTT (milliseconds): 2
Latest operation start time: 16:48:53.072 mst Thu May 7 2007
Latest operation return code: OK

7.配置小技巧
show命令输出的有效过滤我就不提了,以前写过文档。另外记得有个do的命令,可以在任何模式下输入全局配置模式下的命令,这样就不用来回的exit来切换不同的模式了,不过使用do的话就不支持上下文类型的帮助了。另外在我翻译的IOS Cookbook中提到了对于配置的存档和回滚,这样帮助你备份配置文件,在出现问题的情况下快速倒回。最后一个default命令也很有用,可以快速的帮助你把清除配置,比如default interface ethernet 2/0命令就可以帮助你清除掉以太口2/0下的所有配置。

8.IOS出问题的解决
路由器也有POST自检信息,不过缺省情况下这些都不显示的,这些自检信息可以帮助你了解启动不了时的具体硬件问题,开启POST消息需要修改寄存器值为0xA102.
IOS出问题时有时会产生traceback通过show stacks命令的输出,然后通过思科网站的命令输出解释器找出具体原因
[url]https://www.cisco.com/cgi-bin/Support/OutputInterpreter/home.pl[/url]
如果你配置了类似exception dump 10.123.123.7 这样的命令,在IOS崩溃的情况下可以产生core dump文件在TFTP服务器上。
最后说一个parser config cache interface命令,对于很大的配置文件可以通过缓存的方法来加快show run类似命令的输出
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章