本文档介绍如何为 IPv6 配置静态路由。 静态路是手动配置的路由,用于定义两个设备之间的明确路径。当网络拓扑发生更改时,静态路由不会像动态协议那样自动更新,必须手动重新配置。对于只有一条路径通往外部网络的小型网络,静态路由非常有用。
使用静态路由的主要缺点就是在网络拓扑发生更改时不能自动重新配置。静态路由也可用于为大型网络中需要更多控制的特定类型流量提供安全保护。使用静态路由时需要考虑的局限性一是缺少冗余,二是在大型网络中,手动重新配置路由可能会造成巨大的管理开销。
使用ipv6 route命令配置静态路由。请注意,在为路由器配置静态IPv6路由之前,必须在全局配置模式下使用ipv6 unicast-routing命令启用IPv6数据包的转发。
尝试进行此配置之前,请确保满足以下要求:
具备与 IPv4 静态路由相关的知识
具备与 IPv6 寻址方案相关的知识
本文所述的内容基于运行 Cisco IOS® 软件版本 12.4(15)T13 的思科 3700 系列路由器。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您使用的是真实网络,请确保您已经了解所有命令的潜在影响。
有关文档规则的详细信息,请参阅 Cisco 技术提示规则。
本部分提供有关如何配置本文档所述功能的信息。
注意:使用命令查找工具(仅限注册客户)查找有关本文档中使用的命令的详细信息。
本文档使用以下网络设置:
  
 
本文档使用以下配置:
下面这段来自思科支持社区 的视频展示了如何在 Cisco IOS 路由器上为 IPv6 网络配置静态路由:
  
 
| 路由器 R1 | 
|---|
| version 12.4 ! hostname R1 ! ip cef ! ipv6 unicast-routing !--- Enables the forwarding of IPv6 packets. ! interface Loopback1 no ip address ipv6 address 1010::1/128 ! interface FastEthernet0/0 no ip address duplex auto speed auto ipv6 address 2000::1/126 ! ip forward-protocol nd ! ipv6 route 2001::/126 2000::2 ipv6 route 2020::1/128 2000::2 ipv6 route 3030::1/128 2000::2 !--- Static routes are configured in router R1, !--- to reach the networks in router R2 and R3. !--- This is done when you specify !--- the next-hop address, which in this case is !--- 2000::2 from which the output interface !--- is automatically derived. ! end | 
| 路由器 R2 | 
|---|
| version 12.4 ! hostname R2 ! ip cef ! ipv6 unicast-routing ! interface Loopback2 no ip address ipv6 address 2020::1/128 ! interface FastEthernet0/0 no ip address duplex auto speed auto ipv6 address 2000::2/126 ! interface FastEthernet0/1 no ip address duplex auto speed auto ipv6 address 2001::1/126 ! ip forward-protocol nd ! ipv6 route 1010::1/128 2000::1 ipv6 route 3030::1/128 2001::2 !--- Static routes are configured to reach !--- routers R1 and R3 loopback address when you !--- specify the corresponding interface address. ! end | 
| 路由器 R3 | 
|---|
| version 12.4 ! hostname R3 ! ip cef ! ipv6 unicast-routing ! interface Loopback3 no ip address ipv6 address 3030::1/128 ! interface FastEthernet0/0 no ip address duplex auto speed auto ipv6 address 2001::2/126 ! ip forward-protocol nd ! ipv6 route 1010::1/128 2001::1 ipv6 route 2000::/126 2001::1 ipv6 route 2020::1/128 2001::1 !--- For router 3, to reach R1 and R2, !--- static routes are configured when you !--- mention 2001::1 as the next-hop address. ! end | 
使用本部分可确认配置能否正常运行。
命令输出解释程序(仅限注册用户)(OIT) 支持某些 show 命令。使用 OIT 可查看对 show 命令输出的分析。
使用show ipv6 route static 命令显示IPv6路由表的内容,输出如下所示:
| show ipv6 route static | 
|---|
| 在路由器 R1 中 R1#show ipv6 route static
IPv6 Routing Table - 7 entries
Codes: C - Connected, L - Local, S - Static, R - RIP, B - BGP
       U - Per-user Static route, M - MIPv6
       I1 - ISIS L1, I2 - ISIS L2, IA - ISIS interarea, IS - ISIS summary
       O - OSPF intra, OI - OSPF inter, OE1 - OSPF ext 1, OE2 - OSPF ext 2
       ON1 - OSPF NSSA ext 1, ON2 - OSPF NSSA ext 2
       D - EIGRP, EX - EIGRP external
