第116篇:IPv6 路由——静态与 OSPFv3 基础

关键词

IPv6 路由、OSPFv3、IPv6 静态路由、OSPFv3 vs OSPFv2、IPv6 路由表


一、IPv6 路由基础

1.1 IPv6 路由表

IPv6 路由表与 IPv4 类似,但地址是 128 位的:

display ipv6 routing-table
-----------------------------------------------
Destination  : 2001:DB8:1::/64       Protocol  : Direct
NextHop      : 2001:DB8:1::1         Preference: 0
Interface    : Vlanif10              Cost      : 0

Destination  : 2001:DB8:2::/64       Protocol  : Static
NextHop      : 2001:DB8:1::2         Preference: 60
Interface    : Vlanif10              Cost      : 0

Destination  : ::/0                   Protocol  : Static
NextHop      : 2001:DB8::1            Preference: 60
Interface    : Vlanif10

注意:IPv6 默认路由是 ::/0,而不是 0.0.0.0/0

1.2 IPv6 路由协议

路由类型 IPv4 对应 IPv6 实现
直连路由 接口配置 IP IPv6 直连
静态路由 ip route-static ipv6 route-static
IG(内部网关协议) OSPFv2/RIP OSPFv3/RIPng
EG(外部网关协议) BGP-4 MP-BGP

二、IPv6 静态路由

2.1 基本配置

# IPv6 静态路由配置
ipv6 route-static 2001:DB8:2:: 64 2001:DB8:1::2

# 带出接口的静态路由
ipv6 route-static 2001:DB8:3:: 64 GigabitEthernet0/0/1 FE80::2

# 默认路由
ipv6 route-static :: 0 2001:DB8::1

2.2 配置示例

   R1 ──── 2001:DB8:12::/64 ──── R2
    │                             │
2001:DB8:1::/64             2001:DB8:2::/64
# R1
interface GigabitEthernet0/0/0
 ipv6 enable
 ipv6 address 2001:DB8:12::1/64

interface GigabitEthernet0/0/1
 ipv6 enable
 ipv6 address 2001:DB8:1::1/64

ipv6 route-static 2001:DB8:2:: 64 2001:DB8:12::2

# R2
interface GigabitEthernet0/0/0
 ipv6 enable
 ipv6 address 2001:DB8:12::2/64

interface GigabitEthernet0/0/1
 ipv6 enable
 ipv6 address 2001:DB8:2::1/64

ipv6 route-static 2001:DB8:1:: 64 2001:DB8:12::1
ipv6 route-static :: 0 2001:DB8:12::1

2.3 浮动静态路由

# 主链路:优先级 60(默认)
ipv6 route-static 2001:DB8:2:: 64 2001:DB8:12::2

# 备份链路:优先级 100(更高值 = 更低优先级)
ipv6 route-static 2001:DB8:2:: 64 2001:DB8:13::2 preference 100

三、OSPFv3 基础

3.1 OSPFv3 与 OSPFv2 的差异

OSPFv3(RFC 5340)是为 IPv6 设计的 OSPF 版本。尽管很多概念相似,但关键区别如下:

对比项 OSPFv2(IPv4) OSPFv3(IPv6)
承载网络 IPv4 IPv6(使用链路本地地址)
Router ID 32 位 IPv4 地址 32 位 IPv4 地址(仍需配置)
运行方式 接口配置网络地址 接口运行在链路本地地址上
LSA 类型 7 种(Type 1-7) 修改 + 新增(Type 1-8)
认证 支持 依赖 IPsec
多实例 不支持 支持(Instance ID)
邻居 基于 IP 地址 基于链路本地地址

3.2 OSPFv3 的 LSA 类型

LSA 类型 名称 作用
Type 1 Router LSA 路由器链路信息
Type 2 Network LSA 网络链路信息(DR 生成)
Type 3 Inter-Area-Prefix LSA 区域间前缀(类似 OSPFv2 Type 3)
Type 4 Inter-Area-Router LSA 区域间路由器(类似 OSPFv2 Type 4)
Type 5 AS-External LSA 外部路由
Type 7 NSSA LSA NSSA 区域外部路由
Type 8 Link LSA 链路本地信息
Type 9 Intra-Area-Prefix LSA 区域内前缀(OSPFv3 特有)

3.3 OSPFv3 配置

# ===== R1 配置 =====
ospfv3 1
 router-id 1.1.1.1

interface GigabitEthernet0/0/0
 ipv6 enable
 ipv6 address 2001:DB8:12::1/64
 ospfv3 1 area 0                # 在接口上启用 OSPFv3 Area 0

interface GigabitEthernet0/0/1
 ipv6 enable
 ipv6 address 2001:DB8:1::1/64
 ospfv3 1 area 1                # OSPFv3 Area 1

# ===== R2 配置 =====
ospfv3 1
 router-id 2.2.2.2

interface GigabitEthernet0/0/0
 ipv6 enable
 ipv6 address 2001:DB8:12::2/64
 ospfv3 1 area 0

interface LoopBack0
 ipv6 enable
 ipv6 address 2001:DB8:2::1/128
 ospfv3 1 area 1

3.4 OSPFv3 邻居状态

display ospfv3 peer
-----------------------------------------------
OSPFv3 Process 1
Neighbors
 Area 0.0.0.0 interface GigabitEthernet0/0/0
 Router ID: 2.2.2.2     State: Full

四、RIPng 简介

RIPng(RIP Next Generation)是 IPv6 的距离矢量路由协议:

# 启用 RIPng
ripng 1

interface GigabitEthernet0/0/0
 ipv6 enable
 ipv6 address 2001:DB8:12::1/64
 ripng 1 enable

RIPng 使用 UDP 521 端口,度量仍然是跳数(最大 15),限制与 RIPv2 相同,实际部署中已被 OSPFv3 取代。


五、OSPFv3 排错

# 检查 OSPFv3 进程
display ospfv3 brief

# 检查接口
display ospfv3 interface

# 检查 LSDB
display ospfv3 lsdb

# 查看 IPv6 路由表
display ipv6 routing-table protocol ospfv3

# 邻居状态诊断
display ospfv3 peer verbose

常见问题

问题 原因 解决
邻居卡在 Init 接口未启用 ospfv3 检查接口配置
邻居卡在 ExStart MTU 不匹配 检查链路两端 MTU
邻居卡在 2-Way DR 选举问题 检查接口网络类型
路由不学习 Router ID 冲突 检查 Router ID 是否唯一

六、总结

知识点 核心要点
IPv6 静态路由 ipv6 route-static,默认路由 ::/0
OSPFv3 IPv6 的 OSPF,运行在链路本地地址上
Router ID 仍需手动配置 IPv4 格式的 Router ID
与 OSPFv2 区别 新 LSA 类型、基于链路本地、依赖 IPsec
OSPFv3 排错 检查 Router ID、MTU、接口配置

七、思考

  1. IPv6 的默认路由怎么写?
  2. OSPFv3 和 OSPFv2 最大的区别是什么?
  3. 为什么 OSPFv3 仍然需要配置 IPv4 格式的 Router ID?
  4. OSPFv3 新增了哪两种 LSA 类型?
  5. 如果在 OSPFv3 中邻居关系无法建立,最可能的三个原因是什么?

下篇预告:第117篇《IPv6 过渡技术——双栈、隧道、NAT64》——讲解 IPv4 向 IPv6 迁移过程中的三种主要过渡技术及其适用场景。