天天看点

动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验

一.OSPF路由分发的原理

1.概述

       在现实环境中,一个单一的IP路由协议是管理网络中IP路由的首选方案,但是,在企业环境中,网络中是存在多种路由协议的,如果想要这些网络都互连互通,就要至少有一台路由器运行多种路由协议来实现不同网络之间的通信。这就需要使用路由重分发。

       路由重分发通常负责从一个AS区域学习路由,然后向另一个AS广播,简单来说就是将一种路由协议产生的路由条目转换成另一个路由协议的路由条目。比如:一台路由器既运行OSPF又运行RIP,如果OSPF进程被配置为通告由RIP学习到的路由到OSPF AS中,这种做法就可以成为“重分发RIP”。

2.路由重分发的因素

     进行路由重分发时,最常考虑的因素有:度量值和管理距离。

     OSPF使用的度量值是成本(cost);RIP使用的度量值时跳数(metric)。

     而关于路由的管理距离:

  •  直连的管理距离是0
  •  静态的管理距离是1
  •  OSPF的管理距离是110
  •  RIP的管理距离是120

    OSPF重分发路由的路径协议有两种,计算开销的方式是:

    类型1的外部路径(E1):内部开销+外部开销;

    类型2的外部路径(E2):只计算外部开销。

如下图:

动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验

二.路由重分发配置实验

1.网络拓扑图详解

动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验

2.实验配置

R5的配置

   R5的接口配置

R5#conf t
R5(config)#int f0/0
R5(config-if)#ip add 192.168.10.1 255.255.255.0
R5(config-if)#no shut
R5(config-if)#int f0/1
R5(config-if)#ip add 192.168.20.1 255.255.255.0
R5(config-if)#no shut
           

 R5的默认路由配置

R5(config-if)#ex
R5(config)#ip route 0.0.0.0 0.0.0.0 192.168.20.2
           

  查看R5的路由表

R5(config)#do show ip route
Codes: 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

Gateway of last resort is 192.168.20.2 to network 0.0.0.0

C    192.168.10.0/24 is directly connected, FastEthernet0/0
C    192.168.20.0/24 is directly connected, FastEthernet0/1
S*   0.0.0.0/0 [1/0] via 192.168.20.2
           

R6的配置

  R6的接口配置

R6#conf t
R6(config)#int f0/0
R6(config-if)#ip add 192.168.20.2 255.255.255.0
R6(config-if)#no shut
R6(config-if)#int f0/1
R6(config-if)#ip add 192.168.30.1 255.255.255.0
R6(config-if)#no shut
           

  R6配置静态路由通向PC3

R6#conf t
R6(config)#ip route 192.168.10.0 255.255.255.0 192.168.20.1
           

  R6的OSPF路由协议配置

R6#conf t
R6(config)#int loopback 0
R6(config-if)#ip add 6.6.6.6 255.255.255.255
R6(config-if)#exit
R6(config)#router ospf 1
R6(config-router)#router-id 6.6.6.6
R6(config-router)#network 192.168.30.0 0.0.0.255 area 1
           

  R6的OSPF状态下的重分发静态路由和直连网段

R6(config)router ospf 1
R(config-router)#redistribute static metric 100 subnets
R(config-router)#redistribute connected metric 1 subnets
           

   R6的路由表查看

R6(config)#do show ip route
Codes: 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

Gateway of last resort is 192.168.30.2 to network 0.0.0.0

C    192.168.30.0/24 is directly connected, FastEthernet0/1
O E2 192.168.60.0/24 [110/20] via 192.168.30.2, 00:49:28, FastEthernet0/1
S    192.168.10.0/24 [1/0] via 192.168.20.1
O IA 192.168.40.0/24 [110/11] via 192.168.30.2, 01:02:23, FastEthernet0/1
     6.0.0.0/32 is subnetted, 1 subnets
