0×1.實(shí)例拓?fù)鋱D與配置
C1是使用VPCS虛擬出來(lái)的一臺(tái)計(jì)算機(jī)锉桑,SW1是一臺(tái)不可網(wǎng)管交換機(jī)(并非IOU中的交換機(jī),GNS3中自帶的"Ethernet switch"窍株,拖拽到工作區(qū)后會(huì)提示選擇Server民轴,選擇"Local Server"即可),R1球订、R2后裸、R3上都添加了"NM-4T"串口,R1上還添加了一個(gè)"NM-1FE-TX"快速以太網(wǎng)端口冒滩。R3上面配置了一個(gè)回環(huán)接口3.3.3.3/24微驶,各設(shè)備IP配置和連接如下圖:
![Cisco-CCNA-Network-Analyst-1](https://www.qingsword.com/qing/images/Cisco-CCNA-Network-Analyst-1.jpg)
VPCS配置如下:
1
/配置vpcs的
ip
子網(wǎng)掩碼與網(wǎng)關(guān)/
2
VPCS> set pcname C1
3
C1>
ip
192.168.1.2 255.255.255.0 192.168.1.1
4
C1 : 192.168.1.2 255.255.255.0 gateway 192.168.1.1
R1配置如下:
01
Router>
en
02
Router#
conf
t
03
Router(config)#
host
R1
04
R1(config)#line co 0
05
R1(config-line)#
logg
syn
06
R1(config-line)#
exec-t
0 0
07
R1(config-line)#
exit
08
R1(config)#
int
fa 1/0
09
R1(config-if)#
ip
add
192.168.1.1 255.255.255.0
10
R1(config-if)#
no
shut
11
R1(config-if)#
int
s 0/0
12
R1(config-if)#
ip
add
12.1.1.1 255.255.255.0
13
R1(config-if)#
no
shut
14
R1(config-if)#
end
15
R1#
R2配置如下:
01
Router>
en
02
Router#
conf
t
03
Router(config)#line co 0
04
Router(config-line)#
logg
syn
05
Router(config-line)#
exec-t
0 0
06
Router(config-line)#
exit
07
Router(config)#
host
R2
08
R2(config)#
int
s 0/1
09
R2(config-if)#
ip
add
12.1.1.2 255.255.255.0
10
R2(config-if)#
no
shut
11
R2(config-if)#
int
s 0/2
12
R2(config-if)#
ip
add
23.1.1.2 255.255.255.0
13
R2(config-if)#
no
shut
14
R2(config-if)#
end
15
R2#
R3配置如下:
01
Router>
en
02
Router#
conf
t
03
Router(config)#
host
R3
04
R3(config)#line co 0
05
R3(config-line)#
logg
syn
06
R3(config-line)#
exec-t
0 0
07
R3(config-line)#
int
s 0/3
08
R3(config-if)#
ip
add
23.1.1.3 255.255.255.0
09
R3(config-if)#
no
shut
10
R3(config-if)#
exit
11
R3(config)#
int
loopback
0 /配置回環(huán)接口0/
12
R3(config-if)#
ip
add
3.3.3.3 255.255.255.0
13
R3(config-if)#
no
shut
14
R3(config-if)#
end
15
R3#
0×2.測(cè)試連通性
首先在C1上面測(cè)試ping自己的網(wǎng)關(guān)(R1的fa1/0接口)
01
/可以
ping
通/
02
C1>
ping
192.168.1.1
03
192.168.1.1 icmp_seq=1 ttl=255 time=49.000 ms
04
05
/繼續(xù)在C1上測(cè)試
ping
不同網(wǎng)段的地址/
06
07
/*
ping
網(wǎng)關(guān)R1上的串口,成功*/
08
C1>
ping
12.1.1.1
09
12.1.1.1 icmp_seq=1 ttl=255 time=29.000 ms
10
11
/*
ping
R2和R1相連的接口开睡,超時(shí)*/
12
C1>
ping
12.1.1.2
13
12.1.1.2 icmp_seq=1 timeout
這一步為什么會(huì)超時(shí)呢因苹?是不是數(shù)據(jù)包沒有到達(dá)R2?我們?cè)赗2上開啟debug命令進(jìn)行調(diào)試:
01
R2#debug
ip
icmp
02
ICMP packet debugging is on
03
04
/開啟調(diào)試后篇恒,再一次用C1去
ping
12.1.1.2,發(fā)現(xiàn)R2上出現(xiàn)了下面的提示/
05
R2#
06
*Mar 1 00:17:10.135: ICMP: echo reply sent, src 12.1.1.2, dst 192.168.1.2
07
08
/關(guān)閉所有調(diào)試的方法是undebug all/
09
10
/從上面的顯示可以看出R2收到了C1發(fā)送過(guò)來(lái)的ICMP包扶檐,我們查看一下R2的路由表/
11
R2#
show
ip
route
12
/主要看下面這一部分/
13
Gateway of last resort is not set
14
15
23.0.0.0/24 is subnetted, 1 subnets
16
C 23.1.1.0 is directly connected, Serial0/2
17
12.0.0.0/24 is subnetted, 1 subnets
18
C 12.1.1.0 is directly connected, Serial0/1
19
20
/*
21
- 從輸出可以明顯的看到R2的路由表中有兩個(gè)直連條目(C)
22
- 發(fā)往23.1.1.0/24網(wǎng)段的數(shù)據(jù)從Serial0/2發(fā)出
23
- 發(fā)往12.1.1.0/24網(wǎng)段的數(shù)據(jù)從Serial0/1發(fā)出
24
- 并沒有發(fā)往192.168.1.0/24網(wǎng)段的路由條目
25
*/
R2不知道發(fā)往192.168.1.0/24網(wǎng)段的數(shù)據(jù)應(yīng)該從哪個(gè)接口發(fā)出,所以R2丟棄192.168.1.2發(fā)送過(guò)來(lái)的數(shù)據(jù)胁艰。
下面給R2添加靜態(tài)路由款筑,讓他知道發(fā)往192.168.1.0/24網(wǎng)段的數(shù)據(jù)應(yīng)該發(fā)給12.1.1.1(R1),之后C1再ping 12.1.1.2腾么,就能ping通了奈梳,關(guān)于靜態(tài)路由的知識(shí)會(huì)在后面的文章中詳細(xì)介紹,這里有這個(gè)概念就可以了:
1
/添加靜態(tài)路由解虱,去往192.168.1.0/24網(wǎng)段的數(shù)據(jù)發(fā)給12.1.1.1/
2
R2(config)#
ip
route
192.168.1.0 255.255.255.0 12.1.1.1
這個(gè)時(shí)候C1 ping R3的任何地址都是ping不通的攘须,因?yàn)閿?shù)據(jù)包到達(dá)R1后,R1檢查自己的路由表饭寺,它會(huì)發(fā)現(xiàn)沒有任何去往R3的路由條目(3.3.3.0/24阻课、23.1.1.0/24)叫挟,所以它會(huì)直接給C1回復(fù)"Destination host unreachable 主機(jī)不可達(dá)":
01
C1>
ping
3.3.3.3
02
*192.168.1.1 icmp_seq=1 ttl=255 time=20.000 ms (ICMP type:3, code:1, Destination
host
unreachable)
03
04
C1>
ping
23.1.1.2
05
*192.168.1.1 icmp_seq=1 ttl=255 time=20.000 ms (ICMP type:3, code:1, Destination
host
unreachable)
06
07
C1>
ping
23.1.1.3
08
*192.168.1.1 icmp_seq=1 ttl=255 time=26.000 ms (ICMP type:3, code:1, Destination
host
unreachable)
09
10
/*在R1上開啟ICMP調(diào)試,就會(huì)看到下面的輸出限煞,R1對(duì)C1的每一個(gè)ICMP報(bào)文都回復(fù)
"目標(biāo)主機(jī)不可達(dá)"
*/
11
R1#debug
ip
icmp
12
*Mar 1 00:34:55.587: ICMP: dst (23.1.1.3)
host
unreachable sent to 192.168.1.2
要想讓這個(gè)拓?fù)鋱D中的每臺(tái)設(shè)備都能互相ping通抹恳,需要在R1、R2署驻、R3上面添加下面的靜態(tài)路由條目:
1
/R1添加一條默認(rèn)路由目的地是12.1.1.2(R2)/
2
R1(config)#
ip
route
0.0.0.0 0.0.0.0 12.1.1.2
3
4
/R2添加下面兩條靜態(tài)路由奋献,分別指向R1的以太網(wǎng)網(wǎng)段以及R3的環(huán)回接口網(wǎng)段,告訴路由器去往192.168.1.0/24網(wǎng)段的數(shù)據(jù)應(yīng)該發(fā)給12.1.1.1旺上,去往3.3.3.0/24的數(shù)據(jù)應(yīng)該發(fā)給23.1.1.3/
5
R2(config)#
ip
route
192.168.1.0 255.255.255.0 12.1.1.1
6
R2(config)#
ip
route
3.3.3.0 255.255.255.0 23.1.1.3
7
8
/R3也添加一條默認(rèn)路由瓶蚂,目的地是23.1.1.2(R2)/
9
R3(config)#
ip
route
0.0.0.0 0.0.0.0 23.1.1.2
這個(gè)時(shí)候,不論在哪個(gè)設(shè)備上宣吱,都能ping通拓?fù)渖系乃薪涌贗P窃这;下面是R1上面ping R3回環(huán)接口的返回信息:
1
R1#
ping
3.3.3.3
2
3
Type escape sequence to abort.
4
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
5
!!!!!
6
/*
7
- 這里顯示五個(gè)感嘆號(hào),說(shuō)明上面默認(rèn)
ping
發(fā)送5次征候,
ping
成功5次
8
- 如果超時(shí)會(huì)顯示省略號(hào)
"....."
9
*/
關(guān)閉R3的回環(huán)接口杭攻,就會(huì)出現(xiàn)超時(shí)的情況:
01
R3#
conf
t
02
R3(config)#
int
lo
0
03
R3(config-if)#
shut
/關(guān)閉回環(huán)接口/
04
05
06
/使用R1去
ping
,顯示超時(shí)疤坝,實(shí)際上這里產(chǎn)生了路由環(huán)路/
07
R1#
ping
3.3.3.3
08
09
Type escape sequence to abort.
10
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
11
.
12
*Mar 1 00:45:09.355: ICMP: time exceeded rcvd from 23.1.1.2.
13
14
/對(duì)每一個(gè)
ping
兆解,R2都會(huì)返回一條信息,意思是TTL=0了跑揉,數(shù)據(jù)包被丟棄锅睛,實(shí)際上是因?yàn)檫@種靜態(tài)路由配置出現(xiàn)了路由環(huán)路,如果回環(huán)口沒有關(guān)閉历谍,R3將應(yīng)答這個(gè)ICMP现拒,但是此時(shí)R3上回環(huán)關(guān)閉了,R3根據(jù)自己的默認(rèn)路由又將數(shù)據(jù)發(fā)回R2望侈,R2再次將數(shù)據(jù)發(fā)回R3具练;而這條信息為什么會(huì)在R2上呢?這是因?yàn)樘鹞蓿總€(gè)ICMP報(bào)文中都有一個(gè)TTL字段扛点,這個(gè)字段的初始值是32,64,128,256中的一個(gè),而每經(jīng)過(guò)一臺(tái)路由岂丘,這個(gè)值自動(dòng)減一陵究,直到變成0,ICMP包從R1發(fā)往R2的時(shí)候奥帘,初始TTL是一個(gè)偶數(shù)铜邮,通過(guò)R2之后變成了奇數(shù),通過(guò)R3發(fā)回R2的時(shí)候又變成了偶數(shù),然后這個(gè)數(shù)據(jù)包在R2和R3之間不停來(lái)回發(fā)送(因?yàn)殪o態(tài)路由表的原因)松蒜,直到TLL=0扔茅,而根據(jù)這個(gè)數(shù)學(xué)模型分析,偶數(shù)的時(shí)候這個(gè)數(shù)據(jù)包是在R2上的秸苗,所以R2丟棄這個(gè)數(shù)據(jù)包召娜,并且返回一條信息/
15
*Mar 1 00:45:07.991: ICMP: time exceeded (time to live) sent to 12.1.1.1 (dest was 3.3.3.3)
下面我們打開R3的lo0回環(huán)接口,關(guān)閉R2的s0/2,再次用R1去ping 3.3.3.3:
01
R3(config)#
int
lo
0
02
R3(config-if)#
no
shut
03
04
/關(guān)閉R2與R3相連的s0/2接口/
05
R2(config-if)#
int
s 0/2
06
R2(config-if)#
shut
07
08
/*R1開始
ping
*/
09
R1#
ping
3.3.3.3
10
11
Type escape sequence to abort.
12
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
13
14
U /(U)代表目的主機(jī)不可達(dá)/
15
16
*Mar 1 00:53:32.091: ICMP: dst (12.1.1.1)
host
unreachable rcv from 12.1.1.2
17
18
/R2上的顯示如下/
19
R2#
20
*Mar 1 00:53:34.823: ICMP: dst (3.3.3.3)
host
unreachable sent to 12.1.1.1
21
22
/*
23
- 查看R2路由表惊楼,發(fā)現(xiàn)直連接口條目23.1.1.0/24消失了
24
- 同樣玖瘸,目的地址是這個(gè)直連接口網(wǎng)段的靜態(tài)路由條目也消失了
25
- 所以R2返回一個(gè)消息告訴R1
"(3.3.3.3) host unreachable"
26
*/
27
R2#
show
ip
route
28
29
Gateway of last resort is not set
30
12.0.0.0/24 is subnetted, 1 subnets
31
C 12.1.1.0 is directly connected, Serial0/1
32
S 192.168.1.0/24 [1/0] via 12.1.1.1
打開R2的s0/2繼續(xù)下面的實(shí)驗(yàn)。
0×3.高級(jí)ping命令和路由追蹤命令traceroute
使用高級(jí)ping命令檀咙,從R1 ping R3的回環(huán)接口:
01
R1#
ping
/直接輸入
ping
雅倒,回車/
02
Protocol [
ip
]: /選擇協(xié)議,默認(rèn)IP協(xié)議回車即可/
03
Target IP
address
: 3.3.3.3 /選擇目標(biāo)IP弧可,這里是R3的lo0接口IP/
04
Repeat count [5]: 10 /*
ping
次數(shù)蔑匣,本例輸入10次,默認(rèn)5次*/
05
Datagram size [100]: /數(shù)據(jù)包大小棕诵,默認(rèn)回車即可/
06
Timeout in seconds [2]: /超時(shí)時(shí)間殖演,直接回車/
07
Extended commands [n]: y /是否顯示擴(kuò)展命令,輸入y/
08
Source
address
or
interface
: 192.168.1.1
09
/選擇用本地的哪個(gè)接口去
ping
年鸳,這里選擇R1的以太網(wǎng)接口/
10
Type of service [0]: /下面暫時(shí)不用理會(huì),一路回車/
11
Set DF bit in IP header? [
no
]:
12
Validate reply data? [
no
]:
13
Data pattern [0xABCD]:
14
Loose, Strict, Record, Timestamp, Verbose[none]:
15
Sweep range of sizes [n]:
16
Type escape sequence to abort.
17
Sending 10, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
18
Packet sent with a
source
address
of 192.168.1.1
19
!!!!!!!!!! /可以看到
ping
通了十次/
20
Success
rate
is 100 percent (10/10), round-trip min/avg/
max
= 16/40/64 ms
21
22
/高級(jí)
ping
命令能同樣能實(shí)現(xiàn)路由跟蹤/
23
R1#
ping
24
Protocol [
ip
]:
25
Target IP
address
: 3.3.3.3
26
Repeat count [5]: 1 /Ping一次/
27
Datagram size [100]:
28
Timeout in seconds [2]:
29
Extended commands [n]: y /使用擴(kuò)展/
30
Source
address
or
interface
: 192.168.1.1 /選擇源端口/
31
Type of service [0]:
32
Set DF bit in IP header? [
no
]:
33
Validate reply data? [
no
]:
34
Data pattern [0xABCD]:
35
Loose, Strict, Record, Timestamp, Verbose[none]: r /這里輸入r/
36
Number of hops [ 9 ]:
37
Loose, Strict, Record, Timestamp, Verbose[RV]:
38
Sweep range of sizes [n]:
39
40
/記錄ICMP包從發(fā)出到返回所經(jīng)過(guò)的端口(外出方向)/
41
Reply to request 0 (96 ms). Received packet has options
42
Total option bytes= 40, padded length=40
43
Record
route
:
44
(12.1.1.1) /首先從R1的這個(gè)接口發(fā)出/
45
(23.1.1.2) /到達(dá)R2丸相,R2從這個(gè)接口發(fā)出/
46
(3.3.3.3) /到達(dá)目的地/
47
(23.1.1.3) /ICMP包開始返回搔确,R3從這個(gè)接口發(fā)回給R2/
48
(12.1.1.2) /到達(dá)R2,R2從這個(gè)接口發(fā)給R1/
49
(192.168.1.1) <> /回到起點(diǎn)*/
50
(0.0.0.0)
51
(0.0.0.0)
52
(0.0.0.0)
53
End of list
ping命令可以測(cè)試網(wǎng)絡(luò)通不通灭忠,但是如果中間網(wǎng)絡(luò)不通膳算,ping不能很好的定位問(wèn)題出在哪里,而traceroute可以很好的定位問(wèn)題出現(xiàn)的位置弛作,下面是正常狀態(tài)下在R1上traceroute 3.3.3.3的結(jié)果:
01
R1#traceroute 3.3.3.3
02
03
Type escape sequence to abort.
04
Tracing the
route
to 3.3.3.3
05
06
1 12.1.1.2 40 msec 24 msec 40 msec
07
2 23.1.1.3 28 msec 48 msec *
08
09
/*
10
- 可以看到數(shù)據(jù)首先經(jīng)過(guò)了12.1.1.2涕蜂,然后到達(dá)23.1.1.3
11
- 3.3.3.3和23.1.1.3同處于R3上,所以追蹤到此完成
12
- 與
ping
追蹤不同的是映琳,traceroute記錄的是路由的接收端口机隙,而
ping
記錄的是路由的發(fā)出端口
13
*/
Traceroute的工作原理:
首先,發(fā)送設(shè)備將數(shù)據(jù)包中的TTL設(shè)置成1萨西,數(shù)據(jù)包會(huì)被第一臺(tái)接收路由器丟棄有鹿,返回一個(gè)錯(cuò)誤碼信息,發(fā)送設(shè)備根據(jù)錯(cuò)誤碼信息判斷經(jīng)過(guò)的中間設(shè)備和延時(shí)谎脯,發(fā)送設(shè)備一般發(fā)送三個(gè)重復(fù)的包(這就是為什么每個(gè)IP后面有3個(gè)返回時(shí)間的原因"12.1.1.2 40 msec 24 msec 40 msec")葱跋;之后發(fā)送設(shè)備發(fā)送TTL為2的數(shù)據(jù)包,再發(fā)送TTL為3的數(shù)據(jù)包,直到數(shù)據(jù)包達(dá)到目的地或者TTL=30為止娱俺;在正常情況下稍味,除非路由存在環(huán)路,否則TTL不會(huì)超過(guò)30就到達(dá)目的地荠卷;數(shù)據(jù)到達(dá)目的地后模庐,目的設(shè)備會(huì)返回一個(gè)"端口不可達(dá)",發(fā)送設(shè)備就是利用返回的是錯(cuò)誤碼僵朗,還是端口不可達(dá)判斷是否到達(dá)了目的主機(jī)赖欣。
0×4.常用排錯(cuò)命令
01
/針對(duì)某接口,以太網(wǎng)接口可以看到MAC地址验庙,帶寬顶吮,IP地址等/
02
R1#
show
interfaces
fa 1/0
03
FastEthernet1/0 is up, line protocol is up
04
Hardware is AmdFE,
address
is cc00.143c.0010 (bia cc00.143c.0010)
05
Internet
address
is 192.168.1.1/24
06
07
08
/查看接口是否開啟/
09
R1#
show
ip
interface
brief
10
Interface IP-Address OK? Method Status Protocol
11
Serial0/0 12.1.1.1 YES manual up up
12
Serial0/1 unassigned YES unset administratively down down
13
Serial0/2 unassigned YES unset administratively down down
14
Serial0/3 unassigned YES unset administratively down down
15
FastEthernet1/0 192.168.1.1 YES manual up up
16
17
/查看路由器IOS版本,硬件信息等/
18
R1#
show
version
19
/最后一行會(huì)顯示配置寄存器的值/
20
Configuration register is 0x2102
21
22
/查看路由器接口硬件信息/
23
R1#
show
controllers fa 1/0
24
25
/*
26
- 查看路由器接口硬件信息粪薛,
27
- 如果是串行接口可以看到如下一行悴了,可以判斷接口是DCE端還是DTE端還有時(shí)鐘
28
- cable type : V.11 (X.21) DCE cable, received clockrate 2015232
29
*/
30
R1#
show
controllers s 1/0
31
32
/查看路由器ARP緩存/
33
R1#
show
arp
34
Protocol Address Age (min) Hardware Addr Type Interface
35
Internet 192.168.1.1 - cc00.143c.0010 ARPA FastEthernet1/0
36
Internet 192.168.1.2 42 0050.7966.6800 ARPA FastEthernet1/0