Redistribution Between RIP and OSPF

clip_image002

1、 首先配置RIPv2和OSPF

2、 配置被动接口

3、 配置地址汇总

4、 重RIP重分配静态路由

5、 配置分配列表

6、 配置默认路由

7、 配置RIP和OSPF之间的重分配

8、 配置种子度量(seed metric)

9、 修改OSPF外部路由类型

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

首先在每台路由器上根据拓扑图配置接口IP地址

R1>

clip_image004

R2>

clip_image006

R3>

clip_image008

IP地址配置完成后,在R2上验证它到达R1和R3串行链路的接通性

R2#ping 172.16.12.1

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 172.16.12.1, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 168/202/248 ms

R2#ping 172.16.23.3

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 172.16.23.3, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 48/170/396 ms

接下来开始在R1和R2上配置RIPv2

R1#show runn | b r r

router rip

version 2

network 172.16.0.0

network 192.168.48.0

network 192.168.49.0

network 192.168.50.0

network 192.168.51.0

network 192.168.70.0

no auto-summary

!

R2#show runn | b r r

router rip

version 2

network 172.16.0.0

no auto-summary

!

在RIP进程下通告网络只需要通告主网络号,而不需要像EIGRP和OSPF那样加上反掩码。在R1和R2上show ip route rip验证配置是否成功

R1#show ip route rip

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.23.0 [120/1] via 172.16.12.2, 00:00:22, Serial0/0

R 172.16.2.0 [120/1] via 172.16.12.2, 00:00:22, Serial0/0

R2#show ip route rip

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.1.0 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

R 192.168.51.0/24 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

R 192.168.50.0/24 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

R 192.168.49.0/24 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

R 192.168.70.0/24 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

R 192.168.48.0/24 [120/1] via 172.16.12.1, 00:00:24, Serial0/1

RIP配置正确并成功的在R1和R2上面运行,R1可以学习到R2直连的172.16.2.0/24和172.16.23.0/24路由。172.16.23.0/24网络被通告成RIP里面是因为它属于172.16.0.0/16的子网,所以R2会在连接到R3的串行链路上发送RIP的周期更新,显然这是不必要和不安全的,可以通过被动接口抑制RIP更新在R2和R3之间串行链路上发送

R2#show ip pro

Routing Protocol is "rip"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Sending updates every 30 seconds, next due in 8 seconds

Invalid after 180 seconds, hold down 180, flushed after 240

Redistributing: rip

Default version control: send version 2, receive version 2

Interface Send Recv Triggered RIP Key-chain

Serial0/1 2 2

Serial0/3 2 2

Loopback0 2 2

Automatic network summarization is not in effect

Maximum path: 4

Routing for Networks:

172.16.0.0

R2#show ip pro

Routing Protocol is "rip"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Sending updates every 30 seconds, next due in 26 seconds

Invalid after 180 seconds, hold down 180, flushed after 240

Redistributing: rip

Default version control: send version 2, receive version 2

Interface Send Recv Triggered RIP Key-chain

Serial0/1 2 2

Loopback0 2 2

Automatic network summarization is not in effect

Maximum path: 4

Routing for Networks:

172.16.0.0

Passive Interface(s):

Serial0/3

当然环回接口也被通告到RIP里面,RIP更新也会在环回接口,所以在R1上把所有的环回接口都配置成为被动接口

router rip

version 2

passive-interface default

no passive-interface Serial0/0

network 172.16.0.0

network 192.168.48.0

network 192.168.49.0

network 192.168.50.0

network 192.168.51.0

network 192.168.70.0

no auto-summary

!

R1#show ip pro

Routing Protocol is "rip"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Sending updates every 30 seconds, next due in 19 seconds

Invalid after 180 seconds, hold down 180, flushed after 240

Redistributing: rip

Default version control: send version 2, receive version 2

Interface Send Recv Triggered RIP Key-chain

Serial0/0 2 2

Automatic network summarization is not in effect

Maximum path: 4

Routing for Networks:

172.16.0.0

192.168.48.0

192.168.49.0

192.168.50.0

192.168.51.0

192.168.70.0

