重发布技术-路由策略-策略路由(详解)

目录

在RIP中重发布:

在OSPF中重发布

重发布理解

重发布类型:

重发布中出现的问题

路由策略与策略路由

1.ACL工具:

2.前缀列表(prefix-list)

3.过滤列表(fitter-policy)

(1):在距离矢量型路由协议之间做(RIP):

(2).在链路状态型路由协议上做:

3.在不同协议之间使用(重发布):

4.路由策略列表(route-policy)


重发布:import (路由导入);

重发布:重发布就是将不同方式的路由(直连,静态,缺省,其他协议的路由)重发布进入RIP,OSPF中;

注意:     1.在华为中不能将缺省路由重发布进入RIP协议中(在思科中可以);

                2.不能将缺省路由重发布进入OSPF协议中(思科华为一致);

在RIP中重发布:

在RIP中默认的种子度量值为0;

在AR2中写一个静态和缺省,在AR2上将直连重发布到RIP中,将静态和OSPF重发布进入RIP中;
[r2]rip 100
[r2-rip-100]import-route direct 	---直连
[r2-rip-100]import-route static     ---静态
[r2-rip-100]import-route ospf 100   ---OSPF 100





重发布后在AR1上查看路由表:
[r1]display ip routing-table protocol rip
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : RIP
         Destinations : 4        Routes : 4        

RIP routing table status : <Active>
         Destinations : 3        Routes : 3

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.0/24  RIP     100  1           D   12.1.1.2        GigabitEthernet
0/0/0
        3.3.3.3/32  RIP     100  1           D   12.1.1.2        GigabitEthernet
0/0/0
       23.1.1.0/24  RIP     100  1           D   12.1.1.2        GigabitEthernet
0/0/0

RIP routing table status : <Inactive>
         Destinations : 1        Routes : 1

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      100.1.1.0/24  RIP     100  1               12.1.1.2        GigabitEthernet
0/0/0

在路由表中,我们并没有发现在AR2上的一条缺省路由,说明在RIP协议中不允许重发布缺省路由;

我们默认将静态,直连,其他方式动态均可以重发布进入RIP协议;并且默认度量值(种子度量值)均为0;但是缺省路由不能通过重发布方式引入;

我们可以调整默认度量值(种子度量值):

在进行重发布的路由器(AR2上做):

(1):修改重发布进来的所有的路由的种子度量值

[r2]rip 100
[r2-rip-100]default-cost 10		----调整重发布进来的所有路由的种子度量值为10;

修改后在AR1上查看RIP路由:发现现在的开销值变为11,因为cost=重发布进来的种子度量值+AR1与AR2之间的开销值
[r1]display ip routing-table protocol rip 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : RIP
         Destinations : 4        Routes : 4        

RIP routing table status : <Active>
         Destinations : 3        Routes : 3

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.0/24  RIP     100  11          D   12.1.1.2        GigabitEthernet
0/0/0
        3.3.3.3/32  RIP     100  11          D   12.1.1.2        GigabitEthernet
0/0/0
       23.1.1.0/24  RIP     100  11          D   12.1.1.2        GigabitEthernet
0/0/0

RIP routing table status : <Inactive>
         Destinations : 1        Routes : 1

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      100.1.1.0/24  RIP     100  11              12.1.1.2        GigabitEthernet
0/0/0



(2):修改重发布进来的某些路由的种子度量值,我们可以在重发布的过程中做

[r2]rip 100
[r2-rip-100]import-route ?      ------指定重发布什么路由;
  bgp     Border Gateway Protocol (BGP) routes
  direct  Direct routes
  isis    Intermediate System to Intermediate System (ISIS) routes
  ospf    Open Shortest Path First (OSPF) routes
  rip     Routing Information Protocol (RIP) routes
  static  Static routes
  unr     User Network Route
[r2-rip-100]import-route static ?   ----指定重发布的路由为静态路由
  cost          Cost of the import route
  route-policy  Apply the specified route policy to filter route
  <cr>          Please press ENTER to execute command 
[r2-rip-100]import-route static cost 8 ---指定重发布进入的静态路由的种子度量值为8;

