redistribute (多个路由协议的路由重分发)

一、实验目标

  • 掌握综合路由的配置方法;
  • 掌握查看通过路由重分布学习产生的路由;
  • 熟悉广域网线缆的连接方式;

二、实验背景

假设某公司通过一台三层交换机连到公司出口路由器R1上,路由器R1再和公司外的另一台路由器R2连接。三层与R1间运行RIPv2路由协议,R1与R2间运行OSPF路由协议。现要做适当配置,实现公司内部主机与公司外部主机之间的相互通信。

三、技术原理

为了支持本设备能够运行多个路由协议进程,系统软件提供路由信息从一个路由进程重分布到另外一个路由进程的功能。比如你可以将OSPF路由域的路由重新分布后通告RIP路由域中,也可以将RIP路由域的路由重新分布后通告到OSPF路由域中。路由的相互重分布可以在所有的IP路由协议之间进行。

要把路由从一个路由域分布到另一个路由域,并且进行控制路由重分布,在路由进程配置模式中执行以下命令:

redistribute protocol [metric metric] [metric-type metric-type] [match internal | external type | nssa-external type] [tag tag] [route-map route-map-name] [subnets]

四、实验步骤

实验拓扑

redistribute (多个路由协议的路由重分发)

1、PC与交换机间用直连线连接;PC与路由、路由与路由之间用交叉线连接。

2、在三层上划分2个VLAN,运行RIPv2协议;R2运行OSPF协议;

3、在路由器R1上左侧配置RIPv2路由协议;右侧配置OSPF协议;

4、在R1路由器进程中引入外部路由,进行路由重分布;

5、将PC1、PC2主机默认网关分别设置为与直连网络设备接口IP地址;

6、验证PC1、PC2主机之间可以互相通信;

S3560:

 

Switch>en
Switch#conf t
Switch(config)#hostname S3560
S3560(config)#vlan 10
S3560(config-vlan)#exit
S3560(config)#vlan 20
S3560(config-vlan)#exit
S3560(config)#interface fa0/10
S3560(config-if)#switchport access vlan 10
S3560(config-if)#exit
S3560(config)#interface fa0/20
S3560(config-if)#switchport access vlan 20
S3560(config-if)#exit
S3560(config)#interface vlan 10
S3560(config-if)#
S3560(config-if)#ip address 192.168.1.1 255.255.255.0                        //配置vlan 10虚接口IP地址
S3560(config-if)#exit
S3560(config)#interface vlan 20
S3560(config-if)#ip address 192.168.2.1 255.255.255.0                        //配置vlan 20虚接口IP地址
S3560(config-if)#no shut                                                     //
S3560(config-if)#exit                                                       //开启路由功能
S3560(config)IP routing
S3560(config)#router rip                                                     //配置RIPv2协议
S3560(config-router)#network 192.168.1.0
S3560(config-router)#network 192.168.2.0
S3560(config-router)#version 2
S3560(config-router)#end
S3560#
S3560#show ip route 



S3560#show ip route                                                             //三台设备配置好后的路由信息

C    192.168.1.0/24 is directly connected, Vlan10
C    192.168.2.0/24 is directly connected, Vlan20
S3560#show ip route                                                             //路由重分布后的路由信息


C    192.168.1.0/24 is directly connected, Vlan10
C    192.168.2.0/24 is directly connected, Vlan20
R    192.168.3.0/24 [120/1] via 192.168.2.2, 00:00:28, Vlan20
R    192.168.4.0/24 [120/2] via 192.168.2.2, 00:00:28, Vlan20
S3560#

R1:
Router>en
Router#conf t
Router(config)#hostname R1
R1(config)#interface fa0/0
R1(config-if)#no shutdown 
R1(config-if)#ip address 192.168.2.2 255.255.255.0
R1(config-if)#exit
R1(config)#interface fa0/1
R1(config-if)#no shutdown 
R1(config-if)#ip address 192.168.3.1 255.255.255.0
R1(config-if)#exit
R1(config)#router rip                                                      //R1左侧配置RIPv2路由协议
R1(config-router)#network 192.168.2.0
R1(config-router)#version 2
R1(config-router)#exit
R1(config)#router ospf 1                                                   //R1右侧配置OSPF路由协议
R1(config-router)#network 192.168.3.1 0.0.0.255 area 0
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#show ip route 

R    192.168.1.0/24 [120/1] via 192.168.2.1, 00:00:14, FastEthernet0/0
C    192.168.2.0/24 is directly connected, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/1

R1#show ip route                                                           //三台设备配置好后的路由信息