S   2001::/126 [1/0]
     via 2000::2
S   2020::1/128 [1/0]
     via 2000::2
S   3030::1/128 [1/0]
     via 2000::2
!--- Displays the static routes learnt by router R1 through 2000::2.
在路由器 R3 中R3#show ipv6 route static
IPv6 Routing Table - 7 entries
Codes: C - Connected, L - Local, S - Static, R - RIP, B - BGP
       U - Per-user Static route, M - MIPv6
       I1 - ISIS L1, I2 - ISIS L2, IA - ISIS interarea, IS - ISIS summary
       O - OSPF intra, OI - OSPF inter, OE1 - OSPF ext 1, OE2 - OSPF ext 2
       ON1 - OSPF NSSA ext 1, ON2 - OSPF NSSA ext 2
       D - EIGRP, EX - EIGRP external
S   1010::1/128 [1/0]
     via 2001::1
S   2000::/126 [1/0]
     via 2001::1
S   2020::1/128 [1/0]
     via 2001::1
!--- Displays the static routes learnt by router R3 through 2001::1.
 | 
路由器R1具有通往路由器R2和R3的路由,因此路由器R1应该能够ping通路由器R2的环回地址和路由器R3。请使用ping命令进行验证。
| 在路由器 R1 中 | 
|---|
| Ping 路由器 R2 的环回地址 R1#ping 2020::1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 2020::1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 0/36/104 ms !--- Router R1 is successfully able to ping !--- router R2's loopback address.Ping 路由器 R3 R1#ping 2001::2 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 2001::2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 12/40/116 ms R1#ping 3030::1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 3030::1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 8/32/84 ms !--- Similarly R1 is also able to reach R3, !--- for example, ping to R3's interface address !--- and loopback address from router R1 is successful. | 
注意:同样,路由器R3也可以到达路由器R1的Fa0/0地址2000::1及其环回地址1010::1。
使用show ipv6 static命令可显示路由表的当前内容,并使用detail语法可显示更多有用信息,本示例将讨论这些信息:
| show ipv6 static | 
|---|
| 在路由器 R1 中 R1#show ipv6 static IPv6 Static routes Code: * - installed in RIB * 2001::/126 via nexthop 2000::2, distance 1 * 2020::1/128 via nexthop 2000::2, distance 1 * 3030::1/128 via nexthop 2000::2, distance 1 !--- Displays the routes that are installed in !--- the IPv6 Routing Information Base(RIB) marked with *! | 
当指定 detail 关键字时,可以显示更多信息。以下为输出示例:
| show ipv6 static detail | 
|---|
| 在路由器 R2 中 R2#show ipv6 static detail
IPv6 Static routes
Code: * - installed in RIB
* 1010::1/128 via nexthop 2000::1, distance 1
     Resolves to 1 paths (max depth 1)
!--- Displays the output path set, and maximum !--- resolution depth, which in this case is 1.
     via FastEthernet0/0
* 3030::1/128 via nexthop 2001::2, distance 1
     Resolves to 1 paths (max depth 1)
     via FastEthernet0/1
!--- Displays that the route is received through !--- the next-hop 2000::1 through interface fa0/0.
 | 
注意:如果路由无效,将显示以下信息:
由于递归路由无效,所以路由无效。
由于直接指定路由或完全指定路由无效,所以路由无效。
| 版本 | 发布日期 | 备注 | 
|---|---|---|
| 1.0 | 
                                            
                                                16-Dec-2011
                                            
                                         | 初始版本 |