在OSPF中重发布

在OSPF中,重发布进来的路由默认为类型2,默认种子度量值为1;

我们可以在重发布的过程中修改默认的类型和种子度量值;

在进行重发布的路由器上修改默认类型和种子度量值:
(1)在OSPF进程中修改重发布进来的所有路由的类型和种子度量值:
[r2]ospf 100
[r2-ospf-100]default type ?
  INTEGER<1-2>  Type value
[r2-ospf-100]default type 1 cost 12  ---修改默认类型为1,种子度量值为12;


(2)在重发布的过程中修改:
[r2-ospf-100]import-route ?				---选择重发布什么路由
  bgp     Border Gateway Protocol (BGP) routes
  direct  Connected routes
  isis    Intermediate System to Intermediate System (IS-IS) routes
  limit   Limit the number of routes imported into OSPF
  ospf    Open Shortest Path First (OSPF) routes
  rip     Routing Information Protocol (RIP) routes
  static  Static routes
  unr     User Network Routes
[r2-ospf-100]import-route rip 100 ?     ----选择重发布进来的属性;
  cost          Set cost	
  route-policy  Route policy
  tag           Specify route tag
  type          Metric type of the imported external routes
  <cr>          Please press ENTER to execute command 
[r2-ospf-100]import-route rip 100 type 1	
[r2-ospf-100]import-route rip 100 type 1  cost 23  ------将RIP 100重发布进入OSPF中时将默认类型修改为1,将默认种子度量值修改为23;

重发布理解

重发布的定义:在重发布时,将协议A重发布到协议B中,并不是说将A协议中的所有路由全部重发布到B协议中,而是将A协议学习并加表的路由以及通告在A协议中接口所对应的路由;

如下图:

我们将: OSPF100重发布 ----到---> OSPF 200 -------再将OSPF200重发布到------> RIP 100中;

之后我们在AR1上查看RIP路由表:发现只有 4.4.4.0/24和24.1.1.0/24这两条路由,说明将OSPF200重发布到RIP中时并不会将OSPF200在OSPF100中学习到的路由传递过去;

重发布类型:

重发布点:单点,双点,多点;

重发布向:单向,双向,多向;

1.单点重发布:只在一个点上做重发布

2.双点重发布:在两个点上做重发布,可以做备份,提高网络的安全性;

3.多点重发布:就是在多个点进行重发布

4.单向重发布:仅仅将协议A重发布到协议B中;

5.双向重发布:将A协议重发布到B协议中,将B协议重发布到A协议中;

重发布中出现的问题

在多点多向重发布中,会出现以下几种问题:

1.次优路径(原因:不同的路由协议AD值不同,以及计算metric值的方式不同);

2.路由环路(原因:路由回馈);

路由回馈就是在重发布的过程中,从其他协议学习到自己协议的路由并加表;

在重发布中,没有路由回馈就没有路由环路;

在重发布后,我们需要使用网络工具来解决次优路径以及路由环路。
思路:
1.先解决路由回馈(保证所有进行重发布的路由器上的路由是正确的),就解决了路由环路;
2.根据不同的路由协议进行次优路径的调整;

路由策略与策略路由

1:路由策略:路由策略是通过调整路由的策略;控制层面

理解:你学到路由不是最优路由,你学的路由里面有次优路径,你的路由表里面有路由环路;我们就需要使用一些控制列表让路由器在学习路由时按照最合理的进行加表;也就是通过策略来影响路由的学习;

比如:AR1连接AR2,AR1上有三个路由,正常来说AR2会将这3个路由都学习,但是我们现在通过策略调整让AR2只允许学习其中的一条,将另外两条干掉;这个过程就叫做路由策略;

2:策略路由:策略路由是通过策略来影响路由;数据层面

理解:策略路由是通过策略来影响路由,意思是我们路由原本让我走A,但是我不想走A,我通过策略让它走B或者走C;

比如:路由原本是从0/0/1口出去的,现在通过策略要求它从0/0/2口出去;

路由策略实施:

在做路由策略时分为两步:

1.抓取路由,使用路由抓取工具:ACL,前缀列表(prefix-list);

2.对路由属性进行调整,实施策略工具:fitter-policy,router-policy;

1.ACL工具:

ACL不能精确匹配路由的掩码(不能抓取路由的掩码),不能进行大范围的路由抓取;当需要进行抓取大量路由时,ACL就不适用;

ACL可以抓数据,也可以抓路由;
因为ACL既能抓路由,又能抓流量,所以ACL可以单独使用,即直接在接口上调用;

ACL配置:
[r3]acl 2000    
[r3-acl-basic-2000]rule permit source 1.1.1.0 0 

2.前缀列表(prefix-list)

特点:1:前缀列表只能抓路由,不能抓数据;2:能严格匹配网络掩码(以及可以范围性匹配掩码);3:存在序列号,从小到大匹配,一经匹配立即执行;4:末尾隐含拒绝所有;

注意:

前缀列表不能单独使用,在使用时必须依靠高级列表;
在前缀列表中默认的步数为10,即第一条序列号为10,第二条为20  ..........

配置:
[r3]ip ip-prefix ?    	-----前缀列表的名称
  STRING<1-169>  Specify prefix-list name
[r3]ip ip-prefix c1 ?	----定义动作,具体是由实际场景决定的
  deny    Specify a deny rule
  index   Set the sequence number of this entry for IP prefix-list
  permit  Specify a permit rule
[r3]ip ip-prefix c1 permit 2.2.2.0 24 greater-equal 24 less-equal 24

2.2.2.0 24  -----2.2.2.0 是网络号, 24代表的是不变位,代表前24位是不变的;

greater-equal 24 less-equal 24  ----表示掩码,网络掩码是由该参数决定的;

greater-equal   -----表示>=;
less-equal      -----表示<=;


注意:1.如果greater-equal和less-equal 都写了,列如:
[r3]ip ip-prefix c1 permit 2.2.2.0 24 greater-equal 24 less-equal 26;
表示匹配网络号为2.2.2.0,掩码为24/25/26的路由;
     2.如果只有greater-equal,列如:
[r3]ip ip-prefix c1 permit 2.2.2.0 24 greater-equal 26;
表示匹配网络号为2.2.2.0,掩码为26/27/28/29/30/31/32的路由;
	 3.如果只有less-equal,列如:
[r3]ip ip-prefix c1 permit 2.2.2.0 24  less-equal 26;	
表示匹配网络号为2.2.2.0 ,掩码为24/25/26的路由;
	 4.如果两个参数都没有,列如:
[r3]ip ip-prefix c1 permit 2.2.2.0 24 ;
表示匹配网络号为2.2.2.0,掩码为24的路由;

3.过滤列表(fitter-policy)


fitter-policy:过滤策略列表,进行路由信息的过滤;只针对路由信息进行过滤;

fitter-policy只能对路由进行过滤,不能对路由的属性进行调整;

fitter-policy可以在两个地方使用:1.在同种路由协议之间使用;2.在不同路由协议之间使用,不同路由协议使用是指在重发布的过程中来调用;

注意:fitter-policy列表自身没有过滤功能,只能通过调用低级列表(ACL,prefix-list)来进行过滤;

fitter-policy的特点:
1.自身不具备过滤功能;
2.可以在同种路由协议之间使用或不同路由协议之间使用(重发布)过程中使用;
3.同种路由协议之间分为距离矢量型(可以在出和入两个方向实施)和链路状态型(仅仅在路由学习的入方向使用,并且不是过滤LSA只是阻止LSA加表;  在华为设备中可以在出方向上针对5类和7类LSA进行过滤);
4.在不同协议之间使用时,必须为:export + A协议(需要被重发布的协议);
(1):在距离矢量型路由协议之间做(RIP):

在上图中,AR1上有几条环回路由,我们通过使用fitter-policy来控制向AR2传递的路由:

1.在路由的出方向上做(AR1):