C       6.6.6.6 is directly connected, Loopback0
C    192.168.20.0/24 is directly connected, FastEthernet0/0
O IA 192.168.50.0/24 [110/20] via 192.168.30.2, 01:02:23, FastEthernet0/1
O E2 192.168.70.0/24 [110/20] via 192.168.30.2, 00:49:19, FastEthernet0/1
O*E2 0.0.0.0/0 [110/1] via 192.168.30.2, 00:56:22, FastEthernet0/1
R6(config)#
           

R7的配置

  R7的接口配置

R7#conf t
R7(config)#int f0/0
R7(config-if)#ip add 192.168.30.2 255.255.255.0
R7(config-if)#no shut 
R7(config-if)#int f0/1
R7(config-if)#ip add 192.168.50.1 255.255.255.0
R7(config-if)#no shut
R7(config-if)#int range f1/0 -1
R7(config-if-range)#no switchport    //因为这里使用的是交换机接口,所以关闭交换机功能
R7(config-if-range)#int f1/0
R7(config-if)#ip add 192.168.40.1 255.255.255.0
R7(config-if)#no shut
R7(config-if)#int f1/1
R7(config-if)#ip add 10.0.0.1 255.255.255.0
R7(config-if)#no shut
           

  R7配置静态路由通向PC6

