BGP路径属性
验证理论
路径属性的来由,作用,以及如何修改
路径属性:
任何一条BGP路由都拥有多个路径属性
当路由器将BGP路由通告给它的对等体时,一并被通告的还有路由所携带的各个路径属性
BGP路径属性将影响路由优选
路径属性分类:
公认必遵:所有BGP路由器都必须能够识别,必须包括在每个update消息里
Origin
AS-Path
Next-hop
公认任意:所有BGP路由器都必须能够识别,可能包括在某些update消息里
Local-preference
Atomic-aggregate
可选过渡:BGP设备不识别此类属性依然会接受该类属性并通告给其他对等体(从一个AS到另一个AS)
Aggregator
community
可选非过渡:BGP设备不识别此类属性会忽略该属性,且不会通告给其他对等体(从一个AS到另一个AS)
MED
Cluster-List
Originator-ID
实验拓扑
初始配置
建立BGP邻居,network引入10.1.1.1和10.1.4.4的路由
初始结果
[AR1]dis bgp routing-table
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.2.2 0 100i
* 150.1.3.3 0 100i
实验步骤
前言:查看BGP路径属性的命令:display bgp routing-table 10.1.4.4
[AR1]dis bgp routing-table 10.1.4.4
BGP local router ID : 10.1.1.1
Local AS number : 200
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.1.4.4/32:
From: 150.1.2.2 (150.1.2.2)
Route Duration: 00h04m48s
Relay IP Nexthop: 155.1.12.2
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 150.1.2.2
Qos information : 0x0
AS-path 100, origin igp, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 2 peers:
150.1.2.2
150.1.3.3
BGP routing table entry information of 10.1.4.4/32:
From: 150.1.3.3 (155.1.13.3)
Route Duration: 00h04m48s
Relay IP Nexthop: 155.1.13.3
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 150.1.3.3
Qos information : 0x0
AS-path 100, origin igp, pref-val 0, valid, external, pre 255, not preferred for router ID
Not advertised to any peer yet
一.验证公认必遵属性
AS-PATH :该属性为公认必遵属性,时前往目标网络的路由经过的AS号列表
作用:确保路由在EBGP对等体之间传递无环;另外也作为路由优选的衡量标准之一
路由在被通告给EBGP对等体时,路由器会在该路由的AS Path中追加上本地的AS号;路由被通告给IBGP对等体时,AS Path不会发生改变
修改AS-PATH:使用route-policy修改as-path的时候可以additive(增加),overwrite(重写),none overwirte(将已有AS Path的值清空)
通过ROUTE-POLICY增加AS-PATH:
[AR1]ip ip-prefix NET4 permit 10.1.4.4 32
[AR1]route-policy SET-AS-PATH permit node 10
[AR1-route-policy]if-match ip-prefix NET4
[AR1-route-policy]apply as-path 100 100 ?
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
[AR1-route-policy]apply as-path 101 102 additive
[AR1]route-policy SET-AS-PATH permit node 20 //注意:如果只是想要修改某一条路径的属性,千万要在策略路由最后新加一条,是因为最后是在接收或者发送的时候应用策略路由,可能防止形成路由过滤
[AR1-bgp]peer 150.1.2.2 route-policy SET-AS-PATH import
此时,因为从150.1.2.2过来的10.1.4.4所经过的path更多,所以优选从150.1.3.3过来的10.1.4.4
[AR1]dis bgp routing-table
BGP Local router ID is 10.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.3.3 0 100i
* 150.1.2.2 0 101 102 100i //注意:增加的AS号是按照输入顺序从前往后自动添加到实际的AS号的前面。而且因为添加了AS号使得从150.1.2.2过来的这个路由不会再传出去,所以也不需要考虑遭遇到EBGP防环了。当然,实际环境里面还是推荐只添加上一个AS号,反正不管添加什么都只是比较AS数量,也不会传出去
也可以通过as-path-ignore来忽略as-path对BGP选路的影响
[AR1-bgp]bestroute as-path-ignore
[AR1]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.2.2 0 101 102 100i
* 150.1.3.3 0 100i
Origin
该属性为公认必遵属性,它标识了BGP路由的起源
当去往同一个目的地存在多条不同Origin属性的路由时,在其他条件都相同的清空下,BGP将按如Origin的顺序优选路由:IGP>EGP>Incomplete //BGP认为加载的比引入的可靠
删除前面的as-path修改,利用起源属性使得AR1优选从AR3过来的4.4路由
[AR1]route-policy SET-ORI permit node 10
[AR1-route-policy]if-match ip-prefix NET4
[AR1-route-policy]apply origin ?
egp Remote EGP
igp Local IGP
incomplete Unknown heritage
[AR1-route-policy]apply origin incomplete
[AR1]route-policy SET-ORI permit node 20 //同样,因为是在路由引入的时候调用的策略路由,所以策略路由里面一定也要加上最后一条允许所有的策略,避免形成路由过来
AR1-bgp]peer 150.1.2.2 route-policy SET-ORI import
此时从150.1.2.2过来的4.4路由来源变更为?因为i>e>?所以,AR1优选从3.3学到的路由
[AR1]dis bgp routing-table
BGP Local router ID is 10.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.3.3 0 100i
* 150.1.2.2 0 100?
[AR1]
Next-Hop
该属性是一个公认必遵属性,用于指定到达目标网络的下一跳地址
当路由器学习到BGP路由后,需对BGP路由的Next Hop属性值进行检查,该属性值(IP地址)必须在本地路由可达,如果不可达,则这条BGP路由不可用
在不同的场景中,设备对BGP路由的缺省Next Hop属性值的设置规则如下:
路由器将BGP路由通告给自己的EBGP对等体时,将该路由的Next Hop设置为自己的更新源IP地址
路由器在收到EBGP对等体所通告的BGP路由后,在将路由传递给自己的BGP对等体时,会保持路由的Next Hop属性值不变
如果路由器收到某条BGP路由,该路由的Next Hop属性值与EBGP对等体(更新对象)同属一个网段,那么该条路由的NEXT HOP地址将保持不变并传递给它的BGP对等体
删除掉AR23上的next-hop-local配置
因为下一跳在IBGP邻居间传递的时候不更改,所以下一跳认为AR1的更新地址
[AR4]dis bgp routing-table
i 10.1.1.1/32 155.1.12.1 0 100 0 200i
i 155.1.13.1 0 100 0 200i
*> 10.1.4.4/32 0.0.0.0 0 0 i
next-hop-local时next-hop属性的一个应用。增加next-hop-local之后
[AR4]dis bgp routing-table
*>i 10.1.1.1/32 155.1.24.2 0 100 0 200i
i 155.1.13.1 0 100 0 200i
*> 10.1.4.4/32 0.0.0.0 0 0 i
利用route-policy更改从AR2过来的10.1.1.1下一跳为环回接口(反正底层时ISIS,AR4可以到达AR2的环回接口)
[AR2]ip ip-prefix NET1 permit 10.1.1.1 32
[AR2]route-policy SET-NEXT-HOP permit node 10
Info: New Sequence of this List.
[AR2-route-policy]if-match ip-prefix NET1
[AR2-route-policy]apply ip-address next-hop 150.1.2.2
[AR2]route-policy SET-NEXT-HOP permit node 20 //现网环境中修改属性一定记得要后面新增一个允许所有
[AR2-bgp]peer 155.1.24.4 route-policy SET-NEXT-HOP export
二.验证公认任意属性
Local-Preference 本地优先级,越大越优先
Local-Preference属性只能在IBGP对等体间传递(除非做了策略否则Local Preference值在IBGP对等体间传递过程中不会丢失),而不能在EBGP对等体间传递,如果EBGP对等体间收到的路由的路径属性中携带了Local Preference,则会进行错误处理
但是可以在AS边界路由器上使用import方向的策略来修改Local Preference属性值。也就是在收到路由之后,在本地为路由赋予Local Preference
可使用bgp default local-preference命令修改缺省Local Preference值,该值缺省为100.
路由器在向其EBGP对等体发送路由更新时,不能携带Local Preference属性,但是对方接收路由之后,会在本地为这条路由赋一个缺省Local Preference值(100),然后再将路由传递给自己的IBGP对等体
本地使用network命令及import-route命令引入的路由,Local Preference为缺省值100,并能在AS内向其他IBGP对等体传递,传递过程中除非受路由策略影响,否则Local Preference不变
10.1.1.1有本地优先级,10.1.4.4没有本地优先级。可以选择是否携带,但是只要携带了就一定能识别
利用local preference实现AS100内所有路由器要访问1.1都从3.3出去,而不从2.2出去
[AR3]ip ip-prefix NET1 permit 10.1.1.1 32
[AR3]route-policy SET-LP permit node 10
[AR3-route-policy]if-match ip-prefix NET1
[AR3-route-policy]apply local-preference 101
[AR3-bgp]peer 155.1.13.1 route-policy SET-LP import
此时AR4根据更大的本地优先级走AR3了,但是因为I到I不传,所以AR2上还是直接走的AR1
[AR4]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 10.1.1.1/32 155.1.34.3 0 101 0 200i
* i 155.1.24.2 0 100 0 200i
*> 10.1.4.4/32 0.0.0.0 0 0 i
[AR2]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 155.1.12.1 0 0 200i
*>i 10.1.4.4/32 155.1.24.4 0 100 0 i
在AR4上配置反射器,将AR2,3都配置为客户端
[AR4-bgp]peer 155.1.24.2 reflect-client
[AR4-bgp]peer 155.1.34.3 reflect-client
此时再到AR2上看,去往10.1.1.1的下一跳就变成了AR3
[AR2]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 10.1.1.1/32 155.1.34.3 0 101 0 200i
* 155.1.12.1 0 0 200i
*>i 10.1.4.4/32 155.1.24.4 0 100 0 i
Atomic-aggregate 原子聚合
AR3上配置路由聚合
[AR3-bgp]aggregate 10.1.1.0 24
[AR3]dis bgp routing-table 10.1.1.0
BGP local router ID : 155.1.13.3
Local AS number : 100
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.0/24:
Aggregated route.
Route Duration: 00h02m36s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path Nil, origin igp, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 100, Aggregator ID 155.1.13.3 //聚合者ID可以看是由谁来做的聚合
Advertised to such 2 peers:
155.1.13.1
155.1.34.4
此时没有出现原子聚合
增加detail-suppress参数之后[AR3-bgp]aggregate 10.1.1.0 24 detail-suppressed
[AR3]dis bgp routing-table 10.1.1.0
BGP local router ID : 155.1.13.3
Local AS number : 100
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.0/24:
Aggregated route.
Route Duration: 00h00m33s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path Nil, origin igp, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 100, Aggregator ID 155.1.13.3, Atomic-aggregate //出现原子聚合属性
Advertised to such 2 peers:
155.1.13.1
155.1.34.4
有了原子聚合的标记,就代表当前时抑制了所有明细的路有聚合
此时这个选项再AR2上也能被识别到-公认任意
[AR2]dis bgp routing-table 10.1.1.0
BGP local router ID : 150.1.2.2
Local AS number : 100
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.0/24:
From: 155.1.24.4 (155.1.24.4)
Route Duration: 00h02m00s
Relay IP Nexthop: 155.1.24.4
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 155.1.34.3
Qos information : 0x0
AS-path Nil, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 20
Aggregator: AS 100, Aggregator ID 155.1.13.3, Atomic-aggregate
Originator: 155.1.13.3
Cluster list: 155.1.24.4
Advertised to such 1 peers:
155.1.12.1
验证可选过渡路径属性
Aggregator
聚合者ID
在AR4后新增加AR5路由器属于AS300
[AR5]dis bgp routing-table 10.1.1.0
BGP local router ID : 155.1.45.5
Local AS number : 300
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.0/24:
From: 155.1.45.4 (155.1.24.4)
Route Duration: 00h02m01s
Direct Out-interface: GigabitEthernet0/0/2
Original nexthop: 155.1.45.4
Qos information : 0x0
AS-path 100, origin igp, pref-val 0, valid, external, best, select, active, pre 255
Aggregator: AS 100, Aggregator ID 155.1.13.3, Atomic-aggregate //聚合者ID属性带过来了
Not advertised to any peer yet
此时在EBGP邻居AR5上可以看到聚合者ID,不识别但是可以传-可选过渡
community
团体属性,作用类似与路由标记
有了community属性,我们可以为不同种类的路由打上不同的community属性值,这些属性值会随着BGP路由跟新给到EBGP邻居,那么在EBGP邻居AS内的BGP路由器上,只需要根据community属性值来执行差异化的策略即可,而不用去关心具体的路由前缀
community属性值长度为32bit,可以使用两种形式呈现:
1.十进制整数格式
2.AA:NN格式(更常用,为方便识别人们一般把AA表示为AS号,NN标识为自定义的编号)
利用团体属性实现
首先删除AR3上的路由聚合,还原拓扑
[AR1]ip ip-prefix NET1 permit 10.1.1.1 32
[AR1]route-policy SET-COM permit node 10
[AR1-route-policy]if-match ip-prefix NET1
[AR1-route-policy]apply community 200:1
[AR1-bgp]network 10.1.1.1 32 route-policy SET-COM
[AR1]dis bgp routing-table 10.1.1.1
BGP local router ID : 10.1.1.1
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.1/32:
Network route.
From: 0.0.0.0 (0.0.0.0)
Route Duration: 00h01m44s
Direct Out-interface: InLoopBack0
Original nexthop: 127.0.0.1
Qos information : 0x0
Community:<200:1> //此时AR1的路径属性上增加了community属性
AS-path Nil, origin igp, MED 0, pref-val 0, valid, local, best, select, pre 0
Advertised to such 2 peers:
150.1.2.2
150.1.3.3
[AR3]dis bgp routing-table 10.1.1.1
BGP local router ID : 155.1.13.3
Local AS number : 100
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.1/32:
From: 155.1.13.1 (10.1.1.1)
Route Duration: 00h37m29s
Relay IP Nexthop: 0.0.0.0
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 155.1.13.1
Qos information : 0x0
AS-path 200, origin igp, MED 0, localpref 101, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 1 peers:
155.1.34.4
但是此时在AR3上是没有community属性的。因为community属性虽然可以传递,但是默认时不传递的,如果希望他传递的话,需要在AR1上通告团体属性
[AR1-bgp]peer 150.1.2.2 advertise-community
[AR1-bgp]peer 150.1.3.3 advertise-community
[AR3]dis bgp routing-table 10.1.1.1
BGP local router ID : 155.1.13.3
Local AS number : 100
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.1.1.1/32:
From: 155.1.13.1 (10.1.1.1)
Route Duration: 00h00m27s
Relay IP Nexthop: 0.0.0.0
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 155.1.13.1
Qos information : 0x0
Community:<200:1> //此时团体属性已经传递给EBGP邻居了
AS-path 200, origin igp, MED 0, localpref 101, pref-val 0, valid, external, best, select, active, pre 255
Advertised to such 1 peers:
155.1.34.4
此时可以在AR3上根据团体属性进行路由抓取,修改本地优先级了
其他配置不动,只需修改策略路由如下
[AR3]ip community-filter basic TEST permit 200:1 //community-filter用来抓取community标签
[AR3]route-policy SET-LP permit node 10
[AR3-route-policy]if-match community-filter TEST
[AR3-route-policy]apply local-preference 101
完成之后效果和前面通过前缀抓取一样,但是通过标签更具有扩展性
[AR4]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 10.1.1.1/32 155.1.34.3 0 101 0 200i
*> 10.1.4.4/32 0.0.0.0 0 0 i
验证可选非传递-不识别,也不传递
Originator 本AS内是谁带进来的这个路由
Cluster list 记录经过的反射器的router id
[AR2]dis bgp routing-table
BGP Local router ID is 150.1.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 10.1.1.1/32 155.1.34.3 0 101 0 200i
* 155.1.12.1 0 0 200i
*>i 10.1.4.4/32 155.1.24.4 0 100 0 i
[AR2]dis bgp routing-table peer 155.1.12.1 advertised-routes 10.1.1.1
BGP local router ID : 150.1.2.2
Local AS number : 100
BGP routing table entry information of 10.1.1.1/32:
From: 155.1.24.4 (155.1.24.4)
Route Duration: 00h25m30s
Relay IP Nexthop: 155.1.24.4
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 155.1.34.3
Advertised nexthop: 150.1.2.2
Qos information : 0x0
AS-path 100 200, origin igp
AR2上10.1.1.1是最优的,会尝试发向AR1,但是不会携带有originator和cluster id
MED(Multi-Exit Discriminator,多出口鉴别器)是可选非过渡属性,是一种度量值,用于向外部对等体指出进入本AS的首选路径,即当进入本AS的入口有多个时,AS可以使用MED动态地影响其他AS选择进入的路径。
MED属性值越小则BGP路由越优
MED主要用于在AS之间影响BGP的选路。MED被传递给EBGP对等体后,对等体在其AS内传递路由时,携带该MED值,但将路由再此传递给其EBGP对等体时,缺省不会携带MED属性
利用前面配置好的local preference和MED实现AR4访问AR1的路径来回不一致:AR4->3->1->2->4
[AR3]ip ip-prefix NET4 permit 10.1.4.4 32
[AR3]route-policy SET-MED permit node 10
[AR3-route-policy]if-match ip-prefix NET4
[AR3-route-policy]apply cost 10
[AR3]route-policy SET-LP permit node 20
Info: New Sequence of this List.
[AR3-bgp]peer 155.1.13.1 route-policy SET-LP export
[AR2]IP ip-prefix NET4 permit 10.1.4.4 32
[AR2]route-policy SET-MED permit node 10
Info: New Sequence of this List.
[AR2-route-policy]if-match ip-prefix NET4
[AR2-route-policy]apply cost 5
[AR2]route-policy SET-MED permit node 20
[AR2-bgp]peer 155.1.12.1 route-policy SET-MED export
配置完成后,AR1仍然优选AR3,且AR3的med值完全不显示
[AR1]dis bgp routing-table
BGP Local router ID is 10.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.3.3 0 100i
* 150.1.2.2 5 0 100?
然后删除掉AR1上之前更改起源属性的配置后正常
[AR1-bgp]undo peer 150.1.2.2 route-policy SET-ORI import
[AR1]dis bgp routing-table
BGP Local router ID is 10.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: 3
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.1/32 0.0.0.0 0 0 i
*> 10.1.4.4/32 150.1.2.2 5 0 100i
* 150.1.3.3 10 0 100i
此时结果为:
[AR1]tracert -a 10.1.1.1 10
1 155.1.12.2 40 ms 40 ms 20 ms
2 155.1.24.4 30 ms 30 ms 30 ms
[AR4]tracert -a 10.1.4.4 10.1.1.1
1 155.1.34.3 20 ms 20 ms 20 ms
2 155.1.13.1 30 ms 20 ms 20 ms
注意:
缺省情况下,路由器只比较来自同一相邻AS的BGP路由的MED值,也就是说如果去往同一个目的地的两条路由来自不同的相邻AS,则不进行MED值的比较。
一台BGP路由器将路由通告给EBGP对等体时,是否携带MED属性,需要根据以下条件进行判断(不对EBGP对等体使用策略的情况下):
如果该BGP路由是本地始发(本地通过network或import-route命令引入)的,则缺省携带MED属性发送给EBGP对等体
如果该BGP路由为从BGP对等体学习到,那么该路由传递给EBGP对等体时缺省不会携带MED属性
在IBGP对等体之间传递路由时,MED值会被保留并传递,除非部署了策略,否则MED值在传递过程中不发生改变也不会丢失