HCIP之BGP的选路原则

目录

HCIP之BGP的选路原则

实验

R1基本配置

R2基本配置

R3基本配置

R4基本配置

R5基本配置

ospf区域配置

AS1区域配置

AS2区域配置

 BGP选路的原则

 1.优选PV值最大的路由

        修改PV影响选路的配置:

2.优选LP属性值最大的路由

        通过修改LP值来影响选路

3.自己始发的路由

4.优选AS_PATH属性最短的路由

        AS_PATH属性进行选路时,需要注意的两点:

        干涉选路的方法

5.优选起源码属性最优的路由。

        控制选路的方法

6.优选MED属性值较小的路由

        干涉选路的方法

7.EBGP对等体路由优于IBGP对等体


HCIP之BGP的选路原则

        BGP的选路原则 --- 前提 --- 丢弃所有不可用的路由系信息

实验

R1基本配置

[R1]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              12.0.0.1/24          up         up        
GigabitEthernet0/0/1              13.0.0.1/24          up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         1.1.1.1/24           up         up(s)     
NULL0                             unassigned           up         up(s)     
[R1]

R2基本配置

[R2]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              12.0.0.2/24          up         up        
GigabitEthernet0/0/1              24.0.0.1/24          up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         2.2.2.2/24           up         up(s)     
NULL0                             unassigned           up         up(s)     
[R2]

R3基本配置

[R3]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              13.0.0.2/24          up         up        
GigabitEthernet0/0/1              34.0.0.1/24          up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         3.3.3.3/24           up         up(s)     
NULL0                             unassigned           up         up(s)     
[R3]

R4基本配置

[R4]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 0
The number of interface that is UP in Protocol is 5
The number of interface that is DOWN in Protocol is 0

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              24.0.0.2/24          up         up        
GigabitEthernet0/0/1              34.0.0.2/24          up         up        
GigabitEthernet0/0/2              45.0.0.1/24          up         up        
LoopBack0                         4.4.4.4/24           up         up(s)     
NULL0                             unassigned           up         up(s)     
[R4]\

R5基本配置

[R5]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              45.0.0.2/24          up         up        
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         5.5.5.5/24           up         up(s)     
NULL0                             unassigned           up         up(s)     
[R5]

ospf区域配置

R2

[R2]display ip routing-table protocol ospf 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 3        Routes : 3        

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

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        3.3.3.3/32  OSPF    10   2           D   24.0.0.2        GigabitEthernet
0/0/1
        4.4.4.4/32  OSPF    10   1           D   24.0.0.2        GigabitEthernet
0/0/1
       34.0.0.0/24  OSPF    10   2           D   24.0.0.2        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

[R2]

R3

[R3]display ip routing-table protocol ospf 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 3        Routes : 3        

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

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.2/32  OSPF    10   2           D   34.0.0.2        GigabitEthernet
0/0/1
        4.4.4.4/32  OSPF    10   1           D   34.0.0.2        GigabitEthernet
0/0/1
       24.0.0.0/24  OSPF    10   2           D   34.0.0.2        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

[R3]

R4

[R4]display ip routing-table protocol ospf 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
         Destinations : 2        Routes : 2        

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

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        2.2.2.2/32  OSPF    10   1           D   24.0.0.1        GigabitEthernet
0/0/0
        3.3.3.3/32  OSPF    10   1           D   34.0.0.1        GigabitEthernet
0/0/1

OSPF routing table status : <Inactive>
         Destinations : 0        Routes : 0

[R4]

AS1区域配置

R1

[R1-bgp]display bgp routing-table 

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   1.1.1.0/24         0.0.0.0         0                     0      i

[R1-bgp]display bgp peer 

 BGP local router ID : 1.1.1.1
 Local AS number : 1
 Total number of peers : 2		  Peers in established state : 2

  Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State Pre
fRcv

  12.0.0.2        4           2       22       24     0 00:20:04 Established    
   0
  13.0.0.2        4           2       21       23     0 00:19:59 Established    
   0
[R1-bgp]

AS2区域配置

R2

[R2]display bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   1.1.1.0/24         12.0.0.1        0                     0      1i

[R2]display bgp peer 

 BGP local router ID : 2.2.2.2
 Local AS number : 2
 Total number of peers : 2		  Peers in established state : 2

  Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State Pre
fRcv

  4.4.4.4         4           2       14       21     0 00:12:02 Established    
   0
  12.0.0.1        4           1       23       22     0 00:20:50 Established    
   1
[R2]

R3

