静态路由
实验拓扑:
- 网络拓扑及IP编址如图所示;VPCS4和VPCS5使用路由器模拟。
- 在R1、R2、R3、上配置静态路由,保证全网可达。
- 基础知识:
需要掌握静态路由的概念及实现。对于VPCS4来说,如需访问192.168.1.0/24外的网络,则需要将数据先发送网关R1,R1要有到达远端网络的路由。在完成基本的IP配置后,R1仅知道192.168.1.0/24及192.168.12.0/24网络(直连网络),而对于192.168.23.0/24、192.168.2.0/24网络并不知道怎么到达。因此需为其配置静态路由。同理,R2、R3也是一样,需要考虑数据的双向性,数据包有去得有回。
- 关键命令:
静态路由的配置命令如下:
router(config)# ip route 目的网络 网络掩码 下一跳地址/出接口
- 配置及实现:
- PC 及 R1/2/3基本配置、接口IP配置
如拓扑图上IP地址,并测试直连路由的连通性。
接口IP配置,此处略。
查看各设备直连接口状态
R1:
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.1.254 YES NVRAM up up
GigabitEthernet0/1 192.168.12.1 YES NVRAM up up
R2:
R2#sh ip int brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.23.2 YES NVRAM up up
GigabitEthernet0/1 192.168.12.2 YES NVRAM up up
R3:
R3#sh ip int brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.23.3 YES NVRAM up up
GigabitEthernet0/1 192.168.2.254 YES NVRAM up up
直连路由测试:
R1:
R1#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
.!!!!
R1#ping 192.168.12.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.2, timeout is 2 seconds:
!!!!!
R2:
R2#ping 192.168.12.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/3 ms
R2#ping 192.168.23.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 2/2/5 ms
R3:
R3#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 1/1/2 ms
R3#ping 192.168.23.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 2/2/4 ms
直连测试能够正常通信。
测试:测试VPCS4和VPCS5能否正常通信。
VPCS4:
VPCS> ping 192.168.2.1
*192.168.1.254 icmp_seq=1 ttl=255 time=3.628 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.1.254 icmp_seq=2 ttl=255 time=2.786 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.1.254 icmp_seq=3 ttl=255 time=1.816 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.1.254 icmp_seq=4 ttl=255 time=1.998 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.1.254 icmp_seq=5 ttl=255 time=2.036 ms (ICMP type:3, code:1, Destination host unreachable)
思考:为什么VPCS4和VPCS5无法正常通信?查看相关路由表。
VPCS4已经设置了缺省网关192.168.1.254,因此当它发送数据到本地网段外的节点时,数据包会被送到网关,所以我们接着去它的网关也就是R1上看看。
R1:
R1#sh ip route
192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
L 192.168.1.254/32 is directly connected, GigabitEthernet0/0
192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.12.0/24 is directly connected, GigabitEthernet0/1
L 192.168.12.1/32 is directly connected, GigabitEthernet0/1
注释:L – local(本地路由), C – connected(直连路由)
VPCS4可以ping通网关,但无法与VPCS5通信,因为沿途路由器没有相应的路由条目,R1的路由表里面并没有到达192.168.2.0/24网络的路由。
- 配置静态路由
R1:
R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.23.0 255.255.255.0 192.168.12.2
R1#sh ip route
192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
L 192.168.1.254/32 is directly connected, GigabitEthernet0/0
S 192.168.2.0/24 [1/0] via 192.168.12.2
192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.12.0/24 is directly connected, GigabitEthernet0/1
L 192.168.12.1/32 is directly connected, GigabitEthernet0/1
S 192.168.23.0/24 [1/0] via 192.168.12.2
- 从路由表中可以看到,一共六个条目,也就是六条路由,其中两条本地路由,两条直连路由,两条静态路由(S表示static)。
- 路由条目中的[1/0]意思是路由的[管理距离/度量值]。
- 路由条目中的via 192.168.12.2,下一跳是IP地址。
配置R2去往192.168.1.0/24及192.168.2.0/24网段的路由:
R2:
R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.12.1
R2(config)#ip route 192.168.2.0 255.255.255.0 192.168.23.3
配置R3去往192.168.1.0/24及192.168.12.0/24网段的路由:
R3:
R3(config)# ip route 192.168.1.0 255.255.255.0 192.168.23.2
R3(config)# ip route 192.168.12.0 255.255.255.0 192.168.23.2
查看两台VPCS是否能够相互ping通。
VPCS> ping 192.168.2.1
84 bytes from 192.168.2.1 icmp_seq=1 ttl=61 time=8.359 ms
84 bytes from 192.168.2.1 icmp_seq=2 ttl=61 time=4.466 ms
84 bytes from 192.168.2.1 icmp_seq=3 ttl=61 time=3.272 ms
84 bytes from 192.168.2.1 icmp_seq=4 ttl=61 time=5.829 ms
84 bytes from 192.168.2.1 icmp_seq=5 ttl=61 time=2.987 ms