實驗拓撲
實驗步驟
我們要使得 1.1.1.0/24、2.2.2.0/24、3.3.3.0/24 網絡之間能夠互相通信。
(1) 步驟 1:在各路由器上配置 IP 地址、保證直連鏈路的連通性
R1(config)#int loopback0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R1(config)#int s0/0/0
R1(config-if)#ip address 192.168.12.1 255.255.255.0
R1(config-if)#no shutdown
R2(config)#int loopback0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R2(config)#int s0/0/0
R2(config-if)#clock rate 128000
R2(config-if)#ip address 192.168.12.2 255.255.255.0
R2(config-if)#no shutdown
R2(config)#int s0/0/1
R2(config-if)#clock rate 128000
R2(config-if)#ip address 192.168.23.2 255.255.255.0
R2(config-if)#no shutdown
R3(config)#int loopback0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config)#int s0/0/1
R3(config-if)#ip address 192.168.23.3 255.255.255.0
R3(config-if)#no shutdown
(2) 步驟 2:R1上配置靜態路由
R1(config)#ip route 2.2.2.0 255.255.255.0 s0/0/0
//下一跳為接口形式,s0/0/0 是點對點的鏈路,注意應該是 R1 上的s0/0/0 接口
R1(config)#ip route 3.3.3.0 255.255.255.0 192.168.12.2
//下一跳為IP 地址形式,192.168.12.2 是R2 上的IP 地址
(3) 步驟 3:R2上配置靜態路由
R2(config)#ip route 1.1.1.0 255.255.255.0 s0/0/0
R2(config)#ip route 3.3.3.0 255.255.255.0 s0/0/1
(4) 步驟 4:R3上配置靜態路由
R3(config)#ip route 1.1.1.0 255.255.255.0 s0/0/1
R3(config)#ip route 2.2.2.0 255.255.255.0 s0/0/1
實驗調試
(1) 在 R1、R2、R3 上查看路由表
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Serial0/0/0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
2.0.0.0/24 is subnetted, 1 subnets
S 2.2.2.0 is directly connected, Serial0/0/0
3.0.0.0/24 is subnetted, 1 subnets
S 3.3.3.0 [1/0] via 192.168.12.2
R2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Serial0/0/0
1.0.0.0/24 is subnetted, 1 subnets
S 1.1.1.0 is directly connected, Serial0/0/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 1 subnets
S 3.3.3.0 is directly connected, Serial0/0/1
C 192.168.23.0/24 is directly connected, Serial0/0/1
R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
S 1.1.1.0 is directly connected, Serial0/0/1
2.0.0.0/24 is subnetted, 1 subnets
S 2.2.2.0 is directly connected, Serial0/0/1
3.0.0.0/24 is subnetted, 1 subnets C 3.3.3.0 is directly connected, Loopback0
C 192.168.23.0/24 is directly connected, Serial0/0/1
(2) 從各路由器的環回口 ping 其他路由器的環回口:
R1#ping
//不帶任何參數的 ping命令,允許我們輸入更多的參數
Protocol [ip]:
Target IP address: 2.2.2.2 //目標IP地址
Repeat count [5]: //發送的ping 次數
Datagram size [100]: //ping包的大小
Timeout in seconds [2]: //超時時間
Extended commands [n]: y //是否進一步擴展命令
Source address or interface: 1.1.1.1 //源IP地址
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Sweep range of sizes [n]:
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/14/16 ms//以上說明從 R1 的 loopback0 可以ping 通R2 上的 loopback0。也可以直接使用命令:
R1#ping 2.2.2.2 source loopback 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/14/16 ms
R2#ping 1.1.1.1 source loopback 0
R2#ping 3.3.3.3 source loopback 0
//從R2 的 loopback0 應該可以 ping 通R1 和 R3 的lopback0 接口。
R3#ping 1.1.1.1 source loopback 0
R3#ping 2.2.2.2 source loopback 0
//從R3 的 loopback0 也應該可以 ping 通 R1 和 R2 的 lopback0 接口。
【提示】雖然從 R1 的 loopback0 可以 ping 通 R3 的 loopback0,數據需要經過192.168.23.0/24 網絡,但是在 R1 上我們並沒有添加192.168.23.0/24 的路由。路由器轉發數據包完成是根據路由表的,並且數據是一跳一跳地被轉發的,就像接力賽似的。從 R1的loopback0口ping R3的loopback0口時, IP數據包的源IP為1.1.1.1, 目的IP為3.3.3.3。
R1 路由器首先查路由表,數據包被發到了 R2;R2 路由器也查路由表(3.3.3.0/24 路由) ,數據包被發到了 R3;R3知道這是直連路由。R3響應 R1 的數據包進行類似的過程。
(3) 從 R1 上 ping 2.2.2.2、從 R1 上 ping 3.3.3.3
R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/14/16 ms
//可以ping通。
R1#ping 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
//以上無法ping通, 原因在於使用ping命令時, 如果不指明源接口, 則R1路由器使用s0/0/0接口的 IP 地址(192.168.12.1)作為 IP 數據包的源 IP 地址了。R3 上響應R1 的數據包時,數據包是發向 192.168.12.1 的,然而由於 R3 沒有192.168.12.0/24 的路由,數據包無法發送。即:數據包從 R1 到了 R3 后,無法返回 R1。