R7#conf t
R7(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.2
           

  R7配置OSPF协议

R7#conf t
R7(config)#int lo 0


R7(config-if)#ip add 7.7.7.7 255.255.255.255
R7(config-if)#ex
R7(config)#router os 1
R7(config-router)#router-id 7.7.7.7
R7(config-router)#net 192.168.40.0 0.0.0.255 area 0    //把pc4的网段放在area 0中
R7(config-router)#net 192.168.50.0 0.0.0.255 area 0
R7(config-router)#net 192.168.30.0 0.0.0.255 area 1
           

  R7配置OSPF协议下重分发默认路由(给R10配置默认路由)

R7(config)#router os 1
R7(config-router)#default-information  originate 
R7(config-router)#ex
           

R8的配置

  R8的接口配置

R8#conf t
R8(config)#int f0/0
R8(config-if)#ip add 192.168.50.2 255.255.255.0
R8(config-if)#no shut

R8(config-if)#int f0/1
R8(config-if)#ip add 192.168.60.1 255.255.255.0
R8(config-if)#no shut
           

  R8配置OSPF协议

R8(config-if)#int lo 0
R8(config-if)#ip add 8.8.8.8 255.255.255.255
R8(config-if)#router os 1
R8(config-router)#router-id 8.8.8.8
R8(config-router)#net 192.168.50.0 0.0.0.255 area 0
           

  R8配置OSPF协议下的重分发RIP

R8(config-router)#redistribute rip subnets
R8(config-router)#ex
           

  R8配置RIP协议

R8(config)#router rip
R8(config-router)#version 2
R8(config-router)#no auto-summary
R8(config-router)#network 192.168.60.0
           

  R8配置RIP协议下重分发OSPF

R8(config-router)#redistribute ospf 1 metric 5
           

  查看R8的路由表信息

R8(config-router)#do show ip route
Codes: 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

Gateway of last resort is 192.168.50.1 to network 0.0.0.0

O IA 192.168.30.0/24 [110/20] via 192.168.50.1, 01:07:43, FastEthernet0/0
C    192.168.60.0/24 is directly connected, FastEthernet0/1
O E2 192.168.10.0/24 [110/5] via 192.168.50.1, 01:07:43, FastEthernet0/0
O    192.168.40.0/24 [110/11] via 192.168.50.1, 01:07:43, FastEthernet0/0
     6.0.0.0/32 is subnetted, 1 subnets
O E2    6.6.6.6 [110/0] via 192.168.50.1, 01:07:43, FastEthernet0/0
     8.0.0.0/32 is subnetted, 1 subnets
C       8.8.8.8 is directly connected, Loopback0
O IA 192.168.20.0/24 [110/30] via 192.168.50.1, 01:07:45, FastEthernet0/0
C    192.168.50.0/24 is directly connected, FastEthernet0/0
R    192.168.70.0/24 [120/1] via 192.168.60.2, 00:00:22, FastEthernet0/1
O*E2 0.0.0.0/0 [110/1] via 192.168.50.1, 01:07:45, FastEthernet0/0
           

R9的配置

  R9的接口配置

R9#conf t
R9(config)#int f0/0
R9(config-if)#ip add 192.168.60.2 255.255.255.0
R9(config-if)#no shut 
R9(config-if)#int f0/1 
R9(config-if)#ip add 192.168.70.1 255.255.255.0  
R9(config-if)#no shut
           

  R9的RIP协议配置

R9(config-if)#ex
R9(config)#router rip
R9(config-router)#ver 2
R9(config-router)#no au

R9(config-router)#network 192.168.60.0 
R9(config-router)#network 192.168.70.0 
           

  查看R9的路由表

R9(config-router)#do show ip route
Codes: 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

Gateway of last resort is 192.168.60.1 to network 0.0.0.0

R    192.168.30.0/24 [120/5] via 192.168.60.1, 00:00:22, FastEthernet0/0
C    192.168.60.0/24 is directly connected, FastEthernet0/0
R    192.168.10.0/24 [120/5] via 192.168.60.1, 00:00:22, FastEthernet0/0
R    192.168.40.0/24 [120/5] via 192.168.60.1, 00:00:22, FastEthernet0/0
     6.0.0.0/32 is subnetted, 1 subnets
R       6.6.6.6 [120/5] via 192.168.60.1, 00:00:22, FastEthernet0/0
R    192.168.20.0/24 [120/5] via 192.168.60.1, 00:00:22, FastEthernet0/0
R    192.168.50.0/24 [120/5] via 192.168.60.1, 00:00:23, FastEthernet0/0
C    192.168.70.0/24 is directly connected, FastEthernet0/1
R*   0.0.0.0/0 [120/1] via 192.168.60.1, 00:00:23, FastEthernet0/0
R9(config-router)#
           

R10的配置

  R10的接口配置

R10#conf t 

R10(config)#int f0/0
R10(config-if)#ip add 10.0.0.2 255.255.255.0
R10(config-if)#no shut

R10(config)#int f0/1                         
R10(config-if)#ip add 11.0.0.1 255.255.255.0    
R10(config-if)#no shut 
           

  R10的默认路由配置

R10(config-if)#ex
R10(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.1
           

  查看R10的路由表

R10#show ip route 
Codes: 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

Gateway of last resort is 10.0.0.1 to network 0.0.0.0

     10.0.0.0/24 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, FastEthernet0/0
     11.0.0.0/24 is subnetted, 1 subnets
C       11.0.0.0 is directly connected, FastEthernet0/1
S*   0.0.0.0/0 [1/0] via 10.0.0.1
           

配置PC3,PC4,PC5,PC6的IP地址和网关

PC3

PC3>ip 192.168.10.10 192.168.10.1
           

PC4

PC4>ip 192.168.70.70 192.168.70.1
           

PC5

PC5>ip 192.168.40.40 192.168.40.1
           

PC6

PC3>ip 11.0.0.2 11.0.0.1
           

PC3,PC4,PC5,PC6互ping

动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验
动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验
动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验
动态路由-----OSPF协议路由重分发及实验配置一.OSPF路由分发的原理二.路由重分发配置实验

实验完成!!!

路由表中,C表示直连路由、S表示静态路由、R表示通过RIP学到的路由、O表示通过OSPF学习到路由。

其中,有关的参数:

protocol:指明路由器要进行路由重分发的源路由协议,主要的值有:bgp、egp、isis、ospf[process-id]、static、connected和rip。其中,static表示重分发静态路由,connected表示重分发直连路由、ospf[process-id]表示重分发另一个另一个OSPF进程的路由,rip表示重分发rip路由信息;

metric:可选参数,用来指明重分发路由的度量值;

metric-type:指定重分发路由的类型,可取1或2两个值,1即E1,2即E2,默认是E2。

subnets:连其子网一起宣告。

继续阅读