在路由器的故障分析中,Ping命令是一個(gè)常見而實(shí)用的網(wǎng)絡(luò)管理工具,用這種工具可以測(cè)試端到端的連通性,即檢查源端到目的端網(wǎng)絡(luò)是否通暢。Ping的原理很簡(jiǎn)單,就是從源端向目的端發(fā)出一定數(shù)量的網(wǎng)絡(luò)包,然后從目的端返回這些包的響應(yīng),如果在一定的時(shí)間內(nèi)源端收到響應(yīng),則程序返回從包發(fā)出到收到的時(shí)間間隔,根據(jù)時(shí)間間隔就可以統(tǒng)計(jì)網(wǎng)絡(luò)的延遲。如果網(wǎng)絡(luò)包的響應(yīng)在一定時(shí)間間隔內(nèi)沒有收到,則程序認(rèn)為包丟失,返回請(qǐng)求超時(shí)的結(jié)果。我們經(jīng)常讓Ping一次發(fā)一定數(shù)量的包,然后檢查收到相應(yīng)的包的數(shù)量,則可統(tǒng)計(jì)出端到端網(wǎng)絡(luò)的丟包率,而丟包率是檢驗(yàn)網(wǎng)絡(luò)質(zhì)量的重要參數(shù)。
在路由器上Ping返回符號(hào)的含義如下表所示:
符號(hào) 描述
! 收到一個(gè)響應(yīng)
. 在等待時(shí),網(wǎng)絡(luò)服務(wù)器超時(shí)
U 目標(biāo)無法到達(dá),收到錯(cuò)誤的PDU
Q 源消失(目標(biāo)設(shè)備太忙)
M 數(shù)據(jù)無法分割
? 包類型未知
& 包的有效期過了
在路由器上無法Ping通一個(gè)地址的原因有很多種,譬如線路故障,對(duì)方路由器的接口沒有起來,路由器的路由表中沒有該地址的路由信息等等都會(huì)造成網(wǎng)絡(luò)無法Ping通。
實(shí)例一:
Routerl#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5,100-byte ICMP Echos to 34.0.0.4,timeout is 2 seconds:
……
Success rate is 0 percent(0/5)
在Routerl上無法Ping通Router4的接口,通過使用DEBUG命令來獲得更多的信息,便于進(jìn)一步的分析:
Routerl#debug ip packet
IP packet debugging is on
Routerl#Ping 34.0.O.4
Type escape sequence to abort.
Sending 5,100-byte ICMP Echos to 34.0.0.4。timeout is 2 seconds:
nbsp; 5d21h:IP:s=12.0.0.1(local),d=34.0.0.4,Len 100,unroutable.
5d21h:IP:s=12.0.0.1(local),d=34.0.0.4,Len 100,unroutable.
Success rate is 0 percent(0/5)
我們看到“unroutable”的消息,表明在Router1的路由表中不存在該地址的路由信息,Router1不知道該地址向何處轉(zhuǎn)發(fā),現(xiàn)增加一條默認(rèn)路由到Router1中:
Router1# configure terminal
Enter configuration commands,one per line. End with CNTL/Z.
Router1(config)#ip route 0.0.0.0 0.0.0.0 Serial0/0
然后,在Router1上使用Ping:
Router1# Ping 34.0.0.4
Type escape sequence to abort.
Sending 5,100-byte ICMP Echos to 34.0.0.4,timeout is 2 seconds:
U.U.U
Success rate is 0 percent(0/5)
6d03h:IP:s=12.0.0.1(local),d=34.0.0.4(Serial0/0),Len 100,sending
6d03h:ICMP type:8,code=0
6d03h:IP:s=12.0.0.2(Serial0/0),d=12.0.0.1(Serial0/0),Len 56,rcvd 3
6d03h:ICMP type=3,code=l
……
再看看在Router2上收到了什么信息:
Router2#
21:56:04:IP:s=12.0.0.1(Serial1),d=34.0.0.4,Len 100.unroutable
21:56:04:ICMP type=8.code=0
21:56:04:IP:s=12.0.O.2(local),d=12.0.0.1(Serial1),Len 56,sending
21:56:04:ICMP type=3.code=l
從上面的信息可以看出Router1已經(jīng)能正確地發(fā)送包到Router2,但好像Router2并不知道如何轉(zhuǎn)發(fā)地址34.0.0.4,所以Router2發(fā)送了“unreachable”的消息給Router1。因此分別給Router2和Router3加上動(dòng)態(tài)路由協(xié)議RIP:
Router2#
router rip
network 12.O.0.0
network 23.O.0.0
Router3#
router rip
network 23.0.0.0
network 34.0.0.0
然后,在Router1上PingRouter4的接口:
Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5.100-byte ICMP Echos to 34.0.0.4,timeout is 2 seconds:
5d21h:IP:s=12.0.0.1(local),d=34.0.0.4(Serial0/0),Len 100,sending.
5d21h:IP:s=12.0.0.1(local),d=34.0.0.4(Serial0/0),Len 100,sending.
……
Success rate is 0 percent(0/5)
現(xiàn)在情況看起來好點(diǎn),Router1能發(fā)包到Router4,只是收不到任何從Router4返回的信息。看來Router4上也有問題:
Router4#
6d23h:IP:s=12.0.0.1(Serial0/0),d=34.0.0.4(Serial0/0),Len 100,rcvd3
6d23h:IP:s=34.0.0.4(local),d=12.0.0.1,Len 100,unroutable
……
Router4收到了ICMP的包,但由于沒有到12.0.0.1的路由信息,因此無法響應(yīng)12.0.0.1所發(fā)過來的包。在Router4上增加一條默認(rèn)路由:
Router4(config)#ip route 0.0.0.0 0.0.0.0 Serial0/0
這樣問題得到了解決:
Router1#Ping 34.0.0.4
Type escape sequence to abort.
Sending 5.100-byte ICMP Echos t0 34.0.0.4,timeout is 2 seconds:
!!!!!
Success rate is 100 percent(5,5),round-trip min/avg/max=32/35/36ms