前面的06篇如果R1之外有很多不同的网段或者是连接的internet;那么我们再SW上设置默认路由就会条目很多或者根本无法做完;
这时就需要配置默认路由了。
拓扑
本节实验拓扑:
我们还是用上一章的拓扑;首先将R1和SW1设定静态路由先删除。
配置
SW1:
SW1#conf t
SW1(config)#no ip route 1.1.1.0 255.255.255.0 f0/0
SW1(config)#end
SW1#
SW1#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.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
C 192.168.0.0/24 is directly connected, FastEthernet0/0
SW1#
R1:
R1#conf t
R1(config)#no ip route 192.168.10.0 255.255.255.0 f0/1
R1(config)#no ip route 192.168.20.0 255.255.255.0 192.168.0.253
R1(config)#end
R1#
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
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, FastEthernet0/0
C 192.168.0.0/24 is directly connected, FastEthernet0/1
R1#
PC1:
令PC1也回到最初无法连通的状态
SPC-1> ping 192.168.0.253
84 bytes from 192.168.0.253 icmp_seq=1 ttl=255 time=14.954 ms
84 bytes from 192.168.0.253 icmp_seq=2 ttl=255 time=15.959 ms
84 bytes from 192.168.0.253 icmp_seq=3 ttl=255 time=16.096 ms
84 bytes from 192.168.0.253 icmp_seq=4 ttl=255 time=15.779 ms
84 bytes from 192.168.0.253 icmp_seq=5 ttl=255 time=44.776 ms
PC-1> ping 192.168.0.254
192.168.0.254 icmp_seq=1 timeout
192.168.0.254 icmp_seq=2 timeout
192.168.0.254 icmp_seq=3 timeout
192.168.0.254 icmp_seq=4 timeout
192.168.0.254 icmp_seq=5 timeout
PC-1> ping 1.1.1.1
*192.168.10.254 icmp_seq=1 ttl=255 time=21.006 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.254 icmp_seq=2 ttl=255 time=45.408 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.254 icmp_seq=3 ttl=255 time=14.992 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.254 icmp_seq=4 ttl=255 time=14.958 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.254 icmp_seq=5 ttl=255 time=16.625 ms (ICMP type:3, code:1, Destination host unreachable)
PC-1>
接下来我们通过
1.对SW1设置默认路由(因为SW1对外有未知连接;对内都是直连路由(优先级较高且默认配置);适合只写默认路由)
2.R1设置静态路由+默认路由(因为R1对外有未知连接;对内连接有限且是经过我们规划的;若只写默认路由将导致不能兼顾的问题;实际上案例中配合静态或动态路由一起实现,动态路由部分我们后面再研究。)
SW1:
SW1#conf t
SW1(config)#ip route 0.0.0.0 0.0.0.0 f0/0
SW1(config)#end
SW1#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 0.0.0.0 to network 0.0.0.0
C 192.168.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
C 192.168.0.0/24 is directly connected, FastEthernet0/0
S* 0.0.0.0/0 is directly connected, FastEthernet0/0
SW1#
R1:
R1#conf t
R1(config)#ip route 192.168.10.0 255.255.255.0 f0/1
R1(config)#ip route 192.168.20.0 255.255.255.0 192.168.0.253
R1(config)#ip route 0.0.0.0 0.0.0.0 f0/0
R1(config)#end
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 0.0.0.0 to network 0.0.0.0
1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, FastEthernet0/0
S 192.168.10.0/24 is directly connected, FastEthernet0/1
S 192.168.20.0/24 [1/0] via 192.168.0.253
C 192.168.0.0/24 is directly connected, FastEthernet0/1
S* 0.0.0.0/0 is directly connected, FastEthernet0/0
R1#
结果验证
结果可以看到也是可以通的。
PC-1> ping 192.168.0.253
84 bytes from 192.168.0.253 icmp_seq=1 ttl=255 time=45.303 ms
84 bytes from 192.168.0.253 icmp_seq=2 ttl=255 time=16.630 ms
84 bytes from 192.168.0.253 icmp_seq=3 ttl=255 time=16.667 ms
84 bytes from 192.168.0.253 icmp_seq=4 ttl=255 time=15.990 ms
84 bytes from 192.168.0.253 icmp_seq=5 ttl=255 time=15.672 ms
PC-1> ping 192.168.0.254
192.168.0.254 icmp_seq=1 timeout
84 bytes from 192.168.0.254 icmp_seq=2 ttl=254 time=47.278 ms
84 bytes from 192.168.0.254 icmp_seq=3 ttl=254 time=46.173 ms
84 bytes from 192.168.0.254 icmp_seq=4 ttl=254 time=46.392 ms
84 bytes from 192.168.0.254 icmp_seq=5 ttl=254 time=45.668 ms
PC-1> ping 1.1.1.1
1.1.1.1 icmp_seq=1 timeout
84 bytes from 1.1.1.1 icmp_seq=2 ttl=254 time=46.067 ms
84 bytes from 1.1.1.1 icmp_seq=3 ttl=254 time=44.878 ms
84 bytes from 1.1.1.1 icmp_seq=4 ttl=254 time=46.357 ms
84 bytes from 1.1.1.1 icmp_seq=5 ttl=254 time=45.662 ms
PC-1>
这个实验比较简单,同时也是整个系列中不可或缺的一部分。