[r1]ip ip-prefix ccie deny 0.0.0.0 0 greater-equal 32    ---因为是过滤路由,所以这里是deny;这条表示过滤主机路由;
[r1]ip ip-prefix ccie deny 192.0.0.0 3 greater-equal 24 less-equal 24
[r1]ip ip-prefix ccie permit 0.0.0.0 0 less-equal 32  ---在末尾必须放通所有,因为前缀列表末尾隐含拒绝所有;这条表示允许所有;
[r1]rip 100			---进入对应的路由协议
[r1-rip-100]filter-policy ?
  INTEGER<2000-2999>  Apply basic ACL
  acl-name            Specify IP Access Control List (ACL) name for filtering   
                      routes
  gateway             Filter routes based on the distributing gateway
  ip-prefix           Specify IP prefix for filtering routes
[r1-rip-100]filter-policy ip-prefix ccie ?   ---选择在那个方向上调用(出/入); 
  export   Specify an export policy
  gateway  Filter routes based on the distributing gateway
  import   Specify an import policy
[r1-rip-100]filter-policy ip-prefix ccie export GigabitEthernet 0/0/0  ----选择在该路由器具体的那个接口上调用,如果不写将在该路由器所有接口上调用;

在AR2上查看RIP路由表,会发现1.1.2.1/32 和192.168.1.1/24 两条路由被过滤:

2.在路由的入方向上做(AR2):

[r2]ip ip-prefix ccie deny 0.0.0.0 0	---过滤缺省
[r2]ip ip-prefix ccie deny 1.1.1.0 24
[r2]ip ip-prefix ccie permit 0.0.0.0 0 less-equal 32  ---允许所有
[r2]rip 100
[r2-rip-100]filter-policy ip-prefix ccie ?   ----接口调用
  export   Specify an export policy
  gateway  Filter routes based on the distributing gateway
  import   Specify an import policy	
[r2-rip-100]filter-policy ip-prefix ccie import GigabitEthernet 0/0/0

(2).在链路状态型路由协议上做:

在AR3中有几个换回,我们针对环回路由的出方向和入方向进行过滤:

1.在路由的出方向上做:

在链路状态协议中,出方向上仅仅是针对5类和7类LSA进行过滤;

注意:在AR3上进行过滤时,由于AR2与AR3之间使用的是1类LSA进行路由学习的,其中包含拓扑信息,所以是不能过滤的;当lo0接口进行重发布变成5类LSA时才能过滤,因为5类LSA中不包含拓扑信息;

将lo0重发布到ospf中:[r3-ospf-100]import-route direct   ---重发布直连;


在AR3上进行过滤:
[r3]ip ip-prefix ccie deny 3.3.3.0 24
[r3]ip ip-prefix ccie permit 0.0.0.0 0 less-equal 32
[r3]ospf 100
[r3-ospf-100]filter-policy ip-prefix ccie ?
  export  Filtering outgoing routing updates
  import  Filtering incoming routing updates
[r3-ospf-100]filter-policy ip-prefix ccie export 

过滤之后再到AR2上查看路由,发现已经没有3.3.3.0/24这条路由:
[r2]dis ip ro p o
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 1        Routes : 1        

OSPF routing table status : <Active>
         Destinations : 1        Routes : 1

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        3.3.4.0/24  OSPF    10   1           D   23.1.1.2        GigabitEthernet
0/0/1

注意:在链路状态协议(OSPF)中,在出方向上不能针对1类和2类LSA进行过滤,但是针对3类LSA,5类LSA,7类LSA可以进行过滤;

2.在路由的入方向上做:

针对1类和2类LSA在入方向上可以使用fitter-policy,但是这条LSA并不是真正的被过滤了,只是阻止该LSA加表;该条LSA可以正常的传给其他路由器;

[r2]ip ip-prefix hcie deny 3.3.3.0 24
[r2]ip ip-prefix hcie permit 0.0.0.0 0 less-equal 32
[r2]ospf 100	
[r2-ospf-100]filter-policy ip-prefix hcie ?
  export  Filtering outgoing routing updates
  import  Filtering incoming routing updates
[r2-ospf-100]filter-policy ip-prefix hcie import   ----入方向调用
3.在不同协议之间使用(重发布):

