2.1 基本静态路由
 
实验连接图
提要描述
在网络传输中,当终端封装完数据,到了路由器上面来说,路由器会去查找 IP 层封装的目的 IP 地址,通过目的 IP 地址进行转发,在这个过程中就要有路由的概念,路由器会去查找目的 IP 转发用到的路由条目。如果没有目的条目就直接仍掉,如果有目的路由就查找到对应的接口,从对应的接口转发出去。
实验目标: 路由全通
基本配置
R1 的配置
R2 的配置
!
hostname R1
interface Serial1/1
ip address 12.1.1.1 255.255.255.0
no sh
clock rate 64000
!
!
hostname R2
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
no sh
!
interface Serial1/1
ip address 23.1.1.2 255.255.255.0
no sh
R3 的配置
 
!
hostname R3
interface Serial1/0
ip address 23.1.1.3 255.255.255.0
no sh
clock rate 64000
!
 
↓调试配置及监测步骤↓
 
 
首先在 R1 上使用 ping 命令检测直连链路是否畅通
R1#ping 12.1.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.2, timeout is 2 seconds:
!!!!!   (ping 通,收到了ICMP 包回复)
Success rate is 100 percent (5/5), round-trip min/avg/max = 40/57/92 ms
 
再次使用 ping 命令检测能否将数据包从 R1 发送到达 R3
R1#ping 23.1.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
.....  ping 不通)
Success rate is 0 percent (0/5)
ping 命令失败!使用 debug ip packet 命令来监测
R1#debug ip packet
IP packet debugging is on
R1#ping 23.1.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
*Jan  6 13:42:15.271: IP: s=12.1.1.1 (local), d=23.1.1.3, len 100, unroutable.
*Jan  6 13:42:17.271: IP: s=12.1.1.1 (local), d=23.1.1.3, len 100, unroutable.
*Jan  6 13:42:19.271: IP: s=12.1.1.1 (local), d=23.1.1.3, len 100, unroutable.
*Jan  6 13:42:21.271: IP: s=12.1.1.1 (local), d=23.1.1.3, len 100, unroutable.
*Jan  6 13:42:23.271: IP: s=12.1.1.1 (local), d=23.1.1.3, len 100, unroutable.
Success rate is 0 percent (0/5)
根据 debug 信息可以看到 ping 不通是因为无法路由( unroutable ),使用 show ip route 来查看路由表
R1#sh 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
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, Serial1/1
由结果看到路由表中没有 23.1.1.0/24 的路由条目,所以需要手动添加静态路由。
R1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#ip route 23.1.1.0 255.255.255.0 serial 1/1
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
 
     23.0.0.0/24 is subnetted, 1 subnets
S       23.1.1.0 is directly connected, Serial1/1
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, Serial1/1
可以看到此时 R1 发生了变化,多了一条静态路由。
现在再 ping R3 监测一下
R1#ping 23.1.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
*Jan  6 13:54:32.035: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending.
*Jan  6 13:54:34.031: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending.
*Jan  6 13:54:36.031: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending.
*Jan  6 13:54:38.031: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending.
*Jan  6 13:54:40.031: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending.
Success rate is 0 percent (0/5)
现在显示的是数据已经发送出去( sending ),但是依然不通,考虑一下 ping 是一个双向的过程,于是去 R2 上面看一下
R2#ping 23.1.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/53/96 ms
R2#ping 12.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/41/72 ms
R2 上可以 ping R1 R3 ,说明 R2 没有问题。
再到 R3 上面来看一下路由表。
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
 
     23.0.0.0/24 is subnetted, 1 subnets
C       23.1.1.0 is directly connected, Serial1/0
发现路由器 R3 没有去往 12.1.1.0/24 网络的路由信息,此时 debug R3 ping R1 的过程也可以证明了这个推断。
R3#debug ip packet
IP packet debugging is on
R3#ping 12.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:
*Jan  6 14:12:10.579: IP: s=23.1.1.3 (local), d=12.1.1.1, len 100, unroutable.
*Jan  6 14:12:12.579: IP: s=23.1.1.3 (local), d=12.1.1.1, len 100, unroutable.
*Jan  6 14:12:14.579: IP: s=23.1.1.3 (local), d=12.1.1.1, len 100, unroutable.
*Jan  6 14:12:16.579: IP: s=23.1.1.3 (local), d=12.1.1.1, len 100, unroutable.
*Jan  6 14:12:18.579: IP: s=23.1.1.3 (local), d=12.1.1.1, len 100, unroutable.
Success rate is 0 percent (0/5)
R3 上添加去何 12.1.1.0/24/ 网络的静态路由
R3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#ip route 12.1.1.0 255.255.255.0 23.1.1.2
返回特权模式,查看路由表的变化
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
     23.0.0.0/24 is subnetted, 1 subnets
C       23.1.1.0 is directly connected, Serial1/0
     12.0.0.0/24 is subnetted, 1 subnets
S       12.1.1.0 [1/0] via 23.1.1.2
R3 的路由表已经创建一条去往 12.1.1.0/24 网络的路由,在 R3 ping R1 测试一下
R3#ping 12.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.1, timeout is 2 seconds:
!!!!! (可以ping 通)
现在回到 R1 上再 ping  R 3 测试一下
R1#ping 23.1.1.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
!!!!! ( 也可以ping 通了)
Debug 信息也可以看到发出去的包有了回复
R1#debug ip packet
*Jan  6 14:20:50.511: IP: tableid=0, s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), routed via RIB
*Jan  6 14:20:50.515: IP: s=12.1.1.1 (local), d=23.1.1.3 (Serial1/1), len 100, sending
*Jan  6 14:20:50.615: IP: tableid=0, s=23.1.1.3 (Serial1/1), d=12.1.1.1 (Serial1/1), routed via RIB
*Jan  6 14:20:50.615: IP: s=23.1.1.3 (Serial1/1), d=12.1.1.1 (Serial1/1), len 100, rcvd 3
…………………( 省略部分 debug 信息 )………………………………..