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

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 localtime给debug输出增加时间戳的命令一定要首先配上,一般不要在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命令
NBAR是Network Based Application Recognition的缩写就是基于网络的应用识别,虽然从12.1.5(T)就是开始支持了,但是使用的很少,在2500,2600,3600等设备上NBAR的功能比较有限,而对于新的1800,2800,3800等路由器则是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.SAA和RTR 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类似命令的输出

转载于:https://blog.51cto.com/szhjh/98419

教你使用IOS内置的排错命令相关推荐

  1. 苹果屏幕录制5831_苹果怎么录屏幕视频?教你轻松开启内置录屏功能

    苹果怎么录屏幕视频?随着iPhone功能的不断更新换代,iOS系统也早已提供了内置的录屏功能,不过很多小伙伴不清楚怎么使用苹果手机的录屏功能,你还在使用第三方的录屏软件吗?苹果手机升级到iOS 11以 ...

  2. 苹果怎么录屏幕视频?教你轻松开启内置录屏功能

    苹果怎么录屏幕视频?随着iPhone功能的不断更新换代,iOS系统也早已提供了内置的录屏功能,不过很多小伙伴不清楚怎么使用苹果手机的录屏功能,你还在使用第三方的录屏软件吗?苹果手机升级到iOS 11以 ...

  3. IOS内置safari浏览器日期字符串转Date对象失败

    代码示例: <html> <head> <title>Date字符串转化示例</title> </head> <body> &l ...

  4. php内置类,yii2学习教程之5种内置行为类详解

    前言 众所周知学习所有知识都需要循序渐进,行为也是一样,在我们学会很牛逼的新建行为,然后轻松注入到组件类之前,先看看yii2框架为我们准备的5个内置的行为类,也许你刚要用到~话不多说了,来一起看看详细 ...

  5. 纯净ROM如何制作?手把手教你一键精简内置推广

    是不是经历过被下载的内置推广软件困扰,那么在这种情况下是否有想制作一款纯净ROM的冲动.那么如果你是一个小白用户想要制作一款专属自己的纯净ROM时你需要什么样的操作呢? 纯净ROM和普通ROM有什么样 ...

  6. HBuilderX 使用内置终端打开命令框 操作文件

    安装内置终端插件 安装 内置终端插件 随意点击一个文件右击 点击以后如果你没有安装提示你安装 也可以点击工具 插件 进行安装 选择 node npm 运行环境 选择内置终端 npm 路径查询 npm ...

  7. vim内置的搜索命令vimgrep使用

    vim内置搜索命令vimgrep, 可以在多个文件里查找关键字.相当于IDE里的关键字搜索功能. vimgrep命令: :vim[grep] /pattern/[g][j] files ... g和j ...

  8. 苹果IOS内置应用介绍

    文章来自百度百科:http://baike.baidu.com/link?url=4OUX5cErT66qGsbRgSt6eewzcTsdndubuuSdHYMDwU3JB4Hv9c2sYlH-Y1e ...

  9. IOS 内置浏览器,跳转前的http请求失效的问题

    最近的一个程序,有个是个跳转页面,跳转之前会执行一段http请求,告诉后台请求的信息.但是发现在iphone 6中,一开始可以收到发过来的消息,之后发觉每次访问这个页面都是直接跳转,而之前的那个htt ...

最新文章

  1. 【面试】我是如何面试别人List相关知识的,深度有点长文
  2. Effective_STL 学习笔记(四十三) 尽量用算法调用代替手写循环
  3. vscode 写vue 没有js提示_如何用VSCode实现一个vue.js项目?
  4. hint oracle qbname_从才oracle中找到所有列名为BANK_ACC,且BANK_ACC=000的项,并将BANK_ACC=000000的项修改为BANK_ACC=111...
  5. DevOps 火爆,要学这么多技术!
  6. Solaris11修改主机名
  7. Java弹球游戏,刚学Java时做的
  8. 也致第一次安装Rime的你
  9. .Net框架搭建之辅助模版代码生成工具
  10. 三维激光扫描后处理软件_边走边扫的三维激光扫描仪-
  11. 算术分解定理取根号的注意点
  12. java客户端发消息到kafka
  13. TCP协议调试工具TcpEngine V1.3.0使用教程
  14. UIQ的CEikEdwin文本框怎么设置自动滚动(转)
  15. 进制与IP地址的转换
  16. 如何通过python判断闰年?
  17. linux系统网络备份,备份Linux操作系统的几种方法
  18. 【web系列十五】Ubuntu系统部署Web项目
  19. 一次nginx代理前端报rewrite or internal redirection cycle while internally redirecting to “index.html“ 记录
  20. 计算机组成原理课后习题

热门文章

  1. NLayerAppV3-Distributed Service Layer(分布式服务层)
  2. js 日历插件开发
  3. [leetcode] 367. Valid Perfect Square
  4. Centos6下安装中文字体
  5. 关于前端使用JavaScript无法实现canvas打印问题的解决
  6. Myeclipse开发环境下文件中出现的提示错误与解决方法:The import javax.servlet cannot be resolved?
  7. 解决iOS微信H5支付跳转微信后不返回App问题(Swift-WKWebview)(转)
  8. C# 出现System.TypeInitializationException类型初始值设定项引发异常
  9. 执行在一行中组合多个Linux命令
  10. 如何自定义制表符到空格的转换因子?