[R3]display bgp peer 

 BGP local router ID : 3.3.3.3
 Local AS number : 2
 Total number of peers : 2		  Peers in established state : 2

  Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State Pre
fRcv

  4.4.4.4         4           2       14       22     0 00:12:02 Established    
   0
  13.0.0.1        4           1       24       23     0 00:21:17 Established    
   1

[R3]display bgp routing-table 

 BGP Local router ID is 3.3.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   1.1.1.0/24         13.0.0.1        0                     0      1i
[R3]

R4

[R4]display bgp routing-table 

 BGP Local router ID is 4.4.4.4 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 2
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.0/24         2.2.2.2         0          100        0      1i
 * i                     3.3.3.3         0          100        0      1i

[R4]display bgp peer 

 BGP local router ID : 4.4.4.4
 Local AS number : 2
 Total number of peers : 3		  Peers in established state : 3

  Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State Pre
fRcv

  2.2.2.2         4           2       17       15     0 00:13:18 Established    
   1
  3.3.3.3         4           2       16       14     0 00:12:46 Established    
   1
  45.0.0.2        4           3       23       25     0 00:21:52 Established    
   0

 BGP选路的原则

属性名

传播范围默认值评判标准
PV不传播0(0-65535)越大越优
LPIBGP对等体之间100越大越优
AS_PATHBGP对等体之间记录数量越少越优
OGNbgp对等体之间根据起源类型决定I>e>?
MEDbgp对等体之间默认继承全局路由表中的开销值越小越优

 1.优选PV值最大的路由

        PV值是华为的私有属性,可以理解为是权重,数值越大,其优先级越高,又因为他是所有选路原则中的第一条原则,所以,该属性是本设备上选路最方便的一个属性。 --- 这个属性只能在本设备上生效,他无法传递给任何BGP对等体。

修改PV影响选路的配置:

        方法一 --- 全局修改

[R4-bgp]peer 3.3.3.3 preferred-value ?
  INTEGER<0-65535>  Preference value
[R4-bgp]peer 3.3.3.3 preferred-value 100

AS-path 1, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for PreVal

负载分担 --- 即让不同的流量走不同的线路,分担单一线路的压力

        方法二 --- 精细化控制

                1.抓取流量

[R4]ip ip-prefix PV permit 10.0.0.0 24

                2.做路由策略

[R4]route-policy PV permit node 10
Info: New Sequence of this List.
[R4-route-policy]if-match ip-prefix pv
[R4-route-policy]apply preferred-value 100
[R4-route-policy]q
[R4]route-policy PV permit node 20 --- 配置空列表放通剩余所有流量
Info: New Sequence of this List.
[R4-route-policy]q

注意:

        必须要配置空列表放通剩余所有流量

        3.在BGP中调用路由策略

[r4-bgp]peer 3.3.3.3 route-policy PV import

2.优选LP属性值最大的路由

        LP --- 本地优先级 --- 默认值为100,越大越优。这个属性可以再IBGP对等体之间进行传递,所以,他是AS内部选路最常用的属性。路由信息在传递给EBGP对等体时将不携带这个属性

通过修改LP值来影响选路

        方法一 --- 全局修改

[R3-bgp]default local-preference 200

        方法二 --- 精细化控制

                在R3的出方向做

                1.抓取路由

[r3]ip ip-prefix lp permit 10.0.0.0 24

                2.做路由策略

[r3]route-policy lp permit node 10
Info: New Sequence of this List.
[r3-route-policy]if-match ip-prefix lp
[r3-route-policy]apply local-preference 300
[r3-route-policy]q
[r3]route-policy lp permit node 20
Info: New Sequence of this List.
[r3-route-policy]q

                3.在BGP进程中调用

[r3-bgp]peer 4.4.4.4 route-policy lp export

3.自己始发的路由

       自己始发的路由优先级高于对等体处学来的,自己始发的方法也存在多种,他们的优先级关系为手工聚合>自动聚合>network>import

4.优选AS_PATH属性最短的路由

        AS_PATH属性进行选路时,需要注意的两点:

        1.我们在进行路由聚合时,如果激活AS_SET关键字之后,将不同AS的明细路由进行聚合,则我们将AS_PATH属性中携带所有明细AS的AS号,并用大括号括起来。在进行选路比较时,大括号的内容当做一个AS号来看待。

        2.在联邦时,我们联邦内部也需要使用AS_PATH来进行防环,我们使用小括号将AS号括起来,在进行选路比较时,将不计算小圆括号里的内容。

