路由重发布
{Back to Index}  

Table of Contents

1 定义 👨🏻‍🎓

在路由器上,当将路由协议 A 重发布进路由协议 B 时, 会将路由器上 所有运行 A 协议的接口以及所有学习到的 A 协议路由 重分布进 B 协议中。

换句话说,可以被重分布的路由条目有两种:

  1. 因为重分布是 基于路由表 的, 只有在路由表中呈现为协议 A 的路由条目时,才会重分布进路由协议 B
  2. 被 A 协议所 network 的 直连接口 也会被重分布进 B 协议

1.1 原则

(其实就是上面所描述的内容的总结)

  • 重分布总是 向外的 ,执行重分发的路由器不会修改其自身的路由表,否则就是 过河拆桥
  • 要发布出去的路由必须要 存在 于路由表中(且 类型为源路由协议或与源协议路由器直连的网段)才能被重分发

2 种子度量值

种子度量值也叫初始度量值,默认度量值。是在重分发配置期间定义的,可使用命令 default-metric 或在 redistribute 命令中使用 metric 来指定。

2.1 默认种子度量值

重分布 进入 的协议 默认度量值 备注
RIP 重分布时必须手工指定 metric 值 [重分布直连,静态默认为 1]
EIGRP 重分布时必须手工指定 metric 值(10000 100 255 1 1500)[重分布直连,静态会自动计算,EIGRP 进程间重分布不需要指定]
OSPF BGP 为 1 ,其他路由为 20 注意加上 subnets 关键字,否则自由主类路由会被重分布
ISIS 0  
BGP set to IGP metric value  

3 协议间重发布

3.1 => RIP (metric 1)

指定 metric 为 1 即可。

to_rip.png

3.2 => OSPF (subnets)

to_ospf.png

3.3 => EIGRP (10000 100 255 1 1500)

需要指定 带宽/延迟/可靠性/负载/MTU 作为 metric 。

to_eigrp.png

4 重发布静态路由

redistribute static

5 重发布直连接口

通常用于不想通告接口,但又想让其他协议路由器学习到直连网络的信息。比如下图, R1 并不想 e0/1 向外发送 OSPF 消息(通常接口直接连着 PC),但希望 R2 又能学习到 R1 连接的网络。

connected.png

Figure 4: 实验拓扑

R1#show running-config | s ospf
 ip ospf 1 area 0
router ospf 1
 router-id 1.1.1.1
 redistribute connected metric 10 subnets
R1#

R2 可以学到直连网络( 包括逻辑接口上的网络 ):

R2#show ip route
Gateway of last resort is not set

      11.0.0.0/32 is subnetted, 1 subnets
O E2     11.11.11.11 [110/10] via 192.168.12.1, 00:00:03, Ethernet0/0
O E2  192.168.1.0/24 [110/10] via 192.168.12.1, 01:03:23, Ethernet0/0
      192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.12.0/24 is directly connected, Ethernet0/0
L        192.168.12.2/32 is directly connected, Ethernet0/0

6 实验

6.1 单点双向重发布 1

ripv2_ospf_topo.png

Figure 5: 实验拓扑

将 RIPv2 发布进 OSPF
R2(config)#router ospf 1 ! 进入目标协议配置模式
R2(config-router)#redistribute rip ! 最好加上 subnets 参数,否则只会将主类网络发布过来,从下面的显示看,这个参数好像是默认的
R2(config-router)#do sh run | s ospf
 ip ospf 1 area 0
router ospf 1
 router-id 2.2.2.2
 redistribute rip subnets
R3 路由信息
R3#show ip route | begin Gateway
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
O E2     1.1.1.1 [110/20] via 192.168.23.2, 00:02:46, Ethernet0/0
      3.0.0.0/32 is subnetted, 1 subnets
C        3.3.3.3 is directly connected, Loopback0
O E2  192.168.12.0/24 [110/20] via 192.168.23.2, 00:07:39, Ethernet0/0
      192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.23.0/24 is directly connected, Ethernet0/0
L        192.168.23.3/32 is directly connected, Ethernet0/0
R1 路由信息
R1#show ip route
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback0
      192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.12.0/24 is directly connected, Ethernet0/0
L        192.168.12.1/32 is directly connected, Ethernet0/0
将 OSPF 发布进 RIPv2
R2(config)#router rip
R2(config-router)#redistribute ospf 1 metric 3
R1 路由信息(重发布后)
R1#show ip route
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback0
      3.0.0.0/32 is subnetted, 1 subnets
R        3.3.3.3 [120/3] via 192.168.12.2, 00:00:01, Ethernet0/0 # metric 为 3
      192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.12.0/24 is directly connected, Ethernet0/0
L        192.168.12.1/32 is directly connected, Ethernet0/0
R     192.168.23.0/24 [120/3] via 192.168.12.2, 00:00:01, Ethernet0/0
使用静态路由覆盖动态路由
R2(config)#ip route 1.1.1.1 255.255.255.255 null 0
R2(config)#do show ip route
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
S        1.1.1.1 is directly connected, Null0
      3.0.0.0/32 is subnetted, 1 subnets