Passive Interface(s):

Serial0/1

Serial0/2

Serial0/3

Loopback0

Passive Interface(s):

Loopback1

Loopback48

Loopback49

Loopback50

Loopback51

Loopback70

VoIP-Null0

Routing Information Sources:

Gateway Distance Last Update

172.16.12.2 120 00:00:04

Distance: (default is 120)

Passive-interface在RIP中可以抑制RIP向外发送RIP更新,但是还是可以在该接口上接收RIP更新。不过在OSPF中,由于LSA需要同步,如果配置了被动接口,那么在该接口方向上的邻居或邻接关系将会断开,并不会在该接口发送HELLO包。

查看R2上学习到的RIP路由,可以看到所有RIP域内的明细路由,但是为了节约路由器的内存空间加快路由表查找速度和减少路由更新对网络链路的占用,可以在R1上对明细路由进行汇总,但是RIP进行路由汇总是有条件的

R1(config-if)#int s0/0

R1(config-if)#ip summary-address rip 192.168.48.0 255.255.252.0

Summary mask must be greater or equal to major net

也就是RIP进行路由汇总时的掩码位数必须等于或者大于主类网络的掩码位数。在上面的RIP汇总中,掩码的位数必须等于或大于255.255.255.0,所以在这个网络环境中不可以使用这种方法对RIP进行路由汇总。回想一下EIGRP和OSPF进行路由汇总时都会产生一条指向NULL0的汇总路由,因此,也可以借鉴这种方法对RIP进行路由汇总。先在R1中配置一条指向NULL0的汇总路由之后再向RIP进程中重分配静态路由,这样可以达到路由汇总的目的

R1#show runn | b r

router rip

version 2

redistribute static metric 1

passive-interface default

no passive-interface Serial0/0

network 172.16.0.0

network 192.168.48.0

network 192.168.49.0

network 192.168.50.0

network 192.168.51.0

network 192.168.70.0

no auto-summary

!

ip http server

ip route 192.168.48.0 255.255.252.0 Null0

在R2上查看路由表,可以看到/22的路由

R2#show ip route rip

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.1.0 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.51.0/24 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.50.0/24 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.49.0/24 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.70.0/24 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.48.0/24 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

R 192.168.48.0/22 [120/1] via 172.16.12.1, 00:00:10, Serial0/1

其中,192.168.48.0/22路由中的度量值为1,也就是R1在重分配静态路由时所指定的价。如果R1在重分配时没有指定metric值那么默认度量值为无穷大,当然EIGRP在重分配时也需要指定度量值,但是OSPF存在默认重分配度量值为20。

在R2上存在向R1学习到的汇总路由和明细路由,为了让汇总路由真正起作用,必须在R1上进行路由过滤把所有的明细路由都抑制掉。

在R1上只需要允许172.16.1.0/24,192.168.48.0/22,192.168.70.0/24发送给R2,因为访问控制列表无法达到想要的效果,所以使用prefix-list

R1#show runn | b r r

router rip

version 2

redistribute static metric 1

passive-interface default

no passive-interface Serial0/0

network 172.16.0.0

network 192.168.48.0

network 192.168.49.0

network 192.168.50.0

network 192.168.51.0

network 192.168.70.0

distribute-list prefix 1to2 out Serial0/0

no auto-summary

!

ip http server

ip route 192.168.48.0 255.255.252.0 Null0

!

ip prefix-list 1to2 seq 5 permit 192.168.48.0/22

ip prefix-list 1to2 seq 10 deny 192.168.48.0/22 le 24

ip prefix-list 1to2 seq 15 permit 0.0.0.0/0 le 32

在R2上验证R1上的配置是否正确

R2#show ip route rip

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.1.0 [120/1] via 172.16.12.1, 00:00:05, Serial0/1

R 192.168.51.0/24 [120/1] via 172.16.12.1, 00:00:33, Serial0/1

R 192.168.50.0/24 [120/1] via 172.16.12.1, 00:00:33, Serial0/1

R 192.168.49.0/24 [120/1] via 172.16.12.1, 00:00:33, Serial0/1

