预配置第一步:R1上的预配置R1(config)#int s1/2R1(config-if)#ip address 10.1.1.1 255.255.255.0 R1(config-if)#no s
.
预配置
第一步:R1上的预配置
R1(config)#int s1/2
R1(config-if)#ip address 10.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config)#int lo0
R1(config-if)#ip ad 1.1.1.1 255.255.255.0
第二步:R2上的预配置
R2(config)#int s2/1
R2(config-if)#ip address 10.1.1.1 255.255.255.0
R2(config-if)#no sh
R2(config)#int lo0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
实验过程:
第一步:先在R1上ping 2.2.2.2网段
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 0 percent (0/5) (没有成功)
因为在R1上没有去2.2.2.0网段的路由
R1#sh ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * - candidate default
U - per-user static route, o - ODR
T - traffic engineered route
Gateway of last resort is not set
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial1/2
R1#
可以看到没有去R2的路由
第二步:新增路由
在R1上加一条默认路由
R1(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2 (这里是下一条的地址或为出接口)
R1#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * - candidate default
U - per-user static route, o - ODR
T - traffic engineered route
Gateway of last resort is 10.1.1.2 to network 0.0.0.0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Loopback0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial1/2
*S 0.0.0.0/0 [1/0] via 10.1.1.2 (这里可以看到多了一条默认路由)**
第四步:在R2上也加入一条默认路由让数据包能返回
R2(config)#ip route 0.0.0.0 0.0.0.0 s2/1
第五步:现在再次ping 测试一下
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/20/40 ms
在实际环境中一般当路由器作为出口进,配置一条
ip route 0.0.0.0 0.0.0.0 x.x.x.x(x.x.x.x为运营商给的网关)
或者
ip route 0.0.0.0 0.0.0.0 f0/0(f0/0为去运营商的出接口)