O        3.3.3.3 [110/11] via 192.168.23.3, 00:22:29, Ethernet0/1
      192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.12.0/24 is directly connected, Ethernet0/0
L        192.168.12.2/32 is directly connected, Ethernet0/0
      192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.23.0/24 is directly connected, Ethernet0/1
L        192.168.23.2/32 is directly connected, Ethernet0/1
R3 路由信息
R3#show ip route
Gateway of last resort is not set

      3.0.0.0/32 is subnetted, 1 subnets
C        3.3.3.3 is directly connected, Loopback0
O E2  192.168.12.0/24 [110/20] via 192.168.23.2, 00:26:14, Ethernet0/0 ! 只剩与 RIP 直连网络路由信息了
      192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.23.0/24 is directly connected, Ethernet0/0
L        192.168.23.3/32 is directly connected, Ethernet0/0

6.2 单点重分发次优路径问题

not_good_route.png

Figure 6: 实验拓扑

在 R3 上将 RIP 路由重分发进 OSPF ,由于 OSPF 的 AD 值大于 RIP ,因此 R4 去往 192.168.1.0/24 网段的路由指向 R2 ,这就造成了次优路径。

R4 路由 (重分布前)
R4#show ip route | begin Gateway
Gateway of last resort is not set

R     192.168.1.0/24 [120/1] via 192.168.45.5, 00:00:02, Ethernet0/1
O     192.168.12.0/24 [110/20] via 192.168.24.2, 00:07:32, Ethernet0/0
O     192.168.13.0/24 [110/30] via 192.168.24.2, 00:07:32, Ethernet0/0
      192.168.24.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.24.0/24 is directly connected, Ethernet0/0
L        192.168.24.4/32 is directly connected, Ethernet0/0
R     192.168.35.0/24 [120/1] via 192.168.45.5, 00:00:02, Ethernet0/1
      192.168.45.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.45.0/24 is directly connected, Ethernet0/1
L        192.168.45.4/32 is directly connected, Ethernet0/1
R4 路由 (重分布后)
R4#show ip route | begin Gateway
Gateway of last resort is not set

O E2  192.168.1.0/24 [110/23] via 192.168.24.2, 00:00:20, Ethernet0/0 # 选择 OSPF 发布的路由(次优路径)
O     192.168.12.0/24 [110/20] via 192.168.24.2, 00:11:26, Ethernet0/0
O     192.168.13.0/24 [110/30] via 192.168.24.2, 00:11:26, Ethernet0/0
      192.168.24.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.24.0/24 is directly connected, Ethernet0/0
L        192.168.24.4/32 is directly connected, Ethernet0/0
O E2  192.168.35.0/24 [110/23] via 192.168.24.2, 00:00:20, Ethernet0/0
      192.168.45.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.45.0/24 is directly connected, Ethernet0/1
L        192.168.45.4/32 is directly connected, Ethernet0/1

6.3 多点单向重发布存在的问题

在上面的例子中,假设 R4 也配置了重分布(向 OSPF 发布 RIP 路由) ,但是由于 192.168.1.0/24 已属于 O E2 ,因此重分布无效。

6.4 多点双向重发布产生环路的问题 2

从低 AD 值协议区域重分布到高 AD 值协议区域不会产生问题,反过来就会产生问题。

loop_topo.png

Figure 7: 实验拓扑

初始配置
----------------- R1 ----------------------
en
conf t
hostname R1
no ip do lo
line con 0
  exec-timeout 0 0
  logging synchronous
exit
int lo0
  ip address 1.1.1.1 255.255.255.255
int e0/0
  ip address 10.1.12.1 255.255.255.0
  no sh
int e0/1
  ip address 10.1.13.1 255.255.255.0
  no sh
router ospf 110
  router-id 11.11.11.11
  network 10.1.12.1 0.0.0.0 area 0
  network 10.1.13.1 0.0.0.0 area 0
----------------- R2 ----------------------
en
conf t
hostname R2
no ip do lo
line con 0
  exec-timeout 0 0
  logging synchronous
exit
int lo0
  ip address 2.2.2.2 255.255.255.255
int e0/0
  ip address 10.1.12.2 255.255.255.0
  no sh
int e0/1
  ip address 10.1.24.2 255.255.255.0
  no sh
int e0/2
  ip address 10.1.23.2 255.255.255.0
  no sh
router ospf 110
  router-id 22.22.22.22
  network 10.1.12.2 0.0.0.0 area 0
router rip
 version 2
 no auto-summary
 network 10.1.23.2
 network 10.1.24.2
----------------- R3 ----------------------
en
conf t
hostname R3
no ip do lo
line con 0
  exec-timeout 0 0
  logging synchronous
exit
int lo0
  ip address 3.3.3.3 255.255.255.255
int e0/0
  ip address 10.1.13.3 255.255.255.0
  no sh
int e0/1
  ip address 10.1.34.3 255.255.255.0
  no sh
int e0/2
  ip address 10.1.23.3 255.255.255.0
  no sh
