prefVal:华为私有,仅在本地有意义,不会更新给邻居,不能用于export方向。prefval的值默认是0,越大越优先。它的作用是用来影响自己的出站流量的,需要针对路由注入方向的邻居来做策略。有两种做策略的方法:

A. 针对一个邻居完全的修改,从该邻居更新来的,都更改,此时不需要方向,该邻居通告的路由,都会应用这个首选值。
B.明细的修改,调用route-policy,些时需要方向,只能是import方向。

实验一:使用pref-val来影响选路,针对一个邻居发送过来的路由,全部应用一个较大的Pref-val,以获得优选。我们在R4上使用pref-val来实验选路,让它走R3去往AS100 在通告完路由以后,R4默认的BGP表如下,可以看到,因为R2有较小的router-id.所以R4优选R2做为下一跳去往R1通告的三条路由。

<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: 8
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.0/24         2.2.2.2         0          100        0      100i
 *  i                           3.3.3.3         0          100        0      100i
 *>   5.5.5.0/24         45.1.1.5        0                     0      300i
 *>i  10.1.1.0/24        2.2.2.2         0          100        0      100i
 * i                             3.3.3.3         0          100        0      100i
 *>   44.44.44.0/24      0.0.0.0         0                     0      i
 *>i  100.1.1.0/24       2.2.2.2         0          100        0      100i
 * i                             3.3.3.3         0          100        0      100i
<R4>display bgp routing-table 1.1.1.0 255.255.255.0

 BGP local router ID : 4.4.4.4
 Local AS number : 200
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 1.1.1.0/24:
 From: 2.2.2.2 (2.2.2.2)
 Route Duration: 01h07m21s  
 Relay IP Nexthop: 24.1.1.2
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 2.2.2.2
 Qos information : 0x0
 AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 1
 Advertised to such 1 peers:
    45.1.1.5
 BGP routing table entry information of 1.1.1.0/24:
 From: 3.3.3.3 (3.3.3.3)
 Route Duration: 01h07m21s  
 Relay IP Nexthop: 34.1.1.3
 Relay IP Out-Interface: GigabitEthernet0/0/1
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for router ID
 Not advertised to any peer yet

现在,针对R4做设置,让其去往1.1.1.0/24 10.1.1.0/24 100.1.1.0/24走R3

[R4-bgp]peer 3.3.3.3 preferred-value 100

在R4上查看BGP表以及针对1.1.1.0/24的路由,为什么优选R3做为出口

[R4-bgp]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: 8
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.0/24         3.3.3.3         0          100        100    100i
 * i                            2.2.2.2         0          100          0      100i
 *>   5.5.5.0/24        45.1.1.5        0                         0      300i
 *>i  10.1.1.0/24       3.3.3.3         0          100        100    100i
 * i                             2.2.2.2         0          100        0      100i
 *>   44.44.44.0/24      0.0.0.0         0                       0           i
 *>i  100.1.1.0/24       3.3.3.3         0          100        100    100i
 * i                              2.2.2.2         0          100         0      100i
[R4-bgp]display bgp routing 1.1.1.0 255.255.255.0

 BGP local router ID : 4.4.4.4
 Local AS number : 200
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 1.1.1.0/24:
 From: 3.3.3.3 (3.3.3.3)
 Route Duration: 00h00m27s  
 Relay IP Nexthop: 34.1.1.3
 Relay IP Out-Interface: GigabitEthernet0/0/1
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 100, origin igp, MED 0, localpref 100, pref-val 100, valid, internal, best, select, active, pre 255, IGP cost 1
 Advertised to such 1 peers:
    45.1.1.5
 BGP routing table entry information of 1.1.1.0/24:
 From: 2.2.2.2 (2.2.2.2)
 Route Duration: 01h11m56s  
 Relay IP Nexthop: 24.1.1.2
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 2.2.2.2
 Qos information : 0x0
 AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 1, not preferred for PreVal(R4去往1.1.1.0/24的路由,没有走R2 2.2.2.2是因为首选值不是最优的)
 Not advertised to any peer yet

实验二: 让R4通过协议首选值来选择R3做为下一跳,而去往10.1.1.0/24和100.1.1.0/24保持默认。 首先,我们将实验一中的这条命令去掉:[R4-bgp] undo peer 3.3.3.3 preferred-value 针对特定路由使用Pref-val来做选路,需要调用Route-map来实验

R4:
acl number 2000  
 rule 10 permit source 1.1.1.0 0 

route-policy pref permit node 10          
 if-match acl 2000 
 apply preferred-value 123
#
route-policy pref permit node 20

bgp 200
peer 3.3.3.3 route-policy pref import
[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: 8
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  1.1.1.0/24         3.3.3.3         0          100        123    100i
 * i                            2.2.2.2         0          100        0      100i
 *>   5.5.5.0/24         45.1.1.5        0                     0      300i
 *>i  10.1.1.0/24        2.2.2.2         0          100        0      100i
 * i                             3.3.3.3         0          100        0      100i
 *>   44.44.44.0/24      0.0.0.0         0                     0      i
 *>i  100.1.1.0/24       2.2.2.2         0          100        0      100i
 * i                              3.3.3.3         0          100        0      100i

现在,我们看到R4去往1.1.1.0/24的路由,选择了R3做为下一跳,因为对R3设置了PrefVal为123,高于R2的PrefVal 0. 而针对10.1.1.0/24和100.1.1.10/24并没有应用route-policy,所以其prefval保持默认的值,为0. R4去往这两条路由,依旧选择R2做为下一跳。