指定静态路由的下一跳 IP 地址 目录 简介背景信息对广播接口的静态路由浮动静态路由示例问题解决方案结论 简介 本文描述静态路由基本概念 问题场景用于为了展示指定接口下一跳 IP 地址可以被到达的情况变得理想, 当您配置静态路由时 失败可能导致不需要的行为和一个残破的网络状况 背景信息 由于各种各样的原因使用静态路由并且是常用的, 当没有动态路由对目的 IP 地址时, 或者, 当您要动态地改写获取的路由时 默认情况下, 静态路由有管理距离一个, 给他们在路由的优先从所有动态路由协议 当您将管理距离的值增加到高于动态路由协议的值时, 在动态路由发生故障的情况下, 静态路由可算作是一种安全保护网 例如, 增强的内部网关路由选择协议 (EIGRP) - 派生的路由有默认管理距离 90 内部路由的和 170 外部路由的 为了配置由 EIGRP 路由改写的静态路由, 请指定比 170 极大静态路由的管理距离 这种有高管理距离的静态路由呼叫浮动静态路由 只有当获取的路由动态地消失时, 它在路由表里安装 浮动静态路由的示例是 ip route 172.31.10.0 255.255.255.0 10.10.10.2 101 注意 : 管理距离 255 认为不可达的, 并且有管理距离的静态路由 255 从未被输入到路由表 对广播接口的静态路由 如果指向静态路由广播接口, 路由插入到路由表, 只有当广播接口是活跃的时 建议不采用此配置, 因为当静态路由的下一跳指向接口时, 路由器会认为路由范围内的每一台主机都可以通过该接口直接连接 这样静态路由示例是 ip route 0.0.0.0 0.0.0.0 Ethernet0 使用这类配置, 路由器执行在以太网的地址解析服务 (ARP) 路由器通过默认路由查找的每个目的地
的, 因为路由器所有这些目的地把直接地连接视为对 Ethernet0 这种静态路由, 特别是如果由对许多不同的目的地子网的许多数据包使用, 能导致高处理器利用率和一非常大 ARP 缓存 ( 与内存分配失败一起 ) 因此, 没有推荐这种静态路由 当您直接地指定在一个连接的接口时的下一跳地址, 防止路由器每目的地址的执行的 ARP 示例是 ip route 0.0.0.0 0.0.0.0 Ethernet0 192.168.1.1 您能指定仅直接地连接的下一跳地址, 但是这没有为在本文描述的原因推荐 您不需要指定直接地连接的下一跳地址 您能指定远程下一跳递归的远程下一跳地址和接口 如果与下一跳的接口断开, 并且下一跳通过递归路由是可及的, 您应该指定下一跳应该找到的下一跳 IP 地址和备选接口 例如,ip route 0.0.0.0 0.0.0.0 Serial 3/3 192.168.20.1 这使静态路由安装变得更加确定的 浮动静态路由示例 两个指定出站接口和下一跳地址用静态路由命令的此示例描述使用浮动静态路由并且说明需要 问题 使用在下镜像说明的网络配置, 一台主机 172.31.10.1 有连接到互联网 在本例中, 主机建立对互联网主机 10.100.1.1 的联系 : 使用此配置, 主链路是串行端口 1/0 之间的链路 R1 的到 R2 的串行端口 1/0 流量的到 / 从主机 172.31.10.1 到互联网 主机 10.100.1.1 例如互联网主机使用这里 串行端口 2/0 之间的链路对串行端口 2/0 的 R1 的 R2 的是备份链路 备份链路, 如果主链路发生故障, 应该只使用 这配置有指向主链路和使用浮动静态路由指向备份链路的使用静态路由 有两静态路由对同一个目的地 (172.31.10.0/24) 在 R1 一个路由是正常静态路由, 并且另一个路由是浮动静态路由, 是备份, 或者冗余路径对在 LAN 的目的地网络 在此方案的问题是浮动静态路由在路由表里从未安装, 当主链路发生故障时 这是在 R1 的配置 : hostname R1 interface Serial1/0 ip address 10.10.10.1 255.255.255.252 interface Serial2/0 ip address 10.10.20.1 255.255.255.252 ip route 10.0.0.0 255.0.0.0 192.168.10.2 This is the primary route to get to hosts on the Internet. ip route 172.31.10.0 255.255.255.0 10.10.10.2 This is the preferred route to the LAN. ip route 172.31.10.0 255.255.255.0 10.10.20.2 250 This is the floating static route to the LAN. 这是在 R2 的配置 :
hostname R1 interface Serial1/0 ip address 10.10.10.1 255.255.255.252 interface Serial2/0 ip address 10.10.20.1 255.255.255.252 ip route 10.0.0.0 255.0.0.0 192.168.10.2 This is the primary route to get to hosts on the Internet. ip route 172.31.10.0 255.255.255.0 10.10.10.2 This is the preferred route to the LAN. ip route 172.31.10.0 255.255.255.0 10.10.20.2 250 This is the floating static route to the LAN. 这是 R1 的路由表 : R1#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 5 subnets, 3 masks S 10.0.0.0/8 [1/0] via 192.168.10.2 C 10.10.10.0/30 is directly connected, Serial1/0 L 10.10.10.1/32 is directly connected, Serial1/0 C 10.10.20.0/30 is directly connected, Serial2/0 L 10.10.20.1/32 is directly connected, Serial2/0 172.31.0.0/24 is subnetted, 1 subnets S 172.31.10.0 [1/0] via 10.10.10.2 192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.10.0/30 is directly connected, Serial3/0 L 192.168.10.1/32 is directly connected, Serial3/0 当 ping 从主机执行到互联网主机 10.100.1.1 时, 作用正如所料 : host#ping 10.100.1.1 Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds: Success rate is 100 percent (5/5), round-trip min/avg/max = 73/78/80 ms 从主机的一 traceroute 到互联网主机 10.100.1.1 显示此 : host#traceroute 10.100.1.1 Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 10.10.10.1 31 msec 39 msec 39 msec 3 192.168.10.2 80 msec * 80 msec 主要使用链路 10.10.10.0/30
如果关闭 R1 的串行端口 1/0 为了测试故障切换, 您应该盼望 R1 安装浮动静态路由到本地 LAN 172.31.10.0 和为 R2to 安装浮动静态路由到 0.0.0.0 通过 10.10.20.1 您应该盼望流量漫过备份链路 R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface serial1/0 R1(config-if)#shutdown R1(config-if)#end R1# 然而, LAN 的 172.31.10.0/24 静态路由在 R1 的路由表里保持 : R1#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks S 10.0.0.0/8 [1/0] via 192.168.10.2 C 10.10.20.0/30 is directly connected, Serial2/0 L 10.10.20.1/32 is directly connected, Serial2/0 172.31.0.0/24 is subnetted, 1 subnets S 172.31.10.0 [1/0] via 10.10.10.2 192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.10.0/30 is directly connected, Serial3/0 L 192.168.10.1/32 is directly connected, Serial3/0R1#show ip route 172.31.10.0 Routing entry for 172.31.10.0/24 Known via "static", distance 1, metric 0 Routing Descriptor Blocks: * 10.10.10.2 Route metric is 0, traffic share count is 1 R1#show ip route 10.10.10.2 Routing entry for 10.0.0.0/8 Known via "static", distance 1, metric 0 Routing Descriptor Blocks: * 192.168.10.2 Route metric is 0, traffic share count is 1 ping 和 traceroute 从主机不再运作 : host#ping 10.100.1.1 Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds:... Success rate is 0 percent (0/5) host#traceroute 10.100.1.1 Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 * * * 3 * * * 4 * * * 5 * * *
6 * * * 7 * * * 8 * * * 9 * * * 10 * * * 11 * * *? 浮动静态路由在 R1 没有安装, 并且主要的静态路由仍然在 R,1 的路由表里, 即使串行端口 1/0 链路被关闭 因为静态路由是递归本质上, 这发生 只要您有到下一跳的路由, 您便永远具有路由表中的静态路由 在此问题场景中, 您也许预计, 因为主链路发生故障, 您应该有有在 R1 的路由表里 250 浮动静态路由安装的管理距离的 然而, 因为正常静态路由在路由表里, 保持浮动静态路由在路由表里没有安装 下一跳地址 10.10.10.2 顺利地 recursed 对 ( 对 192.168.10.2) 通过静态路由 10.0.0.0/8, 是存在路由表里 解决方案 配置在下一跳不可以是递归对另一静态路由的 R1 的静态路由 思科建议您配置出站接口和下一跳地址静态路由的 一旦 serial interfaces, 因为 serial interfaces 是点对点接口, 出站接口的规格是满足的 如果出站接口是以太网接口, 则您必须配置出站接口和下一跳地址 这里, LAN 的静态路由配置与出站接口的规格 : R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#no ip route 172.31.10.0 255.255.255.0 10.10.10.2 R1(config)#ip route 172.31.10.0 255.255.255.0 Serial1/0 R1(config)#endR1#show ip route Codes: L - local, 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, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks S 10.0.0.0/8 [1/0] via 192.168.10.2 C 10.10.20.0/30 is directly connected, Serial2/0 L 10.10.20.1/32 is directly connected, Serial2/0 172.31.0.0/24 is subnetted, 1 subnets S 172.31.10.0 [250/0] via 10.10.20.2 192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C 192.168.10.0/30 is directly connected, Serial3/0 L 192.168.10.1/32 is directly connected, Serial3/0 ping 和 traceroute 从主机到互联网主机当前运作, 并且使用备份链路 : R1#show ip route 172.31.10.0 Routing entry for 172.31.10.0/24 Known via "static", distance 250, metric 0 (connected) Routing Descriptor Blocks: * 10.10.20.2 Route metric is 0, traffic share count is 1host#ping 10.100.1.1
Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds: Success rate is 100 percent (5/5), round-trip min/avg/max = 76/79/80 ms host#traceroute 10.100.1.1 Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 10.10.20.1 38 msec 39 msec 40 msec 3 192.168.10.2 80 msec * 80 msec 结论 思科强烈建议您指定出站接口和下一跳 IP 地址, 当您配置静态路由时 当出站接口是链路的一种点到点类型 ( 例如, 串行链路 ), 下一跳地址的规格不是需要的