BGP的路由属性-------Preferred Value

       在BGP路由表中,到达同一目的地可能存在多条路由。此时BGP会选择其中一条路由作为最佳路由,并只把此路由发送给其对等体。BGP为了选出最佳路由,会根据BGP的路由优选规则依次比较这些路由的BGP属性。

一、BGP属性

路由属性是对路由的特定描述,所有的BGP路由属性都可以分为以下4类,常见BGP属性类型。

  1. 公认必须遵循(Well-known mandatory):所有BGP设备都可以识别此类属性,且必须存在于Update报文中。如果缺少这类属性,路由信息就会出错。
  2. 公认任意(Well-known discretionary):所有BGP设备都可以识别此类属性,但不要求必须存在于Update报文中,即就算缺少这类属性,路由信息也不会出错。
  3. 可选过渡(Optional transitive):在AS之间具有可传递性的属性。BGP设备可以不支持此属性,但它仍然会接收这类属性,并传递给其他对等体。
  4. 可选非过渡(Optional non-transitiveBGP设备可以不识别此类属性,如果BGP设备不识别此类属性,则会被忽略该属性,且不会通告给其他对等体。
属性名类型
Origin属性公认必须遵循
AS_Path属性公认必须遵循
Next_Hop属性公认必须遵循
Local_Pref属性公认任意
MED属性可选非过渡
团体属性可选过渡
Originator_ID属性可选非过渡
Cluster_List属性可选非过渡
1.协议首选值(PrefVal)

       协议首选值(PrefVal)是华为设备的特有属性,该属性仅在本地有效,不会传递给BGP邻居。因为协议首选值是人为主动设置的,代表本地用户的意愿,因而在BGP进行选路时会优先比较协议首选值。当到达同一地址前缀有多条路由时,优先选择首选值大的路由。缺省情况下,从邻居学来的路由的初始首选值为0。

方法

使用场景

使用peer { group-name | ipv4-address | ipv6-address } preferred-value value命令。

为本机从BGP对等体(组)接收的所有路由设置一个相同的协议首选值。

使用入口路由策略,并且路由策略里配置了apply preferred-value preferred-value命令。

为本机从BGP对等体(组)接收的不同的路由设置不同的协议首选值。

说明:

当路由同时符合peerapply preferred-value命令时,apply preferred-value命令的配置优先生效。

实例:

每台设备接口和LoopBack的IP地址:

[R1]display ip interface brief 
Interface                         IP Address/Mask      Physical   Protocol
GigabitEthernet0/0/0              10.0.12.1/24         up         up  
GigabitEthernet0/0/1              10.0.13.1/24         up         up  
LoopBack0                         10.0.1.1/32          up         up(s)
LoopBack1                         10.0.11.11/32        up         up(s)
NULL0                             unassigned           up         up(s)

[R2]display ip interface brief 
Interface                         IP Address/Mask      Physical   Protocol
GigabitEthernet0/0/0              10.0.12.2/24         up         up 
GigabitEthernet0/0/1              10.0.24.2/24         up         up 
LoopBack0                         10.0.2.2/32          up         up(s)
NULL0                             unassigned           up         up(s)

[R3]display ip interface brief
Interface                         IP Address/Mask      Physical   Protocol
GigabitEthernet0/0/0              10.0.13.3/24         up         up  
GigabitEthernet0/0/1              10.0.34.3/24         up         up 
LoopBack0                         10.0.3.3/32          up         up(s) 
NULL0                             unassigned           up         up(s) 

[R4]display ip interface brief 
Interface                         IP Address/Mask      Physical   Protocol
GigabitEthernet0/0/0              10.0.24.4/24         up         up 
GigabitEthernet0/0/1              10.0.34.4/24         up         up 
LoopBack0                         10.0.4.4/32          up         up(s)
LoopBack1                         10.0.44.44/32        up         up(s)
LoopBack2                         10.0.55.55/32        up         up(s)
NULL0                             unassigned           up         up(s)

这边我采用LoopBack接口做令居关系,用OSPF协议学习路由,R1、R2、R3配置OSPF宣告网段实现互通:

注:连接到其他OSPF区域的网段不能宣告过来

[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 10.0.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 10.0.12.1 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.0.13.1 0.0.0.255

[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.12.2 0.0.0.255

[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.13.3 0.0.0.255

在R2、R3上配置静态路由指向R4的10.0.4.4作为LoopBack接口的下一跳,R4同理指向R2、R3:

[R2]ip route-static 10.0.4.4 32 10.0.24.4

[R3]ip route-static 10.0.4.4 32 10.0.34.4

[R4]ip route-static 10.0.2.2 32 10.0.24.2
[R4]ip route-static 10.0.3.3 32 10.0.34.3

这里基本的配置也是完成,配置BGP:

注:一台设备只属于一个AS

[R1]bgp 100
[R1-bgp]router-id 10.0.1.1
[R1-bgp]network 10.0.11.11 255.255.255.255
[R1-bgp]peer 10.0.2.2 as-number 100    ----建立邻居
[R1-bgp]peer 10.0.2.2 connect-interface LoopBack 0   ----指定更新源
[R1-bgp]peer 10.0.3.3 as-number 100
[R1-bgp]peer 10.0.3.3 connect-interface LoopBack 0 

[R2]bgp 100
[R2-bgp]router-id 10.0.2.2
[R2-bgp]peer 10.0.1.1 as-number 100
[R2-bgp]peer 10.0.1.1 connect-interface LoopBack 0
[R2-bgp]peer 10.0.1.1 next-hop-local       -----更改下一跳属性
[R2-bgp]peer 10.0.3.3 as-number 100
[R2-bgp]peer 10.0.3.3 connect-interface LoopBack 0
[R2-bgp]peer 10.0.3.3 next-hop-local	
[R2-bgp]peer 10.0.4.4 as-number 200
[R2-bgp]peer 10.0.4.4 connect-interface LoopBack 0
[R2-bgp]peer 10.0.4.4 ebgp-max-hop      ----修改TTL值

[R3]bgp 100
[R3-bgp]router-id 10.0.3.3
[R3-bgp]peer 10.0.1.1 as-number 100
[R3-bgp]peer 10.0.1.1 connect-interface LoopBack 0
[R3-bgp]peer 10.0.1.1 next-hop-local
[R3-bgp]peer 10.0.2.2 as-number 100
[R3-bgp]peer 10.0.2.2 connect-interface LoopBack 0
[R3-bgp]peer 10.0.2.2 next-hop-local
[R3-bgp]peer 10.0.4.4 as-number 200
[R3-bgp]peer 10.0.4.4 connect-interface LoopBack 0
[R3-bgp]peer 10.0.4.4 ebgp-max-hop 

[R4]bgp 200
[R4-bgp]router-id 10.0.4.4	
[R4-bgp]network 10.0.4.4 32
[R4-bgp]network 10.0.44.44 32
[R4-bgp]network 10.0.55.55 32
[R4-bgp]peer 10.0.2.2 as-number 100
[R4-bgp]peer 10.0.2.2 connect-interface LoopBack 0
[R4-bgp]peer 10.0.2.2 ebgp-max-hop 
[R4-bgp]peer 10.0.3.3 as-number 100
[R4-bgp]peer 10.0.3.3 connect-interface LoopBack 0
[R4-bgp]peer 10.0.3.3 ebgp-max-hop 

通过查看BGP路由表看到R1的路由都是通过R2到达目的,接下来我们通过修改‘协议首选值(PrefVal)’来更改下一跳属性。

[R1]display bgp routing-table 

 BGP Local router ID is 10.0.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: 5
      Network            NextHop      MED    LocPrf   PrefVal  Path/Ogn

 *>   10.0.11.11/32      0.0.0.0       0                0       i
 *>i  10.0.44.44/32      10.0.2.2      0      100       0       200i
 * i                     10.0.3.3      0      100       0       200i
 *>i  10.0.55.55/32      10.0.2.2      0      100       0       200i
 * i                     10.0.3.3      0      100       0       200i
------------------------------------------------------------------------------

[R1]display ip routing-table protocol bgp 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : BGP
         Destinations : 2        Routes : 2        

BGP routing table status : <Active>
         Destinations : 2        Routes : 2
Destination/Mask   Proto   Pre  Cost   Flags  NextHop     Interface

10.0.44.44/32      IBGP    255  0      RD     10.0.2.2    GigabitEthernet0/0/0
10.0.55.55/32      IBGP    255  0      RD     10.0.2.2    GigabitEthernet0/0/0

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

写一条路由策略应用到BGP中。

[R1]ip ip-prefix 1 index 10 permit 10.0.55.55 32
[R1]route-policy 1 permit node 10
Info: New Sequence of this List.
[R1-route-policy]if-match ip-prefix 1
[R1-route-policy]apply preferred-value 50
[R1-route-policy]q
[R1]route-policy 1 permit  node 20
Info: New Sequence of this List.
[R1-route-policy]q
[R1]bg	
[R1]bgp 100
[R1-bgp]peer 10.0.3.3 route-policy 1 import 

更改后的路由情况,10.0.55.55的下一跳变成10.0.3.3

[R1]display bgp routing-table 

 BGP Local router ID is 10.0.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: 5
      Network            NextHop     MED   LocPrf    PrefVal   Path/Ogn

 *>   10.0.11.11/32      0.0.0.0      0                0        i
 *>i  10.0.44.44/32      10.0.2.2     0     100        0        200i
 * i                     10.0.3.3     0     100        0        200i
 *>i  10.0.55.55/32      10.0.3.3     0     100        50       200i
 * i                     10.0.2.2     0     100        0        200i

[R1]display ip routing-table protocol bgp 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : BGP
         Destinations : 2        Routes : 2        

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

Destination/Mask  Proto   Pre  Cost   Flags  NextHop     Interface

10.0.44.44/32     IBGP    255  0       RD    10.0.2.2    GigabitEthernet0/0/0
10.0.55.55/32     IBGP    255  0       RD    10.0.3.3    GigabitEthernet0/0/1

BGP routing table status : <Inactive>
         Destinations : 0        Routes : 0
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值