router ospf 110
  router-id 33.33.33.33
  network 10.1.13.3 0.0.0.0 area 0
router rip
 version 2
 no auto-summary
 network 10.1.23.3
 network 10.1.34.3
----------------- R4 ----------------------
en
conf t
hostname R4
no ip do lo
line con 0
  exec-timeout 0 0
  logging synchronous
exit
int lo0
  ip address 4.4.4.4 255.255.255.255
int e0/0
  ip address 10.1.24.4 255.255.255.0
  no sh
int e0/1
  ip address 10.1.45.4 255.255.255.0
  no sh
int e0/2
  ip address 10.1.34.4 255.255.255.0
  no sh
router rip
 version 2
 no auto-summary
 network 10.1.24.4
 network 10.1.34.4
 network 10.1.45.4
----------------- R5 ----------------------
en
conf t
hostname R5
no ip do lo
line con 0
  exec-timeout 0 0
  logging synchronous
exit
int lo0
  ip address 5.5.5.5 255.255.255.255
int e0/1
  ip address 10.1.45.5 255.255.255.0
  no sh
router rip
 version 2
 no auto-summary
 network 10.1.45.5
 network 5.5.5.5
R2 上将 RIP 重发布进 OSPF
router ospf 110
 router-id 22.22.22.22
 redistribute rip subnets
 network 10.1.12.2 0.0.0.0 area 0
R3 路由信息
R3#sh 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, p - overrides from PfR

Gateway of last resort is not set

      3.0.0.0/32 is subnetted, 1 subnets
C        3.3.3.3 is directly connected, Loopback0
      5.0.0.0/32 is subnetted, 1 subnets
O E2     5.5.5.5 [110/20] via 10.1.13.1, 00:16:21, Ethernet0/0 ! 次优路径
      10.0.0.0/8 is variably subnetted, 9 subnets, 2 masks
O        10.1.12.0/24 [110/20] via 10.1.13.1, 00:27:42, Ethernet0/0
C        10.1.13.0/24 is directly connected, Ethernet0/0
L        10.1.13.3/32 is directly connected, Ethernet0/0
C        10.1.23.0/24 is directly connected, Ethernet0/2
L        10.1.23.3/32 is directly connected, Ethernet0/2
O E2     10.1.24.0/24 [110/20] via 10.1.13.1, 00:16:21, Ethernet0/0
C        10.1.34.0/24 is directly connected, Ethernet0/1
L        10.1.34.3/32 is directly connected, Ethernet0/1
O E2     10.1.45.0/24 [110/20] via 10.1.13.1, 00:16:21, Ethernet0/0
R3 上将 OSPF 重发布进 RIP
router rip
 version 2
 redistribute ospf 110 metric 1
 network 10.0.0.0
 no auto-summary
R2 路由信息
R2#sh 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, p - overrides from PfR

Gateway of last resort is not set

      2.0.0.0/32 is subnetted, 1 subnets
C        2.2.2.2 is directly connected, Loopback0
      5.0.0.0/32 is subnetted, 1 subnets
R        5.5.5.5 [120/1] via 10.1.23.3, 00:00:18, Ethernet0/2 ! 下一跳指向 R3 ,因为其 metric 值更小
      10.0.0.0/8 is variably subnetted, 9 subnets, 2 masks
C        10.1.12.0/24 is directly connected, Ethernet0/0
L        10.1.12.2/32 is directly connected, Ethernet0/0
O        10.1.13.0/24 [110/20] via 10.1.12.1, 00:30:26, Ethernet0/0
C        10.1.23.0/24 is directly connected, Ethernet0/2
L        10.1.23.2/32 is directly connected, Ethernet0/2
C        10.1.24.0/24 is directly connected, Ethernet0/1
L        10.1.24.2/32 is directly connected, Ethernet0/1
R        10.1.34.0/24 [120/1] via 10.1.24.4, 00:00:19, Ethernet0/1
                      [120/1] via 10.1.23.3, 00:00:18, Ethernet0/2
R        10.1.45.0/24 [120/1] via 10.1.24.4, 00:00:19, Ethernet0/1
                      [120/1] via 10.1.23.3, 00:00:18, Ethernet0/2
产生环路

R1 访问 5.5.5.5/32 的路由产生了一条环路 (R1->R2->R3->R1) :

loop_pcap.png

7 路由协议迁移套路

  1. 将现有路由协议 AD 值改小,小于即将安装的新路由协议
  2. 配置新路由协议
  3. 将旧路由协议 AD 改大,让新路由协议生效
  4. 删除旧路由协议

Footnotes:

1

重分布的定义 可知,单点双向重分布不会产生问题

2

EIGRP 和 OSPF 多点双向重分布不会产生问题,参考 https://youtu.be/O0lOsiCm8Gk?list=PLwLfEC5vHvKex1Z90_qz3fYXHGVmrnVFA&t=6644

Author: Hao Ruan (ruanhao1116@gmail.com)

Created: 2021-05-01 Sat 23:29

Updated: 2021-10-06 Wed 14:22

Emacs 27.1 (Org mode 9.3)