BGP屬性 ASPath
AS_PATH 屬性
BGP路由的必遵屬性;
AS間防環屬性;
用於BGP路由的路徑選擇,當經過多條路徑到達莫網路的情況,會選擇經過ASpath 較少的作為最優;
順序的記錄了某條BGP路由所經過的AS資訊,每經過一個AS會在ASPath 屬性的最左邊或者說外層新增AS號;
特點:
1、BGP路由器從EBGP鄰居接收路由的時候,檢查路由的ASPATH屬性是否攜帶本地的AS,攜帶則丟棄;
2、BGP路由器傳遞路由到EBGP的時候,會再ASPATH屬性前新增本路由器的AS號;
3、BGP路由器傳遞路由到IBGP鄰居的時候,對ASPATH屬性不進行任何判斷;
ASpath 是路由選路使用的其中一個屬性,落後於preferred value(優先順序),local pref (本地優先),再次是路由的生成方式(network、import 引入、聚合路由),
如果還區分不出來就需要考慮ASpath 了;也可以理解為是排序到路由選路的第五條;
實驗圖:
說明:
1、R1 與R3 相互建立IBGP鄰居關係,R 與R5相互建立EBGP 鄰居關係;
2、R2 與R3 相互建立IBGP鄰居關係;
3、R3 與R4 相互建立EBGP鄰居關係;
4、R5 與R4 相互建立EBGP鄰居關係;
5、R1、R2、R3之間透過OSPF協議來打通相互之間的環回口之間的通訊,以便BGP透過環回口建立IBGP鄰居;
測試:
1、當路由器從EBGP鄰居接收與本機相同AS號的路由時,會丟棄掉此路由;
當R3 接收到從R6 通告的6.6.6.6/32 的時候,由於R3的AS號為100,6.6.6.6/32 的路由內也包含了AS100,所以直接丟棄掉;
檢視R3路由器的BGP路由:
[R3]dis bgp routing-table ipv4 Total number of routes: 7 BGP local router ID is 3.3.3.3 Status codes: * - valid, > - best, d - dampened, h - history, s - suppressed, S - stale, i - internal, e - external a - additional-path Origin: i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn * >i 1.1.1.1/32 1.1.1.1 0 100 0 i * >i 2.2.2.2/32 2.2.2.2 0 100 0 i * > 3.3.3.3/32 127.0.0.1 0 32768 i * >e 4.4.4.4/32 34.1.1.4 0 0 400i i 15.1.1.5 100 0 500 400i * >e 5.5.5.5/32 34.1.1.4 0 400 500i i 15.1.1.5 0 100 0 500i
當路由器R1 接收到來自R6 的1.1.1.1/32 的路由同樣的道理,也會丟棄掉;
2、路由器傳遞到EBGP鄰居的時候,會攜帶完整的AS號;
R1 接收到來自於R5 路由器通告的5.5.5.5/32 的路由時,會記錄沿途的AS號,經過500、400 後到達本地路由器的100,;
檢視R1 路由
[R1]dis bgp routing-table ipv4 Total number of routes: 6 BGP local router ID is 1.1.1.1 Status codes: * - valid, > - best, d - dampened, h - history, s - suppressed, S - stale, i - internal, e - external a - additional-path Origin: i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn * > 1.1.1.1/32 127.0.0.1 0 32768 i * >i 3.3.3.3/32 3.3.3.3 0 100 0 i * >e 4.4.4.4/32 15.1.1.5 0 500 400i i 34.1.1.4 0 100 0 400i * >e 5.5.5.5/32 15.1.1.5 0 0 500i i 34.1.1.4 100 0 400 500i
上面路由的經過AS500 直接進入到本地路由的100,或者是第二條路線,由AS500 出發,經過AS400 後再到達AS100;
3、優選路由的時候,多條路徑可到達某網路的情況,在preference 、 local pref、路由生成方式(實驗中採用network宣告)的情況下,無法選擇出最優路由,再採用ASPath 進行選路;
如:R3 路由器的路由4.4.4.4/32,由於R4 與R3直接組建的鄰居只經過一個AS,所以被優先選擇;
[R3]dis bgp routing-table ipv4 Total number of routes: 7 BGP local router ID is 3.3.3.3 Status codes: * - valid, > - best, d - dampened, h - history, s - suppressed, S - stale, i - internal, e - external a - additional-path Origin: i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn * >i 1.1.1.1/32 1.1.1.1 0 100 0 i * >i 2.2.2.2/32 2.2.2.2 0 100 0 i * > 3.3.3.3/32 127.0.0.1 0 32768 i * >e 4.4.4.4/32 34.1.1.4 0 0 400i i 15.1.1.5 100 0 500 400i * >e 5.5.5.5/32 34.1.1.4 0 400 500i i 15.1.1.5 0 100 0 500i
路由器配置:
R1:
interface LoopBack0 ip address 1.1.1.1 255.255.255.255 ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/0 port link-mode route combo enable copper ip address 13.1.1.1 255.255.255.0 ospf network-type p2p ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/7 port link-mode route combo enable copper ip address 15.1.1.1 255.255.255.0 # bgp 100 peer 3.3.3.3 as-number 100 peer 3.3.3.3 connect-interface LoopBack0 peer 15.1.1.5 as-number 500 # address-family ipv4 unicast network 1.1.1.1 255.255.255.255 peer 3.3.3.3 enable peer 15.1.1.5 enable
R2:
interface LoopBack0 ip address 2.2.2.2 255.255.255.255 ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/0 port link-mode route combo enable copper ip address 23.1.1.2 255.255.255.0 ospf network-type p2p ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/1 port link-mode route combo enable copper ospf network-type p2p ospf 1 area 0.0.0.0 # bgp 100 peer 3.3.3.3 as-number 100 peer 3.3.3.3 connect-interface LoopBack0 # address-family ipv4 unicast network 2.2.2.2 255.255.255.255 peer 3.3.3.3 enable
R3:
interface LoopBack0 ip address 3.3.3.3 255.255.255.255 ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/0 port link-mode route combo enable copper ip address 13.1.1.3 255.255.255.0 ospf network-type p2p ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/1 port link-mode route combo enable copper ip address 23.1.1.3 255.255.255.0 ospf network-type p2p ospf 1 area 0.0.0.0 # interface GigabitEthernet0/0/2 port link-mode route combo enable copper ip address 34.1.1.3 255.255.255.0 # bgp 100 group as100 internal peer as100 connect-interface LoopBack0 peer 1.1.1.1 group as100 peer 2.2.2.2 group as100 peer 34.1.1.4 as-number 400 # address-family ipv4 unicast network 3.3.3.3 255.255.255.255 peer as100 enable peer 34.1.1.4 enable
R4:
interface LoopBack0 ip address 4.4.4.4 255.255.255.255 # interface GigabitEthernet0/0/0 port link-mode route combo enable copper ip address 34.1.1.4 255.255.255.0 # interface GigabitEthernet0/0/1 port link-mode route combo enable copper ip address 45.1.1.4 255.255.255.0 # bgp 400 peer 34.1.1.3 as-number 100 peer 45.1.1.5 as-number 500 # address-family ipv4 unicast network 4.4.4.4 255.255.255.255 peer 34.1.1.3 enable peer 45.1.1.5 enable
R5:
interface LoopBack0 ip address 5.5.5.5 255.255.255.255 # interface GigabitEthernet0/0/0 port link-mode route combo enable copper ip address 45.1.1.5 255.255.255.0 # interface GigabitEthernet0/0/7 port link-mode route combo enable copper ip address 15.1.1.5 255.255.255.0 # bgp 500 peer 15.1.1.1 as-number 100 peer 45.1.1.4 as-number 400 # address-family ipv4 unicast network 5.5.5.5 255.255.255.255 peer 15.1.1.1 enable peer 45.1.1.4 enable