R    192.168.1.0/24 [120/1] via 192.168.2.1, 00:00:06, FastEthernet0/0
C    192.168.2.0/24 is directly connected, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/1
O    192.168.4.0/24 [110/2] via 192.168.3.2, 00:01:22, FastEthernet0/1
R1#ping 192.168.1.2                                                       //从R1 ping左侧主机,可以ping通

Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:           
..!!!
Success rate is 60 percent (3/5), round-trip min/avg/max = 3/5/8 ms

R1#ping 192.168.4.2                                                       //从R1 ping右侧主机,可以ping通
                                                                          //此时左侧主机ping不通右侧主机
Sending 5, 100-byte ICMP Echos to 192.168.4.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 3/5/7 ms

R1#
R1#
R1#conf t
R1(config)#router rip
R1(config-router)# redistribute ospf 1 metric 1    //将ospf路由协议重分布进RIP,要注意加metric值设定种子metric值
R1(config-router)#exit
R1(config)#router ospf 1
R1(config-router)#redistribute rip ?
  metric       Metric for redistributed routes
  metric-type  OSPF/IS-IS exterior metric type for redistributed routes
  subnets      Consider subnets for redistribution into OSPF
  tag          Set tag for routes redistributed into OSPF
  <cr>
R1(config-router)#redistribute rip subnets        //(ospf里发布rip协议,如不加Subnets,默认只有主类地址能被重分布
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#show ip route                                                             //路由重分布后的路由信息

R    192.168.1.0/24 [120/1] via 192.168.2.1, 00:00:03, FastEthernet0/0
C    192.168.2.0/24 is directly connected, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/1
O    192.168.4.0/24 [110/2] via 192.168.3.2, 00:02:41, FastEthernet0/1
R1#
R1#show running-config 

R2:

Router>en
Router#conf t.
Router(config)#hostname R2
R2(config)#interface fa0/1
R2(config-if)#ip address 192.168.4.1 255.255.255.0
R2(config-if)#no shutdown 
R2(config-if)#exit
R2(config)#interface fa0/0
R2(config-if)#ip address 192.168.3.2 255.255.255.0
R2(config-if)#no shutdown 
R2(config-if)#
R2(config-if)#exit
R2(config)#router ospf 
R2(config)#router ospf 1                                            //配置R2 OSPF路由协议
R2(config-router)#network 192.168.3.0 0.0.0.255 area 0
R2(config-router)#network 192.168.4.0 0.0.0.255 area 0
R2(config-router)#end
R2#
R2#show ip route 
C    192.168.3.0/24 is directly connected, FastEthernet0/0
C    192.168.4.0/24 is directly connected, FastEthernet0/1
R2#
R2#show ip route                                                               //路由重分布后的路由信息
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is not set

O E2 192.168.1.0/24 [110/20] via 192.168.3.1, 00:00:05, FastEthernet0/0
O E2 192.168.2.0/24 [110/20] via 192.168.3.1, 00:00:05, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/0
C    192.168.4.0/24 is directly connected, FastEthernet0/1
R2#

 

PC1:

 

PC1>ping 192.168.4.2     不通
PC2>ping 192.168.1.2     不通   //路由重分布前,左右主机无法ping通





PC1>ping 192.168.4.2                                       //路由重分布后,左右主机可以ping通

在重分发时设定种子metric

协议 Seed MetricRIP 无限大 必须手工指定 (看ios版本)EIGRP 无限大 也必须手工指定 (看ios版本)OSPF 20 如果重分布进来的是BGP的话,Metric是1,这是个特例IS-IS 0BGP 携带原来的Metric值

R1(config-router)#default-metric 1 使用此命令来设定种子metric值

重分布分两种:1、单向重分布2、双向重分布

1)OSPF -> RIP: 将其它路由协议重分布进RIP,要注意加metric值

R1(config)#router ripR1(config-router)#redistribute ospf 110 metric 1 (优于default-metric命令)也可用以下方法指定Metric值R1(config-router)#default-metric 3 (默认Seed Metric=infinity无限大,修改Seed Metric=3)

 R1(config-router)#redistribute connected (可不加Metric,默认=1)重分布直连 R1(config-router)#redistribute static (可不加Metric,默认=1)重分布静态,路由前会打上R

2)RIP -> OSPF: 将其它路由协议重分布进OSPF,要注意加subnets参数

 R1(config)#router ospf 110 R1(config-router)#redistribute rip subnets (如不加Subnets,默认只有主类地址能被重分布)

https://www.cnblogs.com/mchina/archive/2012/07/20/2599961.html