LOCAL_PRAF属性(以下简称LP)和MULTI_EXIT_DISC属性(以下简称MED)
查看BGP 路由表
LP属性被用于在去往同一目的地的多条路由中设置路由优先级,从名字就可以看出,LP属性只是应用于本地对等体之间,即,只能在IBGP对等体之间传递,不会应用于EBGP对等体之间。LP属性常用于AS出口出方向流量的路径控制,LP属性值越大,路由越优。
通常情况下,MED属性的作用是在去往邻居AS存在多条链路时,允许AS为入站流量传达其优先级。(一般来说,比较不同AS的MED属性没有太大意义,特殊场景除外。)从MED属性的作用可以看出,MED属性只是作用于EBGP对等体,而IBGP对等体互相通告路由时,会忽略MED属性。MED属性常用于AS出口入方向流量的路径控制,MED属性值越小,路由越优。
以下是华为专题的例子说明
这里要求R4去往1.1.1.0/24 走 R2、去往2.2.2.0/24 走R3
R2的配置
bgp 1
peer 10.1.1.1 as-number 2
peer 10.3.1.2 as-number 1
#
ipv4-family unicast
undo synchronization
peer 10.1.1.1 enable
peer 10.3.1.2 enable
peer 10.3.1.2 route-policy LP export /对R4出方向使用路由策略LP
peer 10.3.1.2 next-hop-local
#
route-policy LP permit node 5 /设置路由策略LP,如果匹配前缀LP,则LP置为200
if-match ip-prefix LP
apply local-preference 200
#
route-policy LP permit node 10
#
ip ip-prefix LP index 10 permit 1.1.1.0 24 /配置前缀列表LP,匹配1.1.1.0/24
#
R3的配置
bgp 1
peer 10.2.1.1 as-number 2
peer 10.4.1.2 as-number 1
#
ipv4-family unicast
undo synchronization
peer 10.2.1.1 enable
peer 10.4.1.2 enable
peer 10.4.1.2 route-policy LP export /对R4出方向使用路由策略LP
peer 10.4.1.2 next-hop-local
#
route-policy LP permit node 5 /设置路由策略LP,如果匹配前缀LP,则LP置为200
if-match ip-prefix LP
apply local-preference 200
#
route-policy LP permit node 10
#
ip ip-prefix LP index 10 permit 2.2.2.0 24 /配置前缀列表LP,匹配2.2.2.0/24
#
可以看到,在R4上,去到1.1.1.0/24网段有两条路由,但是下一跳为R2的路由的LP属性为200,而下一跳为R3的路由的LP属性为100,所以优选R2进行转发。去到2.2.2.0/24网段的路由同理。
我们对上面的例子稍作修改,在R4上也发布两条路由3.3.3.0/24和4.4.4.0/24。如图:
R2新增配置:
#
bgp 1
#
ipv4-family unicast
peer 10.1.1.1 route-policy MED export /对R1出方向使用路由策略MED
#
route-policy MED permit node 5 /设置路由策略MED,如匹配前缀MED,则MED置为10
if-match ip-prefix MED
apply cost 10
#
route-policy MED permit node 10
#
ip ip-prefix MED index 10 permit 4.4.4.0 24 /配置前缀列表MED,匹配4.4.4.0/24
#
R3新增配置:
bgp 1
#
ipv4-family unicast
peer 10.2.1.1 route-policy MED export /对R1出方向使用路由策略MED
#
route-policy MED permit node 5 /设置路由策略MED,如匹配前缀MED,则MED置为10
if-match ip-prefix MED
apply cost 10
#
route-policy MED permit node 10
#
ip ip-prefix MED index 10 permit 3.3.3.0 24 /配置前缀列表MED,匹配3.3.3.0/24
#
可以看到去往3.3.3.0/24目的地有两条路由,下一跳为R2的路由被优选,因为其MED值较小。4.4.4.0/24的路由同理。