R 192.168.70.0/24 [120/1] via 172.16.12.1, 00:00:05, Serial0/1

R 192.168.48.0/24 [120/1] via 172.16.12.1, 00:00:33, Serial0/1

R 192.168.48.0/22 [120/1] via 172.16.12.1, 00:00:05, Serial0/1

在R2上,192.168.48.0/22和其下的明细路由都没有变化,但是注意看路由表后面的时间,192.168.48.0/22的明细路由的时间都超过了RIP的更新时间间隔30S,这是因为RIP有180S的HoldTime时间,此时可以手动的更新路由表,在R2上

R2#clear ip route *

R2#show ip route rip

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.1.0 [120/1] via 172.16.12.1, 00:00:11, Serial0/1

R 192.168.70.0/24 [120/1] via 172.16.12.1, 00:00:11, Serial0/1

R 192.168.48.0/22 [120/1] via 172.16.12.1, 00:00:11, Serial0/1

现在开始配置OSPF

R2(config-router)#do show runn | b r o

router ospf 1

router-id 2.2.2.2

log-adjacency-changes

network 172.16.23.2 0.0.0.0 area 0

!

R3(config)#do show runn | b r o

router ospf 1

router-id 3.3.3.3

log-adjacency-changes

network 172.16.3.1 0.0.0.0 area 0

network 172.16.23.3 0.0.0.0 area 0

network 192.168.20.1 0.0.0.0 area 0

network 192.168.25.1 0.0.0.0 area 0

network 192.168.30.1 0.0.0.0 area 0

network 192.168.35.1 0.0.0.0 area 0

network 192.168.40.1 0.0.0.0 area 0

!

验证OSPF的配置

R2#show ip route ospf

192.168.30.0/32 is subnetted, 1 subnets

O 192.168.30.1 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

192.168.25.0/32 is subnetted, 1 subnets

O 192.168.25.1 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

192.168.40.0/32 is subnetted, 1 subnets

O 192.168.40.1 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

172.16.0.0/16 is variably subnetted, 5 subnets, 2 masks

O 172.16.3.1/32 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

192.168.20.0/32 is subnetted, 1 subnets

O 192.168.20.1 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

192.168.35.0/32 is subnetted, 1 subnets

O 192.168.35.1 [110/65] via 172.16.23.3, 00:04:57, Serial0/3

在R2上会发现通过OSPF学习到R3的环回口的网络掩码都是/32,这是因为

R3(config)#do show ip ospf int lo 0

Loopback0 is up, line protocol is up

Internet Address 172.16.3.1/24, Area 0

Process ID 1, Router ID 3.3.3.3, Network Type LOOPBACK, Cost: 1

Loopback interface is treated as a stub Host

所以,必须在环回接口上手动指定网络类型为点到点

interface Loopback0

ip address 172.16.3.1 255.255.255.0

ip ospf network point-to-point

!

interface Loopback20

ip address 192.168.20.1 255.255.255.0

ip ospf network point-to-point

!

….

R3(config)#do show ip ospf int bri

Interface PID Area IP Address/Mask Cost State Nbrs F/C

Lo40 1 0 192.168.40.1/24 1 P2P 0/0

Lo35 1 0 192.168.35.1/24 1 P2P 0/0

Lo30 1 0 192.168.30.1/24 1 P2P 0/0

Lo25 1 0 192.168.25.1/24 1 P2P 0/0

Lo20 1 0 192.168.20.1/24 1 P2P 0/0

Lo0 1 0 172.16.3.1/24 1 P2P 0/0

Se0/0 1 0 172.16.23.3/24 64 P2P 1/1

R2#show ip route ospf

O 192.168.30.0/24 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

O 192.168.25.0/24 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

O 192.168.40.0/24 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

172.16.0.0/24 is subnetted, 5 subnets

O 172.16.3.0 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

O 192.168.20.0/24 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

O 192.168.35.0/24 [110/65] via 172.16.23.3, 00:02:16, Serial0/3

当然也可以在R3把环回接口配置成为被动接口

R3(config-router)#do show runn | b r o

router ospf 1

router-id 3.3.3.3