如上图:我们将RIP与OSPF相互重发布,我们在AR2上使用fitter-policy让AR1不能学习到AR3的lo0接口的路由;

配置:
[r2]ip ip-prefix hcie deny 3.3.3.0 24
[r2]ip ip-prefix hcie permit 0.0.0.0 0 less-equal 32
[r2]rip 100
[r2-rip-100]filter-policy ip-prefix hcie ?
  export   Specify an export policy
  gateway  Filter routes based on the distributing gateway
  import   Specify an import policy
[r2-rip-100]filter-policy ip-prefix hcie export ospf 100

注意:当我们需要将B协议重发布到A协议中的路由进行过滤时,我们需要进入A协议进行配置;

4.路由策略列表(route-policy)

在思科中该列表叫做:route-map;

route-policy只能在3种情况中使用: 1.重发布 ; 2.BGP ;3.PBR(QOS,在数据层面对路由进行控制,可以让数据的转发不看路由表)

特点:
1.自身具有过滤功能;
2.序列号由小及大匹配;
3.可以过滤路由或者改变路由的属性;
4.末尾隐含拒绝所有
5.每一个条目中包含逻辑语句(if-match   apply;)

注意:
条目中的逻辑语句为:
if-match 匹配路由 apply  执行动作;
列如:
if-match ACL 2000 apply cost=10   ---表示匹配ACL200的路由并将其cost值变为10;

在if-match中有两种匹配方式:横向(any任意)和竖向(all所有):
(1):横向
if-match ACL 2000 2001 2002 2003 apply cost=99 OE2  ---表示匹配acl 2000 2001 2002 2003 中任意路由,并将其cost值变为99,类型变为2;
(2):竖向
if-match ACL2000 cost5 OE2 apply TAG 999 OE1  ---表示匹配ACL200中的并且cost为5,类型为2的路由,将该路由打上TAG标记,类型变为1;

注意:不同类的条件只能是竖向的,同类的条件也只能是横向的;

如上图,在重发布的过程中使用,我们针对AR3 的几个环回路由进行改变:

要求:
1.将3.3.1.0 ---类型变为OE1;
2.将3.3.2.0 ---开销值变为 100;
3.将3.3.3.0 ---进行过滤;
4.将3.3.4.0 ---tag标记变为 8888;
5.将23.1.1.0 ---正常允许通过;
配置:
[r2]ip ip-prefix b1 permit 3.3.1.0 24    ---先使用prefix-list工具抓取路由;
[r2]ip ip-prefix b2 permit 3.3.2.0 24
[r2]ip ip-prefix b3 permit 3.3.3.0 24
[r2]ip ip-prefix b4 permit 3.3.4.0 24
[r2]route-policy hhp ?					---创建路由策略表,并命名为hhp
  deny    Specify a deny rule
  permit  Specify a permit rule
[r2]route-policy hhp permit ?			---表示动作(拒绝/允许)
  node  Node of the route policy
[r2]route-policy hhp permit node 10 	---第一条node(编号)为10;	
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix b1		---进行匹配
[r2-route-policy]apply cost-type ?
  external  IS-IS external metric
  internal  IS-IS internal metric/Set BGP MED to IGP metric of nexthop
  type-1    OSPF External Type 1 routes
  type-2    OSPF External Type 2 routes
[r2-route-policy]apply cost-type type-1		---执行动作
[r2-route-policy]q
[r2]route-policy hhp permit node 20
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix b2
[r2-route-policy]apply cost 100
[r2-route-policy]q
[r2]route-policy hhp deny node 30
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix b3
[r2-route-policy]q
[r2]route-policy hhp permit node 40
Info: New Sequence of this List.
[r2-route-policy]if-match  ip-prefix b4
[r2-route-policy]apply tag 8888
[r2-route-policy]q
[r2]route-policy hhp permit node 50		---因为route-policy末尾隐含拒绝所有,所以我们要放通所有
Info: New Sequence of this List.
[r2-route-policy]q
[r2]ospf 200
[r2-ospf-200]import-route ospf 100 route-policy hhp		---最后进行重发布的过程中调用路由策略列表hhp;

  • 8
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值