干涉选路的方法

        在R1的出方向修改AS_PATH属性

        1.抓取路由

[r1]ip ip-prefix as permit 10.0.0.0 24

        2.配置路由策略

[r1]route-policy as permit node 10
Info: New Sequence of this List.
[r1-route-policy]if-match ip-prefix as
[R1-route-policy]apply as-path 11 22 33 ?
  INTEGER<1-4294967295>  AS number in asplain format (number<1-4294967295>)
  STRING<3-11>           AS number in asdot format                              
                         (number<1-65535>.number<0-65535>)
  additive               Append to original As Number
  overwrite              Overwrite original As Number

[R1-route-policy]apply as-path 11 22 33 additive 
[R1]route-policy as permit node 20
Info: New Sequence of this List.

解析:

        additive               Append to original As Number --- 在原有AS_PATH属性的基础上添加配置的AS号

        overwrite              Overwrite original As Number --- 直接覆盖原有的AS_PATH属性值

        [R1-route-policy]apply as-path 11 22 33 additive  --- 建议使用添加,因为AS_PATH属性主要任务用来防止环路,将原有属性覆盖可能导致路由回传,造成环路产生

        3.在BGP中调用策略

[R1-bgp]peer 12.0.0.2 route-policy as export 
[r2-route-policy]apply as-path 1 1 1 additive --- 建议在AS_PATH属性中添加真实离开的AS的AS号,因为AS_PATH属性本身具有防环作用,添加AS号后可能导致路由无法发送到对应的AS当中,影响陆游的传递。AS_PATH属性在进行选路时,仅关注AS号的长短,不关注内容。

5.优选起源码属性最优的路由。

        起源码的优先级 --- I>E>?

        OGN --- 起源码 --- I,e,?--- 用来表示路由条目的起源

                I --- 代表该路由信息起源于IGP协议(不局限于IGP协议,包括静态,直连),代表该路由条目起源于AS内部 --- 通过network发不出来的路由信息起源码为I

                E --- 代表该路由信息起源于EGP协议 --- EGP指的是BGP之前使用的外部网关协议

                ?--- 通过除了以上两种方式学习到的路由 --- 重发布导入的路由起源码都是 ?

控制选路的方法

        1.抓取路由

[r2]ip ip-prefix ogn permit 10.0.0.0 24
        2.配置路由策略
[r2]route-policy ogn permit node 10
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix ogn
[r2-route-policy]apply origin ?
egp Remote EGP
igp Local IGP
incomplete Unknown heritage
[r2-route-policy]apply origin incomplete 
[r2-route-policy]q
[r2]route-policy ogn permit node 20
Info: New Sequence of this List.
[r2-route-policy]q

        3.在BGP中进行调用

[r2-bgp]peer 12.0.0.1 route-policy ogn import

6.优选MED属性值较小的路由

        MED --- 多出口鉴别属性 --- MED值默认初始值并不是0,而是继承了路由表中该路由条目的开销值,所以,他可以反应到达目标网段在本AS内部的开销值大小,通过这个参数,别的AS的流量在进入本AS时将可以选择开销值较小的入口进入。通过修改这个属性值,我们也可以影响其他AS的流量流入本AS的路径。若本地通过IBGP毒地鞥提学习到一条BGP路由,其中存在MED值,之后需要将这条路由再传递给本地的EBGP对等体,则他将不再携带这个MED值,这种设置将有可能造成选路不佳的情况。所以,讲义,如果存在多边界设备需要将路由发送给EBGP对等体关系时,需要将所有的路由信息都发布。(每台设备都需要发布)

干涉选路的方法

        在R2配置,影响R1的选路

        1.抓取路由

[r2]ip ip-prefix med permit 4.4.4.0 24

        2.配置路由策略

[r2]route-policy med permit node 10
Info: New Sequence of this List.
[r2-route-policy]if-match ip-prefix med
[r2-route-policy]apply cost 10
[r2-route-policy]q
[r2]route-policy med permit node 20
Info: New Sequence of this List.
[r2-route-policy]q

        3.在BGP进程中调用

[r2-bgp]peer 12.0.0.1 route-policy med export

注意:

        MED值影响的是别的AS的流量通过多个出口进入到本AS内部,如果流入的不是同一个AS,即收到的路由条目中AS_PATH属性最左边的AS号不同,则将不比较第六条,直接比较第七条

        [r4]ping -r -a 4.4.4.4 1.1.1.1 --- 可以记录流量流过的全过程

7.EBGP对等体路由优于IBGP对等体

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

White乄joker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值