log-adjacency-changes

passive-interface default

no passive-interface Serial0/0

network 172.16.23.3 0.0.0.0 area 0

network 192.168.0.0 0.0.255.255 area 0

!

由于OSPF链线状态数据库需要同步,所以不可以把R2和R3相连的串行链路接口配置成为被动接口,一但配置成为被动接口就会

*Mar 1 03:35:10.891: %OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on Serial0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

通过show ip protocol验证

R3#show ip pro

Routing Protocol is "ospf 1"

Outgoing update filter list for all interfaces is not set

Incoming update filter list for all interfaces is not set

Router ID 3.3.3.3

Number of areas in this router is 1. 1 normal 0 stub 0 nssa

Maximum path: 4

Routing for Networks:

172.16.23.3 0.0.0.0 area 0

192.168.0.0 0.0.255.255 area 0

Reference bandwidth unit is 100 mbps

Passive Interface(s):

Serial0/1

Serial0/2

Serial0/3

Loopback0

Loopback1

Loopback20

Loopback25

Loopback30

Loopback35

Loopback40

VoIP-Null0

现在开始在R2上把OSPF重分配到RIP

R2(config-router)#redistribute ospf 1 metric 2

把其他路由协议重分配到RIP时一定要配置度量值,否则默认的度量值为无穷大。在重分配时指定的metric值,为接受此路由第一跳路由器的度量值

R1#show ip route rip

R 192.168.30.0/24 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

R 192.168.25.0/24 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

R 192.168.40.0/24 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

172.16.0.0/24 is subnetted, 4 subnets

R 172.16.23.0 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

R 172.16.2.0 [120/1] via 172.16.12.2, 00:00:20, Serial0/0

R 192.168.20.0/24 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

R 192.168.35.0/24 [120/2] via 172.16.12.2, 00:00:20, Serial0/0

此时在R1上可以学习到OSPF域内的路由,但是R1和R3还是不可以正常通信,因为R3还没有到达R1的路由,所以可以在R2上起源一条默认路由,让R3可以通过R2和R1通信

R2(config-router)#default-information originate always

R3#show ip route ospf

O*E2 0.0.0.0/0 [110/1] via 172.16.23.2, 00:00:18, Serial0/0

当然也可以让R3学习到RIP域内的所有路由

R2(config-router)#redistribute rip subnets

OSPF重分配RIP时,后面加上subnets会对RIP的子网也进行重分配,在OSPF进程下进行重分配不需要指定度量值,因为OSPF默认的外部路由度量值为20

R3#show ip route ospf

172.16.0.0/24 is subnetted, 5 subnets

O E2 172.16.12.0 [110/20] via 172.16.23.2, 00:02:29, Serial0/0

O E2 172.16.1.0 [110/20] via 172.16.23.2, 00:02:29, Serial0/0

O E2 172.16.2.0 [110/20] via 172.16.23.2, 00:02:29, Serial0/0

O E2 192.168.70.0/24 [110/20] via 172.16.23.2, 00:02:29, Serial0/0

O E2 192.168.48.0/22 [110/20] via 172.16.23.2, 00:02:29, Serial0/0

当然也可以修改默认的度量值

R2(config-router)#default-metric ?

<1-16777214> OSPF default metric

在OSPF默认的外部路由类型为O E2。OE2外部路由洪泛到OSPF域内时,度量值是不会变的,当然可以修改为OE1类型的外部路由

R2(config-router)#redistribute rip subnets metric-type 1

在R3上验证配置

R3#show ip route ospf

172.16.0.0/24 is subnetted, 5 subnets

O E1 172.16.12.0 [110/84] via 172.16.23.2, 00:00:13, Serial0/0

O E1 172.16.1.0 [110/84] via 172.16.23.2, 00:00:13, Serial0/0

O E1 172.16.2.0 [110/84] via 172.16.23.2, 00:00:13, Serial0/0

O E1 192.168.70.0/24 [110/84] via 172.16.23.2, 00:00:13, Serial0/0

O E1 192.168.48.0/22 [110/84] via 172.16.23.2, 00:00:13, Serial0/0