BGP属性 ASPath
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