BGP选路规则
BGP 路由器对路由的处理过程
了解BGP 路由器对路由的处理过程,可以更好的控制BGP路由表。
BGP 路由器对路由的处理过程可以概括为图10-15。从图10-15中可以看出:BGP路由来源包括从其他协议引入和从邻居学习两个部分。为了缩小路由表规模,可以先进行路由聚合。之后路由器进行路由选择、路由发送和路由下发IP路由表等过程。
序号 |
说明 |
---|---|
1 |
BGP可以引入其他路由协议的路由,比如直连路由、静态路由、UNR路由和IGP路由。BGP引入路由时支持Import和Network两种方式。 |
2 |
BGP在从其他路由协议引入路由,从邻居接收路由,向邻居发送路由时都可以使用路由策略,路由策略可以实现对路由过滤,也可以修改路由属性。 |
3 |
BGP支持两种路由聚合方式:自动聚合和手动聚合。其中,使用手动聚合时还可以应用多种路由策略。 |
4 |
BGP严格按照选路规则进行路由选择。而选路规则正是本文后续讨论重点。 |
5 |
BGP将优选的路由存在路由表中供自己使用,同时向邻居发送。 |
6 |
BGP将从BGP邻居学习的,并且在BGP路由表中优选的路由下发IP路由表,指导数据流量转发。 |
选路规则
当BGP收到到达同一目的地的多条路由时,会根据选路规则选择出最优路由,然后将最优路由下发到IP路由表,指导数据流量转发。
BGP在选择路由时严格按照先后顺序比较路由的属性,如果通过前面的属性就可以选出最优路由,BGP将不再进行后面的比较;如果BGP通过所有属性仍没有选出最优路由,则先收到的路由优选。表10-5按照顺序列出了这些属性的助记简写、选择规则和补充说明。从表10-5可以看出,仅仅协议首选值和本地优先级是数值高者优选,其他大部分是数值小者或长度短者优选。另外,表格的第一列还可以归纳成如下字符串:“OPPAAA OMTCC RA”,记住此字符串有助于记忆整个选路规则。
助记简写 |
项目 |
选择规则 |
补充说明 |
---|---|---|---|
O |
路由起源 |
Valid > NotFound > Invalid | 在与RPKI服务器进行连接的情景中,会应用起源AS验证结果优选BGP路由。 |
P |
协议首选值(PrefVal) |
数值高者优选。 缺省值0。 |
华为设备的特有属性,仅在本地有效。 |
P |
本地优先级(Local_Pref) |
数值高者优选。 缺省值100。 |
可以通过执行default local-preference命令修改BGP路由的缺省本地优先级。 |
A 说明:
此处取字符串"ASNIL"的首字面。 |
路由生成方式 |
A>S>N>I>L。其中:
|
- |
A |
AIGP(Accumulated Interior Gateway Protocol) |
数值小者优选。 有AIGP的路由优于没有AIGP的路由。 |
- |
A |
AS_Path |
长度短者优选。 |
执行bestroute as-path-ignore命令后,BGP选路时忽略AS_Path的比较。 |
O |
Origin |
IGP>EGP>Incomplete。 |
- |
M |
MED(Multi Exit Discriminator) |
数值小者优选。 缺省值0。 |
执行bestroute med-none-as-maximum命令后,BGP选路时将该路由的MED值按最大值4294967295来处理。 更多MED的使用规则请参考MED。 |
T |
邻居类型(Peer Type) |
EBGP>IBGP。 |
- |
C |
IGP Metric |
数值小者优选。 |
执行bestroute igp-metric-ignore命令后,BGP选路时忽略IGP Cost的比较。 |
C |
Cluster_List |
长度短者优选。 |
缺省情况下,BGP在选择最优路由时Cluster-List优先于Originator-ID。配置bestroute routerid-prior-clusterlist命令后,BGP在选择最优路由时Originator-ID优先于Cluster-List。 |
R |
Router ID |
数值小者优选。 |
如果路由携带Originator_ID属性,选路过程中将比较Originator_ID的大小(不再比较Router ID),并优选Originator_ID最小的路由。 |
A |
对等体的IP地址(Peer Address) |
数值小者优选。 |
- |
配置负载分担时的路由选择
配置BGP负载分担后,满足如下所有条件的多条BGP路由会成为等价路由,进行负载分担:
路由起源相同
首选值(PrefVal)相同。
本地优先级(Local_Pref)相同。
都是聚合路由,或者都不是聚合路由。
AIGP值相同。
AS_Path属性完全相同。
Origin类型(IGP、EGP、Incomplete)相同。
MED(Multi_Exit Discriminator)值相同。
都是EBGP路由或都是IBGP路由。配置maximum load-balancing eibgp命令后,BGP在选择最优VPN路由时忽略该条比较。
AS内部IGP的Metric相同。配置maximum load-balancing eibgp命令后,BGP在选择最优VPN路由时忽略该条比较。
此外,需要特别指出的是,携带标签的BGP路由与不携带标签的BGP路由即使满足上述条件,也不能形成负载分担。
私网路由选路规则
在NE40E的实现中,私网BGP路由选路规则与公网BGP路由选路规则相同。唯一的不同是,相对于公网BGP路由,私网BGP路由需要根据VPN-Target进行路由交叉。更多关于路由交叉的内容,请参见《NE40E 特性描述-IP路由-BGP》中的“路由交叉”章节。
理解BGP路由表
在详细学习BGP路由属性对BGP选路的影响之前,用户需要了解如何查询这些路由属性。
表10-6列出了所有影响BGP选路的路由属性以及这些属性对应的常用查询命令。
路由属性 |
常用查询命令 |
---|---|
路由起源 |
display bgp routing-table [ network ] |
协议首选值(PrefVal) |
display bgp routing-table [ network ] |
本地优先级(Local_Pref) |
display bgp routing-table [ network ] |
路由生成方式 |
display bgp routing-table network |
AIGP |
display bgp routing-table network |
AS_Path |
display bgp routing-table [ network ] |
Origin |
display bgp routing-table [ network ] |
MED |
display bgp routing-table [ network ] |
邻居类型 |
display bgp routing-table network |
IGP Metric |
|
Cluster_List |
display bgp routing-table network |
Originator_ID |
display bgp routing-table network |
Router ID |
display bgp routing-table network |
对等体IP地址 |
display bgp routing-table network |
在下面的描述中,将结合实际例子介绍如何查看BGP路由属性。例如,使用display bgp routing-table命令查看BGP路由表。
<HUAWEI> display bgp routing-table BGP Local router ID is 1.1.1.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn * 1.1.1.0/24 1.1.1.1 0 0 100? * 1.1.1.2/32 1.1.1.1 0 0 100? *> 5.1.1.0/24 1.1.1.1 0 0 100? *> 100.1.1.0/24 1.1.1.1 0 0 100?
项目 |
描述 |
---|---|
BGP Local router ID is 1.1.1.2 |
BGP的Router ID是1.1.1.2,其格式与IPv4地址一样。 |
Status codes |
路由的状态代码。显示在每条路由的最前面。
BGP振荡抑制使用惩罚值来衡量一条路由的稳定性,惩罚值越高则说明路由越不稳定。路由每发生一次振荡,即路由器收到该路由的Withdraw报文或者收到该路由的属性更新的Update报文时,BGP便会给此路由增加一定的惩罚值。 当惩罚值超过抑制阈值时,BGP会将该路由的>标志去掉,此路由被抑制,不再参与BGP选路,路由器也不再向其他BGP对等体发布该路由的Update报文。
惩罚值增加到一定程度之后,便不会再增加,这个值称为惩罚上限值。同时,被抑制的路由每经过一段时间,惩罚值便会减少一半。
|
Origin |
路由的Origin属性代码。
|
RPKI validation codes |
路由起源AS验证代码。
|
Network |
BGP路由表中的网络地址。 |
NextHop |
报文发送的下一跳地址。 |
MED |
BGP路由的MED度量值,作用类似于IGP路由的Metric(也称为Cost)。 |
LocPrf |
本地优先级(Local_Pref)。 |
PrefVal |
协议首选值(PrefVal)。 |
Path/Ogn |
AS_Path属性及Origin属性。 |
通过上文描述可以看到,BGP选路中使用的多个路由属性都可以通过display bgp routing-table命令查询,例如:NextHop、MED、LocPrf、PrefVal、AS_Path和Origin。但是其他的一些属性则需要通过display bgp routing-table network命令查询BGP路由的详细信息获得,例如:Route type、AIGP、Peer type、IGP Metric、Cluster_List、Router ID和Peer IP Address,以下面的显示为例。
<HUAWEI> display bgp routing-table 10.1.1.1
BGP local router ID : 192.168.2.2 Local AS number : 100 Paths: 1 available, 1 best, 1 select, 0 best-external, 0 add-path BGP routing table entry information of 10.1.1.1/32: From: 10.1.3.1 (192.168.2.3) Route Duration: 0d00h01m33s Direct Out-interface: GigabitEthernet0/1/0 Relay is delayed as nexthop flapped frequently Original nexthop: 10.1.3.1 Qos information : 0x0 Primary Routing Table: vrf1 AS-path 200, origin incomplete, MED 0, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 1 peers: 10.1.3.1
项目 |
描述 |
---|---|
BGP local router ID |
本地BGP设备的ID号,其格式与IPv4地址一样。 |
Local AS number |
本地自治系统号。 |
Paths |
BGP的路径信息。 |
BGP routing table entry information of 10.1.1.1/32 |
表示下面的信息是10.1.1.1/32的路由表项信息。 |
From |
路由发布者的IP地址。其中,10.1.3.1是邻居用来建立BGP连接的接口的IP地址(Peer IP Address),192.168.2.3是邻居的Router ID。 |
Route Duration |
路由持续时间。 |
Direct Out-interface |
直连出接口。 |
Relay is delayed as nexthop flapped frequently |
下一跳迭代震荡处于抑制中。如果路由较少,可能抑制处理时间过短,显示信息中看不到该字段 |
Original nexthop |
原始的下一跳。 |
Qos information |
QoS信息。 |
Primary Routing Table |
源路由表 |
AS-path |
AS_Path属性。如果显示为“Nil”表示属性值为空。 |
origin incomplete |
该路由的源(Origin)属性。它有以下3种类型:
|
MED |
BGP路由的MED度量值,作用类似于IGP路由的Cost(也称为Metric)。 |
pref-val |
协议首选值(PrefVal)。 |
valid |
该路由是有效路由,下一跳可达。 |
external |
该路由的邻居类型。
|
best |
该路由是最优路由。 |
select |
该路由是优选路由,将要被下发到IP路由表。 说明:
需要注意select与best标志的区别。根据BGP选路规则,总是能够选择出一条最优路由,这个最优路由会带上best标记;而在负载分担或FRR场景,实际需要将多条BGP有效路由下发到IP路由表,这些路由都会带上select标记。因此best数值总是1,而select数值则是实际下发IP路由表的BGP路由数目。 |
active |
该路由是活跃路由。 |
pre 255 |
该路由的协议优先级为255。 |
Advertised to such 1 peers |
该路由向一个对等体发布。 |
需要指出的是,执行display bgp routing-table network [ { mask | mask-length } [ longer-prefixes ] ]命令输出的显示信息与路由的生成方式和传递方式有关系,并不一定会显示BGP路由的所有属性。比如上述显示信息中,由于12.13.14.15/32是IBGP路由,所以并不会显示Route type。如果使用display bgp routing-table network [ { mask | mask-length } [ longer-prefixes ] ]命令查询本地BGP路由的详细信息,则可以看到Route type。例如:
<HUAWEI> display bgp routing-table 10.0.0.0
BGP local router ID : 192.168.2.4 Local AS number : 200 Paths: 1 available, 1 best, 1 select BGP routing table entry information of 10.0.0.0/8: Aggregated route. Route Duration: 04h50m46s Direct Out-interface: NULL0 Original nexthop: 127.0.0.1 Qos information : 0x0 AS-path {65001 10 100}, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255 Aggregator: AS 200, Aggregator ID 192.168.2.4, Atomic-aggregate Advertised to such 3 peers: 10.1.7.2 172.16.1.2 192.168.1.2
- 如果路由是通过summary automatic命令生成的自动聚合路由,则该处显示为“Summary automatic route”。
- 如果路由是通过network命令引入的路由,则该处显示为“Network route”。
- 如果路由是通过import-route命令引入的路由,则该处显示为“Imported route”。
而在下面的显示信息中,由于网络中配置了路由反射器RR(Router Reflector)和Cluster,所以使用display bgp routing-table network [ { mask | mask-length } [ longer-prefixes ] ]命令查询BGP路由的详细信息时,可以看到路由的Cluster_List属性。例如:
<HUAWEI> display bgp routing-table 10.2.1.0
BGP local router ID : 4.4.4.4 Local AS number : 65010 Paths: 1 available, 0 best, 0 select BGP routing table entry information of 10.2.1.0/24: From: 10.1.4.1 (2.2.2.2) Route Duration: 00h00m14s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, internal, pre 255 Originator: 1.1.1.1 Cluster list: 0.0.0.1 Not advertised to any peer yet
路由属性
BGP路由下一跳
BGP在选择路由时首先忽略下一跳(Next_hop)不可达的路由。
BGP的下一跳属性和IGP的有所不同,不一定就是邻居设备的IP地址。通常情况下,Next_Hop属性遵循下面的规则:
BGP Speaker在向EBGP对等体发布某条路由时,会把该路由信息的下一跳属性设置为本地与对端建立BGP邻居关系的接口地址。
BGP Speaker将本地始发路由发布给IBGP对等体时,会把该路由信息的下一跳属性设置为本地与对端建立BGP邻居关系的接口地址。
BGP Speaker在向IBGP对等体发布从EBGP对等体学来的路由时,并不改变该路由信息的下一跳属性。
BGP Speaker从IBGP向IBGP对等体发布路由时,并不改变该路由信息的下一跳属性。
更改路由下一跳
动作 |
命令 |
适用场景 |
说明 |
---|---|---|---|
配置向IBGP对等体发布路由时,修改下一跳地址 |
peer { ipv4-address | group-name } next-hop-local |
当设备通过EBGP邻居学到路由再转发给其他IBGP邻居时,默认不修改下一跳,但其EBGP邻居发来的路由的下一跳都是其EBGP邻居的Peer地址,本端对等体所属AS域内的IBGP邻居收到这样的路由后,由于下一跳不可达导致路由无法活跃。因此,需要在ASBR上修改EBGP邻居发来的路由的Next_Hop,改变下一跳地址,使得发给IBGP邻居的路由的下一跳是其自身的地址,IBGP邻居收到这样的路由后(由于域内都配置了IGP)发现下一跳可达,路由即为活跃路由。 |
说明:
如果使用maximum load-balancing number命令配置了BGP负载分担,则不论是否配置了peer next-hop-local命令,本地路由器向IBGP对等体组发布路由时都先将下一跳地址修改为与IBGP邻居建立连接使用的IP地址。 |
配置向IBGP对等体发布从IGP学到的路由时,不修改下一跳地址 |
peer { ipv4-address | group-name } next-hop-invariable |
域内通告IGP路由时不修改下一跳地址,可以让对端设备直接迭代原始下一跳,从而减少路由跳数。 |
缺省情况下,BGP向IBGP对等体发布引入的IGP路由时,将下一跳属性改为自身的接口地址。 |
在BGP向IBGP对等体发布引入的静态路由时,不修改下一跳地址 |
peer { ipv4-address | group-name } next-hop-invariable include-static-route |
域内通告静态路由时不修改下一跳地址,可以让对端设备直接迭代原始下一跳,从而减少路由跳数。 |
缺省情况下,BGP向IBGP对等体发布引入的静态路由时,将下一跳属性改为自身的接口地址。 |
配置向EBGP对等体发布路由时,不修改下一跳地址 |
peer { group-name | ipv4-address } next-hop-invariable |
在采用RR(Route Reflector)的跨域VPN OptionC方式组网中,需要在RR上执行peer next-hop-invariable命令,配置向EBGP对等体发布路由时不改变下一跳,保证对端PE可以在流量传输时可以迭代到通往本端PE的BGP LSP(Label Switched Path)。 |
缺省情况下,BGP向EBGP对等体通告路由时,将下一跳属性设为自身的接口地址。 此外,BGP从EBGP向IBGP对等体通告非标签路由时,不改变下一跳属性,通告标签路由时,将下一跳属性改为自身的接口地址。 |
配置按策略进行下一跳迭代 |
nexthop recursive-lookup route-policy route-policy-name |
配置下一跳的迭代路由策略,可以有选择地进行路由迭代,按一定的条件来限制迭代的结果路由。如果路由不能通过策略,则该路由不能被迭代。 |
缺省情况下,没有配置下一跳迭代路由策略。 |
通过应用路由策略设置BGP路由信息的下一跳地址。 |
apply ip-address next-hop{ ipv4-address | peer-address } | 通过路由策略设置路由信息的下一跳地址分两种情况。
|
当import-route命令和network命令使用路由策略时,路由策略中apply ip-address next-hop命令不生效。 |
如何使BGP路由下一跳可达
# 查看DeviceA的BGP路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 0.0.0.0 0 0 i i 3.3.3.9/32 10.1.2.1 0 100 0 65001i
从以上显示信息中可以看出,3.3.3.9/32前面没有“*”标记,这说明3.3.3.9/32并不是有效路由。
# 查看DeviceA的IP路由表。
[~DeviceA] display ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Tables: _public_ Destinations : 5 Routes : 5 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.9/32 Direct 0 0 D 127.0.0.1 LoopBack1 10.1.1.0/30 Direct 0 0 D 10.1.1.1 GigabitEthernet0/1/0 10.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
- 在DeviceA上配置目的地址为10.1.2.1/30的静态路由。
- 在DeviceB与DeviceC之间配置IGP路由协议,并且在DeviceB上配置BGP引入10.1.2.1这条路由。但是由于DeviceB与DeviceC处于不同的AS,所以IGP并不方便使用。
- 在DeviceB上配置import-route direct命令,这种方法可能会引入多余路由,因而也不是最优选择。
- 在DeviceB上配置network 10.1.2.0 30命令,通过BGP发布10.1.2.0/30这条路由给DeviceA。
- 在DeviceB上配置peer 10.1.1.1 next-hop-local命令,在向DeviceA发布路由时修改3.3.3.9/32这条路由的下一跳。
本例选择在DeviceB上配置network 10.1.2.0 30命令。配置完成后,查看DeviceA的BGP路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 3 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 0.0.0.0 0 0 i *>i 3.3.3.9/32 10.1.2.1 0 100 0 65001i *>i 10.1.2.0/30 10.1.1.2 0 100 0 i
从以上显示信息中可以看出,3.3.3.9/32已经存在“*”和“>”标记,这说明3.3.3.9/32是有效路由,也是最优路由。
协议首选值
BGP优选协议首选值最高的路由。
协议首选值(PrefVal)是华为设备的特有属性,该属性仅在本地有效,不会传递给BGP邻居。因为协议首选值是人为主动设置的,代表本地用户的意愿,因而在BGP进行选路时会优先比较协议首选值。
执行命令peer { group-name | ipv4-address } preferred-value value,为对等体配置首选值。
当到达同一地址前缀有多条路由时,优先选择首选值大的路由。缺省情况下,从邻居学来的路由的初始首选值为0。
方法 |
使用场景 |
---|---|
使用peer { group-name | ipv4-address } preferred-value value命令。 |
为本机从BGP对等体(组)接收的所有路由设置一个相同的协议首选值。 |
使用入口路由策略,并且路由策略里配置了apply preferred-value preferred-value命令。 |
为本机从BGP对等体(组)接收的不同的路由设置不同的协议首选值。 说明:
当路由同时符合peer preferred-value和apply preferred-value命令时,apply preferred-value命令的配置优先生效。 |
场景一:当未在DeviceA上配置协议首选值时,查看DeviceA的BGP路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.11.0.0/16 10.1.3.2 0 200? * 10.1.2.2 0 300 100? *> 10.22.0.0/16 10.1.3.2 0 200? * 10.1.2.2 0 300 100?
从DeviceA的路由表中可以看出,DeviceA分别从ISP1和ISP2收到了10.11.0.0/16和10.22.0.0/16这两条路由。
[~DeviceA] display bgp routing-table 10.11.0.0
BGP local router ID : 10.1.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.2 (10.1.3.2) Route Duration: 00h08m35s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 200, origin incomplete, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.2.2 BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.2 (10.1.2.2) Route Duration: 00h04m38s Direct Out-interface: 0/1/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 300 100, origin incomplete, pref-val 0, valid, external, pre 255, not preferred for AS-Path Not advertised to any peer yet
场景二:AS 65001的管理员希望通过合理配置实现下述目的:到达10.11.0.0/16和10.22.0.0/16这两个网络的数据流量都以ISP1为主用服务商,以ISP2为备用服务商。
为达到上述目的,需要保证DeviceA优选ISP1发布的路由做为到达10.11.0.0/16和10.22.0.0/16这两个网络的路由。通过在DeviceA上配置peer { group-name | ipv4-address } preferred-value value命令增大本机从AS 300接收的路由的协议首选值可以实现上述需求。具体配置如下:
bgp 65001 # ipv4-family unicast peer 10.1.2.2 preferred-value 120 //设置本机从AS 300接收的路由的协议首选值为120
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.11.0.0/16 10.1.2.2 120 300 100? * 10.1.3.2 0 200? *> 10.22.0.0/16 10.1.2.2 120 300 100? * 10.1.3.2 0 200?
从上述显示信息可以看出,DeviceA优选了ISP1发布的路由。
# 查看DeviceA上路由10.11.0.0/16或10.22.0.0/16的详细信息,这里以10.11.0.0/16为例。
[~DeviceA] display bgp routing-table 10.11.0.0
BGP local router ID : 10.1.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.2 (10.1.2.2) Route Duration: 00h05m36s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 300 100, origin incomplete, pref-val 120, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.2.2 BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.2 (10.1.3.2) Route Duration: 00h23m11s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 200, origin incomplete, pref-val 0, valid, external, pre 255, not preferred for PreVal Not advertised to any peer yet
从上面的显示信息可以看出,由于DeviceA从ISP1学习到的路由具有较高的协议首选值,因而DeviceA直接选择从ISP1学习到的路由做为优选路由,而不再进行其他路由属性的比较。
场景三:AS 65001的管理员希望通过合理配置实现下述目的:
- 到达10.11.0.0/16这个网络的数据流量能够以ISP1为主用服务商,以ISP2为备用服务商。
- 到达10.22.0.0/16这个网络的数据流量能够以ISP2为主用服务商,以ISP1为备用服务商。
为达到上述目的,需要保证:AS 65001优选ISP1发布的路由做为到达10.11.0.0/16这个网络的路由;优选ISP2发布的路由做为到达10.22.0.0/16这个网络的路由。此时由于需要对来自同一个邻居的不同路由设置协议首选值,因而不能使用peer preferred-value命令,只能通过入口路由策略来实现。具体配置如下:
# bgp 65001 # ipv4-family unicast peer 10.1.2.2 route-policy for_isp1_in import //对来自对等体10.1.2.2的路由应用入口路由策略for_isp1_in,通过for_isp1_in修改路由的协议首选值 peer 10.1.3.2 route-policy for_isp2_in import //对来自对等体10.1.3.2的路由应用入口路由策略for_isp2_in,通过for_isp2_in修改路由的协议首选值 # route-policy for_isp1_in permit node 10 //定义路由策略for_isp1_in的第一个节点,设置路由10.11.0.0/16的协议首选值为80 if-match ip-prefix for_isp1 apply preferred-value 80 # route-policy for_isp1_in permit node 20 //定义路由策略for_isp1_in的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # route-policy for_isp2_in permit node 10 //定义路由策略for_isp2_in的第一个节点,设置路由10.22.0.0/16的协议首选值为120 if-match ip-prefix for_isp2 apply preferred-value 120 # route-policy for_isp2_in permit node 20 //定义路由策略for_isp2_in的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix for_isp1 index 10 permit 10.11.0.0 16 //定义地址前缀列表,匹配路由10.11.0.0/16 ip ip-prefix for_isp2 index 10 permit 10.22.0.0 16 //定义地址前缀列表,匹配路由10.22.0.0/16 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.11.0.0/16 10.1.2.2 80 300 100? * 10.1.3.2 0 200? *> 10.22.0.0/16 10.1.3.2 120 200? * 10.1.2.2 0 300 100?
从以上显示信息可以看出,DeviceA选择ISP1发布的路由做为到达10.11.0.0/16这个网络的最优路由;选择ISP2发布的路由做为到达10.22.0.0/16这个网络的最优路由。
# 查看DeviceA上路由10.22.0.0/16的详细信息。
[~DeviceA] display bgp routing-table 10.22.0.0
BGP local router ID : 10.1.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.22.0.0/16: From: 10.1.3.2 (10.1.3.2) Route Duration: 00h14m14s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 200, origin incomplete, pref-val 120, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.2.2 BGP routing table entry information of 10.22.0.0/16: From: 10.1.2.2 (10.1.2.2) Route Duration: 00h07m54s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 300 100, origin incomplete, pref-val 0, valid, external, pre 255, not preferred for PreVal Not advertised to any peer yet
从上述显示信息可以看到,DeviceA的BGP路由表中存在两条目的地址是10.22.0.0/16的路由。由于下一跳为10.1.3.2的路由的协议首选值(120)高于下一跳为10.1.2.2的路由的协议首选值(0),因此下一跳为10.1.3.2的路由成为最优路由。由于通过协议首选值已经选出最优路由,因而DeviceA不再进行其他路由属性的比较。
通过以上示例,可以发现,通过合理配置协议首选值,可以对数据流量转发路径进行合理规划。
本地优先级
BGP优选Local_Pref属性值较高的路由。
Local_Pref属性用于判断流量离开AS时的最佳路由。本地优先级(Local_Pref)属性仅在IBGP对等体之间交换,不通告给其他AS。
修改Local_Pref属性的方法有两个,具体如表10-13所示:
方法 |
使用场景 |
---|---|
使用default local-preference命令。 |
为本机向所有IBGP邻居发布的所有路由设置一个缺省的Local_Pref。 |
使用出口路由策略或入口路由策略,并且路由策略里配置了apply local-preference命令。 |
可以为本机向任意IBGP邻居发布的任意路由设置Local_Pref,并且可以为不同的路由设置不同的Local_Pref。 说明:
当路由同时符合default local-preference和apply local-preference命令时,apply local-preference命令的配置优先生效。 |
下面以图10-19为例介绍Local_Pref属性在BGP选路过程中的应用。在图10-19中,ISP1和ISP2都为AS 65001提供到达10.11.0.0/16和10.22.0.0/16这两个网络的路由。
场景一:当未在DeviceA和DeviceB上配置Local_Pref时,查看DeviceA和DeviceB的BGP路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i
从DeviceA的路由表中可以看出,DeviceA分别从ISP1和DeviceB收到了10.11.0.0/16和10.22.0.0/16这两条路由。
[~DeviceA] display bgp routing-table 10.11.0.0
BGP local router ID : 192.168.2.3 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.1.1 (192.168.2.5) Route Duration: 04h41m03s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.4.2 BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.2 (192.168.2.2) Route Duration: 01h42m40s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/1/3 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for peer type Not advertised to any peer yet
从上面的显示信息可以看出,由于DeviceA从ISP1学习到的路由是EBGP路由,而从DeviceB学习到的路由是IBGP路由,因而从ISP1学习到的路由成为优选路由。DeviceA从ISP1和DeviceB学习到的路由属性对比如表10-14所示。
路由属性 |
从ISP1学习到的路由 |
从DeviceB学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
- |
100 |
相同 说明:
如果路由没有本地优先级,BGP选路时将该路由按缺省的本地优先级100来处理。 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
100 10 |
200 10 |
长度相同 |
Origin |
igp |
igp |
相同 |
MED |
- |
- |
相同 |
Peer Type |
EBGP |
IBGP |
从ISP1学习到的路由更优 |
DeviceB上的处理情况与DeviceA相同。此后,DeviceA和DeviceB分别将优选的路由向DeviceC发送。查看DeviceC的路由表。
[~DeviceC] display bgp routing-table
Total Number of Routes: 6 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 100 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.2.1 100 0 200 10i * i 10.1.1.1 100 0 100 10i *>i 10.22.0.0/16 10.1.2.1 100 0 200 10i * i 10.1.1.1 100 0 100 10i
从上述显示信息可以看到,DeviceC优选了DeviceB发送的路由。
在DeviceC上查看路由的详细信息来判断路由没有优选的原因。以10.11.0.0/16这条路由为例:
[~DeviceC] display bgp routing-table 10.11.0.0
BGP local router ID : 192.168.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.5.1 (192.168.2.2) Route Duration: 00h12m46s Relay IP Nexthop: 10.1.5.1 Relay IP Out-Interface: GigabitEthernet0/1/1 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255 Not advertised to any peer yet BGP routing table entry information of 10.11.0.0/16: From: 10.1.4.1 (192.168.2.3) Route Duration: 00h17m30s Relay IP Nexthop: 10.1.4.1 Relay IP Out-Interface: GigabitEthernet0/1/0 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for router ID Not advertised to any peer yet
从以上显示信息可以看出,DeviceC优选DeviceB发送的路由的原因是:RouterB的Router ID(192.168.2.2)比RouterA的Router ID(192.168.2.3)小。DeviceC从DeviceA和DeviceB学习到的路由属性对比如表10-15所示。
路由属性 |
从DeviceA学习到的路由 |
从DeviceB学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
100 10 |
200 10 |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
- |
- |
相同 |
Peer Type |
IBGP |
IBGP |
相同 |
IGP Metric |
- |
- |
相同 |
Cluster_List |
- |
- |
长度相同 |
Router ID |
192.168.2.3 |
192.168.2.2 |
从DeviceB学习到的路由更优 |
场景二:AS 65001的管理员希望通过合理配置实现下述目的:到达10.11.0.0/16和10.22.0.0/16这两个网络的数据流量都以ISP1为主用服务商,以ISP2为备用服务商。
为达到上述目的,需要保证:AS 65001内的BGP设备都优选ISP1发布的路由做为到达10.11.0.0/16和10.22.0.0/16这两个网络的路由。通过在DeviceA上配置default local-preference命令增大本机对外发布路由的缺省Local_Pref值可以实现上述需求。具体配置如下:
# bgp 65001 # ipv4-family unicast default local-preference 120 //设置本机对外发布路由的Local_Pref为120 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i
从上述显示信息可以看出,DeviceA优选了ISP1发布的路由。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 120 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 0 200 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 0 200 10i
从上述显示信息可以看出,DeviceB优选了DeviceA发布的路由。由于从ISP2学习的路由没有优选,所以DeviceB不会再将路由向其他IBGP邻居发布。
# 查看DeviceB上路由10.11.0.0/16或10.22.0.0/16的详细信息,这里以10.11.0.0/16为例。
[~DeviceB] display bgp routing-table 10.11.0.0
BGP local router ID : 192.168.2.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.1 (192.168.2.3) Route Duration: 00h22m16s Relay IP Nexthop: 10.1.3.1 Relay IP Out-Interface: GigabitEthernet0/1/4 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.2.1 BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.1 (192.168.2.4) Route Duration: 00h22m23s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
从上述显示信息可以看出,DeviceB优选DeviceA发布的路由的原因是DeviceA发布的路由Local_Pref较高。DeviceB从DeviceA和ISP2学习到的路由属性对比如表10-16所示。
路由属性 |
从DeviceA学习到的路由 |
从ISP2学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
120 |
- |
从DeviceA学习到的路由更优 说明:
如果路由没有本地优先级,BGP选路时将该路由按缺省的本地优先级100来处理。 |
# 查看DeviceC的路由表。
[~DeviceC] display bgp routing-table
Total Number of Routes: 4 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 120 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i
由于DeviceB不会向DeviceC发布从ISP2学习的路由,所以DeviceC上优选了ISP1发布的路由。
场景三:AS 65001的管理员希望通过合理配置实现下述目的:
- 到达10.11.0.0/16这个网络的数据流量能够以ISP1为主用服务商,以ISP2为备用服务商。
- 到达10.22.0.0/16这个网络的数据流量能够以ISP2为主用服务商,以ISP1为备用服务商。
为达到上述目的,需要保证:AS 65001优选DeviceA发布的路由做为到达10.11.0.0/16这个网络的路由;优选DeviceB发布的路由做为到达10.22.0.0/16这个网络的路由。具体如图10-20所示。
DeviceA的配置
# bgp 65001 # ipv4-family unicast peer 10.1.1.1 route-policy rp1 import //对来自对等体10.1.1.1的路由应用入口路由策略rp1,通过rp1修改路由的Local_Pref # route-policy rp1 permit node 10 //定义路由策略rp1的第一个节点,设置路由10.11.0.0/16的Local_Pref为80 if-match ip-prefix reducepref apply local-preference 80 # route-policy rp1 permit node 20 //定义路由策略rp1的第二个节点,设置路由10.22.0.0/16的Local_Pref为120 if-match ip-prefix addpref apply local-preference 120 # route-policy rp1 permit node 30 //定义路由策略rp1的第三个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix addpref index 10 permit 10.11.0.0 16 //定义地址前缀列表,匹配路由10.11.0.0/16 ip ip-prefix reducepref index 10 permit 10.22.0.0 16 //定义地址前缀列表,匹配路由10.22.0.0/16 #
DeviceB的配置
bgp 65001 # ipv4-family unicast peer 10.1.2.1 route-policy rp2 import //对来自对等体10.1.1.1的路由应用入口路由策略rp2,通过rp2修改路由的Local_Pref # route-policy rp2 permit node 10 //定义路由策略rp2的第一个节点,设置路由10.22.0.0/16的Local_Pref为200 if-match ip-prefix addpref apply local-preference 200 # route-policy rp2 permit node 20 //定义路由策略rp2的第二个节点,设置路由10.11.0.0/16的Local_Pref为60 if-match ip-prefix reducepref apply local-preference 60 # route-policy rp2 permit node 30 //定义路由策略rp2的第三个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix addpref index 10 permit 10.22.0.0 16 //定义地址前缀列表,匹配路由10.22.0.0/16 ip ip-prefix reducepref index 10 permit 10.11.0.0 16 //定义地址前缀列表,匹配路由10.11.0.0/16 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 5 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.2.1 200 0 200 10i * 10.1.1.1 80 0 100 10i
# 查看DeviceA上路由10.22.0.0/16的详细信息。
[~DeviceA] display bgp routing-table 10.22.0.0
BGP local router ID : 192.168.2.3 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.22.0.0/16: From: 10.1.3.2 (192.168.2.2) Route Duration: 00h20m12s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/1/3 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 200, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.1.1 BGP routing table entry information of 10.22.0.0/16: From: 10.1.1.1 (192.168.2.5) Route Duration: 00h19m40s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 80, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
从上述显示信息可以看到,DeviceA的BGP路由表中存在两条目的地址是10.22.0.0/16的路由。由于下一跳为10.1.2.1的路由的Local_Pref(200)高于下一跳为10.1.1.1的路由的Local_Pref(80),因此下一跳为10.1.2.1的路由成为最优路由。
DeviceA从ISP1和DeviceB学习到的路由属性对比如表10-17所示。
路由属性 |
从ISP1学习到的路由 |
从DeviceB学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
200 |
80 |
从ISP1学习到的路由优选 |
由于下一跳是10.1.1.1的路由不是最优路由,因此并不会向DeviceB和DeviceC发送。另外,DeviceA的BGP路由表中只有一条到达目的地址10.11.0.0/16的路由,下一跳是10.1.1.1。这是因为在DeviceB上,下一跳是10.1.2.1的路由10.11.0.0/16不是最优路由,所以DeviceB不会向DeviceA和DeviceC发送这条路由。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 5 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 100 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 60 0 200 10i *> 10.22.0.0/16 10.1.2.1 200 0 200 10i
# 查看DeviceB上路由10.11.0.0/16的详细信息。
[~DeviceB] display bgp routing-table 10.11.0.0
BGP local router ID : 192.168.2.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.1 (192.168.2.3) Route Duration: 00h40m28s Relay IP Nexthop: 10.1.3.1 Relay IP Out-Interface: GigabitEthernet0/1/4 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.2.1 BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.1 (192.168.2.4) Route Duration: 00h41m00s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 60, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
从上述显示信息可以看到,DeviceB的BGP路由表中存在两条目的地址是10.11.0.0/16的路由。由于下一跳为10.1.1.1的路由的Local_Pref(120)高于下一跳为10.1.2.1的路由的Local_Pref(60),因此下一跳为10.1.1.1的路由成为最优路由。而下一跳是10.1.2.1的路由由于不是最优路由,因此并不会向DeviceA和DeviceC发送。
# 查看DeviceC的路由表。
[~DeviceC] display bgp routing-table
Total Number of Routes: 4 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 100 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.2.1 200 0 200 10i
从上述显示信息可以看出,DeviceC上路由10.11.0.0/16的下一跳是10.1.1.1,路由10.22.0.0/16的下一跳是10.1.2.1。
- DeviceA和DeviceC到达10.11.0.0/16和10.22.0.0/16这两个网络的数据流量都以ISP1为主用服务商,以ISP2为备用服务商。
- DeviceB到达10.11.0.0/16和10.22.0.0/16这两个网络的数据流量都以ISP2为主用服务商,以ISP1为备用服务商。
为达到上述目的,需要保证:DeviceA和DeviceC优选ISP1发布的路由做为到达10.11.0.0/16和10.22.0.0/16这两个网络的路由。具体如图10-21所示。
- 通过在DeviceA上配置出口路由策略修改向DeviceC发布路由的Local_Pref值。
- 通过在DeviceC上配置入口路由策略修改从DeviceA接收路由的Local_Pref值。
bgp 65001 # ipv4-family unicast peer 10.1.2.1 route-policy rp2 export //对来自对等体10.1.1.1的路由应用出口路由策略rp2,通过rp2修改路由的Local_Pref # route-policy rp2 permit node 10 if-match ip-prefix addpref apply local-preference 120
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i
从以上显示信息可以看出,DeviceA优选ISP1发布的路由。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 100 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *> 10.11.0.0/16 10.1.2.1 0 200 10i * i 10.1.1.1 100 0 100 10i *> 10.22.0.0/16 10.1.2.1 0 200 10i * i 10.1.1.1 100 0 100 10i
从以上显示信息可以看出,DeviceB优选ISP2发布的路由。
# 查看DeviceC的路由表。
[~DeviceC] display bgp routing-table
Total Number of Routes: 6 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 120 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * i 10.1.2.1 100 0 200 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i * i 10.1.2.1 100 0 200 10i
从以上显示信息可以看出,DeviceC优选ISP1发布的路由。
# 查看DeviceC上路由10.11.0.0/16或10.22.0.0/16的详细信息,这里以10.11.0.0/16为例。
[~DeviceC] display bgp routing-table 10.11.0.0
BGP local router ID : 192.168.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.4.1 (192.168.2.3) Route Duration: 00h06m26s Relay IP Nexthop: 10.1.4.1 Relay IP Out-Interface: GigabitEthernet0/1/0 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Not advertised to any peer yet BGP routing table entry information of 10.11.0.0/16: From: 10.1.5.1 (192.168.2.2) Route Duration: 00h08m05s Relay IP Nexthop: 10.1.5.1 Relay IP Out-Interface: GigabitEthernet0/1/1 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for Local_Pref Not advertised to any peer yet
从以上显示信息可以看出,DeviceC优选ISP1发布的路由的原因是ISP1发布的路由Local_Pref较高。
通过以上示例,可以发现,修改路由的Local_Pref不仅会影响BGP路由的发布,也影响AS内部BGP设备的路由选择。通过合理配置Local_Pref属性,可以对离开AS的数据流量转发路径进行控制。
路由生成方式
本地引入路由优先级高于从邻居学来的路由,
BGP路由有两个来源:本地引入和从邻居学来的路由,其中本地引入路由优先级高于从邻居学来的路由。实际组网中,路由表中同时出现达到统一目的地址的本地引入路由和从邻居学来的路由的情况相对较少,更多的情况是本机通过多种方案引入了路由。本地引入路由包括通过network命令或import-route命令引入的路由、手动聚合路由和自动聚合路由。
优选聚合路由(聚合路由优先级高于非聚合路由)。
通过aggregate命令生成的手动聚合路由的优先级高于通过summary automatic命令生成的自动聚合路由。
通过network命令引入的路由的优先级高于通过import-route命令引入的路由。
在DeviceC上进行以下配置:
# bgp 65001 # ipv4-family unicast network 10.1.2.0 255.255.255.252 //发布路由10.1.2.0/30 network 10.1.3.0 255.255.255.252 //发布路由10.1.3.0/30 import-route direct //引入直连路由 #
在DeviceD上进行以下配置:
# bgp 65001 # ipv4-family unicast network 10.1.3.0 255.255.255.252 //发布路由10.1.3.0/30 network 10.1.4.0 255.255.255.252 //发布路由10.1.4.0/30 import-route direct //引入直连路由 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceD的路由表。
[~DeviceD] display bgp routing-table
BGP Local router ID is 10.1.3.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 10 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.2.0/30 10.1.4.2 0 100 0 i *> 10.1.3.0/30 0.0.0.0 0 0 i * 0.0.0.0 0 0 ? *> 10.1.3.2/32 0.0.0.0 0 0 ? *> 10.1.4.0/30 0.0.0.0 0 0 i * 0.0.0.0 0 0 ? i 10.1.4.2 0 100 0 ? *> 10.1.4.1/32 0.0.0.0 0 0 ? *> 127.0.0.0 0.0.0.0 0 0 ? *> 127.0.0.1/32 0.0.0.0 0 0 ?
从以上显示信息可以看出,路由表中存在三条10.1.4.0/30路由,其中下一跳是10.1.4.2的路由是从Device C学习而来,因而首先被BGP淘汰。
[~Device D] display bgp routing-table 10.1.4.0 30
BGP local router ID : 10.1.3.2 Local AS number : 65001 Paths: 3 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: Network route. From: 0.0.0.0 (0.0.0.0) Route Duration: 00h03m51s Direct Out-interface: GigabitEthernet0/1/4 Original nexthop: 10.1.4.1 Qos information : 0x0 AS-path Nil, origin igp, MED 0, pref-val 0, valid, local, best, select, pre 0 Advertised to such 2 peers: 10.1.3.1 10.1.4.2 BGP routing table entry information of 10.1.4.0/30: Imported route. From: 0.0.0.0 (0.0.0.0) Route Duration: 00h04m10s Direct Out-interface: GigabitEthernet0/1/4 Original nexthop: 10.1.4.1 Qos information : 0x0 AS-path Nil, origin incomplete, MED 0, pref-val 0, valid, local, pre 0, not preferred for route type Not advertised to any peer yet BGP routing table entry information of 10.1.4.0/30: From: 10.1.4.2 (10.1.2.2) Route Duration: 00h02m24s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: GigabitEthernet0/1/4 Original nexthop: 10.1.4.2 Qos information : 0x0 AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, internal, pre 255 Not advertised to any peer yet
从以上显示信息可以看出,通过network命令引入的路由成为最优路由。
在DeviceB上进行以下配置:
bgp 65001 # ipv4-family unicast summary automatic aggregate 10.0.0.0 255.0.0.0 import-route direct #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.1.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 14 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.0.0.0 127.0.0.1 0 ? * 127.0.0.1 0 ? s> 10.1.1.0/30 0.0.0.0 0 0 ? *> 10.1.1.2/32 0.0.0.0 0 0 ? s> 10.1.2.0/30 0.0.0.0 0 0 ? i 10.1.2.2 0 100 0 i *> 10.1.2.1/32 0.0.0.0 0 0 ? s> 10.1.3.0/30 0.0.0.0 0 0 ? i 10.1.3.2 0 100 0 i *> 10.1.3.1/32 0.0.0.0 0 0 ? *>i 10.1.4.0/30 10.1.3.2 0 100 0 i * i 10.1.2.2 0 100 0 ? *> 127.0.0.0 0.0.0.0 0 0 ? *> 127.0.0.1/32 0.0.0.0 0 0 ?
从以上显示信息可以看出,路由表中存在两条聚合路由10.0.0.0。
[~DeviceB] display bgp routing-table 10.0.0.0
BGP local router ID : 10.1.1.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.0.0.0/8: Aggregated route. Route Duration: 00h17m04s Direct Out-interface: NULL0 Original nexthop: 127.0.0.1 Qos information : 0x0 AS-path Nil, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255 Aggregator: AS 65001, Aggregator ID 10.1.1.2 Advertised to such 3 peers: 10.1.1.1 10.1.3.2 10.1.2.2 BGP routing table entry information of 10.0.0.0/8: Summary automatic route Route Duration: 00h17m04s Direct Out-interface: NULL0 Original nexthop: 127.0.0.1 Qos information : 0x0 AS-path Nil, origin incomplete, pref-val 0, valid, local, pre 255, not preferred for route type Aggregator: AS 65001, Aggregator ID 10.1.1.2 Not advertised to any peer yet
从以上显示信息可以看出,通过aggregate命令生成的手动聚合路由成为最优路由。
AIGP
BGP优选AIGP较小的路由。
AIGP属性是一种新的BGP路由属性,用于传递并累加IGP Cost值,该属性为可选非过渡属性。在一个AIGP域内部署AIGP属性,可以使BGP像IGP那样基于路由的Cost值优选出最优路由,从而保证一个AIGP域内的设备都按照最优路径进行数据转发。AIGP的比较遵循如下规则:
有AIGP属性的路由优先级高于没有AIGP属性的路由。
如果路由都存在AIGP属性,则比较AIGP属性与其下一跳的IGP Cost之和,优选该值较小的。
AIGP属性只能通过路由策略添加。在BGP引入、接收或发送路由时,可以人为通过路由策略里的apply aigp { cost | inherit-cost }命令设置AIGP属性值的大小。其中,在BGP引入IGP路由时,若不进行设置,BGP路由没有AIGP属性值。
上述配置完成后,在DeviceE上执行display bgp routing-table [ ip-address ]命令验证配置结果。本例以10.1.4.0/30这个网段路由为例。
# 查看DeviceE的路由表。
[~DeviceE] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.2.0/30 10.1.1.2 0 0 65002? * 10.1.3.2 3 0 65002? *> 10.1.4.0/30 10.1.1.2 2 0 65002? * 10.1.3.2 2 0 65002? *> 10.1.5.0/30 10.1.3.2 0 0 65002? * 10.1.1.2 3 0 65002?
[~DeviceE] display bgp routing-table 10.1.4.0
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: From: 10.1.1.2 (10.1.1.2) Route Duration: 00h02m29s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002, origin incomplete, MED 2, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.1.2 10.1.3.2 BGP routing table entry information of 10.1.4.0/30: From: 10.1.3.2 (10.1.5.1) Route Duration: 00h03m58s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 65002, origin incomplete, MED 2, pref-val 0, valid, external, pre 255, not preferred for router ID Not advertised to any peer yet
从以上显示信息可以看出,在没有配置AIGP的情况下DeviceE通过比较Router ID,优选了DeviceA发布的路由。下面通过配置AIGP属性,调整DeviceE上路由选择。
DeviceA上的配置:
# bgp 65002 # ipv4-family unicast import-route ospf 1 route-policy aigp_policy //对本地引入的OSPF路由应用路由策略aigp_policy,通过aigp_policy修改路由的AIGP peer 10.1.1.1 aigp //使能与对等体10.1.1.1之间的AIGP能力 # route-policy aigp_policy permit node 10 //定义路由策略aigp_policy的第一个节点,设置路由10.1.4.0/30的AIGP为10 if-match ip-prefix prefix1 apply aigp 10 # route-policy aigp_policy permit node 20 //定义路由策略aigp_policy的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix prefix1 index 10 permit 10.1.4.0 30 //定义地址前缀列表prefix1,匹配路由10.1.4.0/30 #
DeviceB上的配置:
bgp 65002 peer 10.1.3.1 as-number 65001 # ipv4-family unicast import-route ospf 1 route-policy aigp_policy1 //对本地引入的OSPF路由应用路由策略aigp_policy1,通过aigp_policy1修改路由的AIGP peer 10.1.3.1 aigp //使能与对等体10.1.3.1之间的AIGP能力 # route-policy aigp_policy1 permit node 10 //定义路由策略aigp_policy1的第一个节点,设置路由10.1.4.0/30的AIGP为5 if-match ip-prefix prefix2 apply aigp 5 # route-policy aigp_policy1 permit node 20 //定义路由策略aigp_policy1的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix prefix2 index 10 permit 10.1.4.0 30 //定义地址前缀列表prefix2,匹配路由10.1.4.0/30 #
DeviceE上的配置:
# bgp 65001 # ipv4-family unicast peer 10.1.1.2 aigp //使能与对等体10.1.1.2之间的AIGP能力 peer 10.1.3.2 aigp //使能与对等体10.1.3.2之间的AIGP能力 #
上述配置完成后,在DeviceE上执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceE的路由表。
[~DeviceE] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.2.0/30 10.1.1.2 0 0 65002? * 10.1.3.2 3 0 65002? *> 10.1.4.0/30 10.1.3.2 2 0 65002? * 10.1.1.2 2 0 65002? *> 10.1.5.0/30 10.1.3.2 0 0 65002? * 10.1.1.2 3 0 65002?
[~DeviceE] display bgp routing-table 10.1.4.0
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: From: 10.1.3.2 (10.1.5.1) Route Duration: 00h00m14s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 65002, origin incomplete, MED 2, pref-val 0, valid, external, best, select, active, pre 255, AIGP 5 Advertised to such 2 peers: 10.1.1.2 10.1.3.2 BGP routing table entry information of 10.1.4.0/30: From: 10.1.1.2 (10.1.1.2) Route Duration: 01h01m15s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002, origin incomplete, MED 2, pref-val 0, valid, external, pre 255, AIGP 10, not preferred for AIGP Not advertised to any peer yet
从以上显示信息可以看出,配置AIGP后,DeviceE通过比较AIGP,优选了DeviceB发布的路由做为到达10.1.4.0/30这个网络的路由。
AS_Path
BGP优选AS路径(AS_Path)最短的路由(AS_Path中AS号的个数最少)。
AS_Path属性有四种形式,分别是:AS_Sequence、AS_Set、AS_Confed_Sequence和AS_Confed_Set。
AS_Sequence:它是到目的地的路径上所经过的AS号的有序集合,按照顺序记录了路由经过的所有AS。
AS_Set:它是到目的地的路径上所经过的AS号的无序集合。AS_Set通常用在路由聚合的场景。
AS_Confed_Sequence:是联盟内子AS的一个有序集合。
AS_Confed_Set:是联盟内子AS的一个无序集合,主要用在联盟内路由聚合的场景。
项目 |
描述 |
---|---|
AS_Set |
AS_Set内不管含有多少AS号,在BGP选路时都按照长度为1进行计算。 配置aggregate (BGP)命令进行手动路由聚合时,如果携带as-set参数,则生成AS_Set,否则不生成AS_Set。生成AS_Set时,
|
AS_Confed_Sequence和AS_Confed_Set |
BGP计算AS_Path长度时不考虑AS_Confed_Sequence和AS_Confed_Set。 |
bestroute as-path-ignore命令 |
执行此命令后,BGP选路时,忽略AS_Path的比较。 |
apply as-path命令 |
通过在路由策略里使用此命令,可以清空、替换或者追加AS号。 说明:
apply as-path命令会直接影响网络流量所经过的途径,另外也可能造成环路和选路错误,请谨慎使用。 |
peer public-as-only命令 |
执行此命令后,BGP发送Update报文时删除私有AS号,仅携带公有AS号。其中私有AS编号范围是64512~65534。
说明:
如果配置private-4-byte-as enable命令使能4字节私有AS号能力之后,私有AS号范围除了64512~65534之外,还可以是4200000000~4294967294(或者64086.59904~65535.65534)。 |
peer fake-as命令 |
执行此命令后,BGP可以将真实AS号隐藏,而使用伪AS号与对端建立邻居。 如果本端使用真实AS号与对端建立EBGP邻居,那么发送给邻居的路由的AS_Path列表就携带真实AS号。如果本端使用伪AS号与对端建立EBGP邻居,那么发送给邻居的路由的AS_Path列表就只携带伪AS号。 |
peer substitute-as命令 |
执行此命令后,当PE向指定对等体中的CE发布路由时,如果路由的AS_Path中有与CE相同的AS号,将被替换成PE的AS号后再发布。
说明:
peer substitute-as仅适用于BGP MPLS IP/VPN里的PE设备上,配置不当会引起路由环路,请谨慎使用。 |
AS_Path的比较可以简单概括为比较AS_Sequence里的AS号数量,如果存在AS_Set时,AS_Path长度再加一。下面将使用示例详细介绍上述一些常用的命令。
移除私有AS号
根据图10-24,当DeviceA向外发布路由10.0.0.0/8时,该路由通过ISP1和ISP2到达DeviceD时,DeviceD会检查路由的AS_Path,此时发现自己的AS号65001已经存在于AS_Path中,从而会将路由丢弃。
为了防止出现此类问题,可以在DeviceB上配置peer public-as-only命令,这样当ISP1的DeviceB向ISP2的DeviceC发送路由时,会首先将私有AS号65001移除,然后添加自己的AS号100,这样就可以防止由于私有AS重复导致的路由被丢弃的现象。
路由的AS_Path属性中含有对端的AS号时。这种情况下删除私有AS号,可能会造成路由环路。
AS_Path属性中同时含有公有AS号和私有AS号。这种情况表明路由已经经过了公网,如果删除私有AS号,可能会造成转发错误。
AS号追加
执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 172.16.1.0/24 10.1.3.2 0 65003 65005? * 10.1.1.2 0 65002 65004 65005? *> 172.16.2.0/24 10.1.3.2 0 65003 65005? * 10.1.1.2 0 65002 65004 65005? *> 172.16.3.0/24 10.1.3.2 0 65003 65005? * 10.1.1.2 0 65002 65004 65005?
[~DeviceA] display bgp routing-table 172.16.1.0
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 172.16.1.0/24: From: 10.1.3.2 (10.1.5.1) Route Duration: 00h00m56s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 65003 65005, origin incomplete, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.1.2 BGP routing table entry information of 172.16.1.0/24: From: 10.1.1.2 (10.1.1.2) Route Duration: 00h34m43s Direct Out-interface: GigabitEthernet0/0/1 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002 65004 65005, origin incomplete, pref-val 0, valid, external, pre 255, not preferred for AS-Path Not advertised to any peer yet
从以上显示信息可以看出,DeviceA优选了DeviceC发布的路由,因为DeviceC发布的路由AS_Path长度更短。如果DeviceA希望优选DeviceB发布的路由,则可以通过缩短DeviceB发布路由的AS_Path长度或者增加DeviceC发布路由的AS_Path长度来实现。本例以增加DeviceC发布路由的AS_Path长度为例。DeviceC上具体配置如下:
# bgp 65003 # ipv4-family unicast undo synchronization peer 10.1.3.1 route-policy add_asn export //对BGP对等体10.1.3.1使用出口策略add_asn # route-policy add_asn permit node 10 //定义路由策略add_asn的第一个节点 if-match ip-prefix prefix1 //匹配IP地址前缀列表prefix1 apply as-path 65003 65003 65003 additive //为匹配IP地址前缀列表prefix1的路由追加AS号65003 65003 65003 # route-policy add_asn permit node 20 //定义路由策略add_asn的第二个节点,允许其他路由通过 # ip ip-prefix prefix1 index 10 permit 172.16.1.0 24 //定义IP地址前缀列表prefix1的第一个索引,匹配路由172.16.1.0/24 ip ip-prefix prefix1 index 20 permit 172.16.2.0 24 //定义IP地址前缀列表prefix1的第二个索引,匹配路由172.16.2.0/24 ip ip-prefix prefix1 index 30 permit 172.16.3.0 24 //定义IP地址前缀列表prefix1的第三个索引,匹配路由172.16.3.0/24 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 172.16.1.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65003 65003 65003 65003 65005? *> 172.16.2.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65003 65003 65003 65003 65005? *> 172.16.3.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65003 65003 65003 65003 65005?
[~DeviceA] display bgp routing-table 172.16.1.0
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 172.16.1.0/24: From: 10.1.1.2 (10.1.1.2) Route Duration: 00h33m30s Direct Out-interface: GigabitEthernet0/0/1 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002 65004 65005, origin incomplete, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.1.2 BGP routing table entry information of 172.16.1.0/24: From: 10.1.3.2 (10.1.5.1) Route Duration: 00h02m12s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 65003 65003 65003 65003 65005, origin incomplete, pref-val 0, valid, external, pre 255, not preferred for AS-Path Not advertised to any peer yet
用户可以在AS_Path中追加任意AS号。但是实际应用中,最常用的方法还是在BGP对外发布路由时追加本地AS号。这是因为如果添加其他AS号则意味着阻止路由进入该AS。例如在图10-25中,如果在DeviceC向DeviceA发布路由时使用出口路由策略追加AS 65001,则DeviceA接收到路由后检查AS_Path,会发现本地AS号已经处于AS_Path中,进而将路由丢弃。
AS号替换
隐藏路由的真实路径信息。
如果配置了as-path-limit命令,接收路由时会检查AS_Path属性中的AS号是否超限,如果超限则丢弃路由。这样对于AS_Path较长的路由,在接收之前,可以把AS_Path替换成较短的AS_Path,防止路由由于AS号超限而被丢弃。
缩短AS_Path长度,使路由被优选。
除了上述应用,AS号替换还可以用于形成负载分担。通常情况下,BGP要求路由的AS_Path相同才能形成负载分担。为满足负载分担的条件,可以进行AS号替换。例如在图10-25中,如果在DeviceA从DeviceC接收路由时使用apply as-path 65002 65004 65005 overwrite命令进行AS号替换,则DeviceA从DeviceB和DeviceC收到的路由AS_Path相同,这些路由有可能形成负载分担。DeviceA上具体配置如下:
# bgp 65001 # ipv4-family unicast undo synchronization peer 10.1.3.2 route-policy replace_asn import //对BGP对等体10.1.3.1使用出口策略replace_asn # route-policy replace_asn permit node 10 //定义路由策略replace_asn的第一个节点 if-match as-path-filter filter1 //匹配AS_Path过滤器filter1 apply as-path 65002 65004 65005 overwrite //将AS_Path过滤器filter1的路由AS_Path替换为65002 65004 65005 # route-policy replace_asn permit node 20 //定义路由策略replace_asn的第二个节点,允许其他路由通过 # ip as-path-filter filter1 permit ^65003 //定义AS_Path过滤器filter1,匹配AS 65003发来的所有路由 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 172.16.1.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65002 65004 65005? *> 172.16.2.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65002 65004 65005? *> 172.16.3.0/24 10.1.1.2 0 65002 65004 65005? * 10.1.3.2 0 65002 65004 65005?
从以上显示信息可以看出,AS 65003发来的路由AS_Path已经被修改。此时AS 65002和AS 65003发来的路由具有相同的AS_Path,已经满足负载分担条件。在DeviceA上执行maximum load-balancing 2命令配置负载分担条数为2。然后查看指定BGP路由详细信息,以172.16.1.0/24这条路由为例。
[~DeviceA] display bgp routing-table 172.16.1.0
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 2 select BGP routing table entry information of 172.16.1.0/24: From: 10.1.1.2 (10.1.1.2) Route Duration: 19h57m51s Direct Out-interface: GigabitEthernet0/0/1 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002 65004 65005, origin incomplete, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.1.2 10.1.3.2 BGP routing table entry information of 172.16.1.0/24: From: 10.1.3.2 (10.1.5.1) Route Duration: 00h10m21s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path 65002 65004 65005, origin incomplete, pref-val 0, valid, external, select, active, pre 255, not preferred for router ID Not advertised to any peer yet
从以上显示信息可以看出,DeviceB发来的路由是最优路由,被BGP选择用作负载分担,而DeviceC发来的路由虽然不是最优路由,但是也被BGP选择用作负载分担。为了进一步证实上述结论,查看IP路由表中172.16.1.0/24这条路由的信息。
[~DeviceA] display ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route
------------------------------------------------------------------------------
Routing Tables: _Public_
Destinations : 9 Routes : 12
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.1.0/30 Direct 0 0 D 10.1.1.1 GigabitEthernet0/0/1
10.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
10.1.3.0/30 Direct 0 0 D 10.1.3.1 GigabitEthernet0/0/0
10.1.3.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
172.16.1.0/24 EBGP 255 0 D 10.1.1.2 GigabitEthernet0/0/1
EBGP 255 0 D 10.1.3.2 GigabitEthernet0/0/0
172.16.2.0/24 EBGP 255 0 D 10.1.1.2 GigabitEthernet0/0/1
EBGP 255 0 D 10.1.3.2 GigabitEthernet0/0/0
172.16.3.0/24 EBGP 255 0 D 10.1.1.2 GigabitEthernet0/0/1
EBGP 255 0 D 10.1.3.2 GigabitEthernet0/0/0
从以上显示信息可以看出,对于同一目的地址前缀,BGP下发两条路由到IP路由表,负载分担已经形成。
清空AS_Path
配置apply as-path命令时,如果选择none overwrite参数,则可以清空AS_Path,这种方式可以隐藏真实的路径信息,还可以缩短AS_Path长度。BGP在选路时,如果AS_Path列表为空,AS_Path长度按照0来处理。
Origin
Origin属性定义路径信息的来源,标记一条路由是怎么成为BGP路由的。
- IGP:具有最高的优先级。路由是用network命令注入到BGP路由表中的,则Origin属性为IGP。
- EGP:优先级次之。通过EGP得到的路由信息,其Origin属性为EGP。
NE40E可以接收和发送携带EGP属性的BGP路由。但是NE40E本身不支持EGP协议,因而在NE40E上,只能通过路由策略里的apply origin { egp { as-number-plain | as-number-dot } | igp | incomplete }命令为路由添加EGP属性。
- Incomplete:优先级最低。路由是用import-route命令注入到BGP路由表中的,则Origin属性为Incomplete。
在DeviceD上进行以下配置:
# bgp 65001 # ipv4-family unicast network 10.1.4.0 255.255.255.252 //发布路由10.1.4.0/30 #
在DeviceC上进行以下配置:
# bgp 65001 # ipv4-family unicast import-route direct //引入直连路由 #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.1.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 3 Network NextHop MED LocPrf PrefVal Path/Ogn i 10.1.2.0/30 10.1.2.2 0 100 0 ? *>i 10.1.4.0/30 10.1.3.2 0 100 0 i * i 10.1.2.2 0 100 0 ?
从以上显示信息可以看出,路由表中存在两条有效路由10.1.4.0/30。
[~DeviceB] display bgp routing-table 10.1.4.0
BGP local router ID : 10.1.1.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: From: 10.1.3.2 (10.1.3.2) Route Duration: 01h14m48s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: GigabitEthernet0/0/2 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.1.1 BGP routing table entry information of 10.1.4.0/30: From: 10.1.2.2 (10.1.2.2) Route Duration: 01h13m20s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for Origin Not advertised to any peer yet
从以上显示信息可以看出,由于从DeviceD发来的路由是通过network命令引入,因而Origin属性更优而成为最优路由。DeviceB从DeviceC和DeviceD学习到的路由属性对比如表10-21所示。
路由属性 |
从DeviceC学习到的路由 |
从DeviceD学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
- |
- |
长度相同 |
Origin |
Incomplete |
IGP |
从DeviceD学习到的路由更优 |
用户可用通过配置路由策略修改路由的Origin属性。本例在DeviceB上进行修改,具体配置如下:
# bgp 65001 # ipv4-family unicast peer 10.1.3.2 route-policy for_d import //向对等体10.1.3.2发来的路由应用入口路由策略for_d,通过for_d修改路由的Origin # route-policy for_d permit node 10 //定义路由策略for_d apply origin incomplete //设置路由的Origin属性是incomplete
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.1.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 3 Network NextHop MED LocPrf PrefVal Path/Ogn i 10.1.2.0/30 10.1.2.2 0 100 0 ? *>i 10.1.4.0/30 10.1.2.2 0 100 0 ? * i 10.1.3.2 0 100 0 ?
从以上显示信息可以看出,从DeviceC发来的路由已经变为最优路由。
[~DeviceB] display bgp routing-table 10.1.4.0
BGP local router ID : 10.1.1.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: From: 10.1.2.2 (10.1.2.2) Route Duration: 01h28m19s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.1.1 BGP routing table entry information of 10.1.4.0/30: From: 10.1.3.2 (10.1.3.2) Route Duration: 00h03m18s Relay IP Nexthop: 0.0.0.0 Relay IP Out-Interface: GigabitEthernet0/0/2 Original nexthop: 10.1.3.2 Qos information : 0x0 AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for router ID Not advertised to any peer yet
从以上显示信息可以看出,由于从DeviceC发来的路由Router ID较小而成为最优路由。DeviceB从DeviceC和DeviceD学习到的路由属性对比如表10-22所示。
路由属性 |
从DeviceC学习到的路由 |
从DeviceD学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
- |
- |
相同 |
Origin |
Incomplete |
Incomplete |
相同 |
MED |
0 |
0 |
相同 |
Peer Type |
IBGP |
IBGP |
相同 |
IGP Metric |
- |
- |
相同 |
Cluster_List |
- |
- |
相同 |
Router ID |
10.1.2.2 |
10.1.3.2 |
从DeviceC学习到的路由更优 |
MED
通过合理配置MED,可以对网络流量进行合理规划,达到负载均衡的目的。
MED(Multi-Exit-Discriminator)属性仅在AS内部或者相邻两个AS之间传递,收到此属性的AS一方不会再将其通告给任何其他第三方AS。
MED属性相当于IGP使用的度量值(Metrics),它用于判断流量进入AS时的最佳路由。当BGP设备通过不同的EBGP对等体得到目的地址相同但下一跳不同的多条路由时,在其它条件相同的情况下,将优先选择MED值较小者作为最佳路由。
修改MED属性的方法有三个,具体如表10-23所示:
方法 |
使用场景 |
---|---|
使用default med命令。 |
为本机向所有BGP邻居发布的所有路由设置一个缺省的MED。default med命令只对本设备上用import-route命令引入的路由和BGP的聚合路由生效。 |
使用出口路由策略或入口路由策略,并且路由策略里配置了apply cost命令。 |
可以为本机向任意EBGP邻居发布的任意路由设置MED,并且可以为不同的路由设置不同的MED。 |
使用出口路由策略,并且路由策略里配置了apply cost-type internal命令。 |
路由器会将向对等体通告的路由的MED值设置为该路由的下一跳的IGP开销值,仅对EBGP邻居生效。 |
使用出口路由策略,并且路由策略里配置了apply cost-type internal-inc-ibgp命令。 |
路由器会将向对等体通告的路由的MED值设置为该路由的下一跳的IGP开销值,对IBGP邻居、EBGP邻居均生效。 |
使用出口路由策略,并且路由策略里配置了apply cost-type med-plus-igp命令。 |
路由器会将向对等体通告的路由的MED值设置为该路由的下一跳的IGP开销值叠加原MED值,对IBGP邻居、EBGP邻居均生效。 |
使用出口路由策略,并且路由策略里配置了apply cost-type med-inherit-aigp命令。 |
路由器会将向对等体通告的路由的MED值设置为路由的AIGP属性值,对IBGP邻居、EBGP邻居均生效。该策略仅对私网BGP生效。 |
此外,在使用MED属性时还需要注意以下几条规则:
由于MED属性主要用来判断流量进入同一个AS时的最佳路由,若路由来自于不同的AS,则意味着流量也是进入不同的AS,所以BGP只比较来自同一个AS(不包括联盟的子AS)的路由的MED值。即,只有两条路由的AS_SEQUENCE(不包括AS_CONFED_SEQUENCE)属性的第一个AS号相同时,BGP才会比较二者的MED值。
执行compare-different-as-med命令后,BGP将强制比较来自不同AS的路由的MED值。除非能够确认不同的AS采用了同样的IGP和路由选择方式,否则不要使用compare-different-as-med命令(可能产生环路)。
如果路由没有MED属性,BGP选路时将该路由的MED值按缺省值0来处理;执行bestroute med-none-as-maximum命令后,BGP选路时将该路由的MED值按最大值4294967295来处理,选路结束后,MED值恢复为原始值。
执行bestroute med-confederation命令后,只有当AS_Path中不包含外部AS号(不属于联盟的子AS),且AS_CONFED_SEQUENCE的第一个AS号相同时,才能比较MED值的大小。
执行deterministic-med命令后,将消除路由接收顺序对选路结果的影响。
下面以图10-27为例介绍MED属性在BGP选路过程中的应用。在图10-27中,ISP1和ISP2都可以通过DeviceC或DeviceD到达1.1.1.9/32这个目的地址。
场景一:当未在DeviceC和DeviceD上配置修改1.1.1.9/32这条路由的MED属性时,查看DeviceA和DeviceB的BGP路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 10.1.1.2 0 65001i * 10.1.3.2 0 65001i
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 10.1.4.2 0 65001i * 10.1.2.2 0 65001i
从以上显示信息可以看出ISP1和ISP2都选择了DeviceC发布的路由做为最优路由。也就是说,从ISP1和ISP2到达1.1.1.1/32这个目的地址的数据流量都将通过DeviceC进入AS 65001,DeviceD没有承载流量,这样显然不利于负载均衡。
在DeviceB上执行display bgp routing-table ip-address命令,分析DeviceB优选Device C发布路由的原因。
[~DeviceB] display bgp routing-table 1.1.1.9
BGP local router ID : 10.1.2.1 Local AS number : 200 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 1.1.1.9/32: From: 10.1.4.2 (10.1.1.2) Route Duration: 00h00m58s Direct Out-interface: GigabitEthernet0/0/2 Original nexthop: 10.1.4.2 Qos information : 0x0 AS-path 65001, origin igp, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.2.2 10.1.4.2 BGP routing table entry information of 1.1.1.9/32: From: 10.1.2.2 (10.1.2.2) Route Duration: 00h01m07s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 65001, origin igp, pref-val 0, valid, external, pre 255, not preferred for router ID Not advertised to any peer yet
从以上显示信息可以看出,DeviceB优选DeviceC发送的路由的原因是:RouterC的Router ID(10.1.1.2)比RouterD的Router ID(10.1.2.2)小。DeviceB从DeviceC和DeviceD学习到的路由属性对比如表10-24所示。
路由属性 |
从DeviceC学习到的路由 |
从DeviceD学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
- |
- |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
65001 |
65001 |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
- |
- |
相同 |
Peer Type |
EBGP |
EBGP |
相同 |
IGP Metric |
- |
- |
相同 |
Cluster_List |
- |
- |
长度相同 |
Router ID |
10.1.1.2 |
10.1.2.2 |
从DeviceC学习到的路由更优 |
- 从ISP1发来的到达1.1.1.9/32的数据流量首选从DeviceC进入AS 65001,次选从DeviceD进入AS 65001。
- 从ISP2发来的到达1.1.1.9/32的数据流量首选从DeviceD进入AS 65001,次选从DeviceC进入AS 65001。
为达到上述目的,需要保证:ISP1优选DeviceC发布的路由做为到达1.1.1.9/32这个目的地址的路由;ISP2优选DeviceD发布的路由做为到达1.1.1.9/32这个目的地址的路由。具体如图10-28所示。
DeviceC的配置
# bgp 65001 # ipv4-family unicast undo synchronization peer 10.1.4.1 route-policy addmed100 export //向发往对等体10.1.4.1的路由应用出口路由策略addmed100,通过addmed100修改路由的MED # route-policy addmed100 permit node 10 //定义路由策略addmed100的第一个节点,设置路由1.1.1.9/32的MED为100 if-match ip-prefix p1 apply cost 100 # route-policy addmed100 permit node 20 //定义路由策略addmed100的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix p1 index 10 permit 1.1.1.9 32 //定义地址前缀列表,匹配路由1.1.1.9/32
- DeviceD的配置
本步骤是为了保证DeviceA优选DeviceC发布的路由。但是从上文可以看出,由于DeviceC的Router ID比DeviceD的Router ID小,DeviceA已经优选了DeviceC发布的路由,所以DeviceD的配置是可选配置。
# bgp 65001 # ipv4-family unicast undo synchronization peer 10.1.3.1 route-policy addmed200 export //向发往对等体10.1.3.1的路由应用出口路由策略addmed200,通过addmed200修改路由的MED # route-policy addmed200 permit node 10 //定义路由策略addmed200的第一个节点,设置路由1.1.1.9/32的MED为200 if-match ip-prefix p1 apply cost 200 # route-policy addmed200 permit node 20 //定义路由策略addmed200的第二个节点,不设置匹配条件,允许其他路由通过路由策略 # ip ip-prefix p1 index 10 permit 1.1.1.9 32 //定义地址前缀列表,匹配路由1.1.1.9/32
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。此处以DeviceB为例。
# 查看DeviceB的路由表。
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 10.1.2.2 0 65001i * 10.1.4.2 100 0 65001i
# 查看DeviceB上路由1.1.1.9/32的详细信息。
[~DeviceB] display bgp routing-table 1.1.1.9 32
BGP local router ID : 10.1.2.1 Local AS number : 200 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 1.1.1.9/32: From: 10.1.2.2 (10.1.2.2) Route Duration: 01h20m38s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 65001, origin igp, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.2.2 10.1.4.2 BGP routing table entry information of 1.1.1.9/32: From: 10.1.4.2 (10.1.1.2) Route Duration: 01h16m28s Direct Out-interface: GigabitEthernet0/0/2 Original nexthop: 10.1.4.2 Qos information : 0x0 AS-path 65001, origin igp, MED 100, pref-val 0, valid, external, pre 255, not preferred for MED Not advertised to any peer yet
从上述显示信息可以看到,DeviceB的BGP路由表中存在两条目的地址是1.1.1.9/32的路由,其中下一跳为10.1.2.2的路由成为最优路由,而下一跳为10.1.4.2的路由因为MED属性没有优选。
DeviceB从DeviceC和DeviceD学习到的路由属性对比如表10-25所示。
路由属性 |
从DeviceC学习到的路由 |
从DeviceD学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
- |
- |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
65001 |
65001 |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
100 |
- |
DeviceD没有MED值,比较MED值时按照缺省值0来处理。 从DeviceD学习到的路由优选 |
在图10-28中,如果路由没有MED属性,BGP选路时将该路由的MED值按缺省值0来处理,所以从DeviceD学习到的路由优选。此时如果在DeviceB上配置bestroute med-none-as-maximum命令,则将再次改变DeviceB的路由选择结果。具体配置如下:
[~DeviceB] display bgp routing-table
BGP Local router ID is 10.1.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 1.1.1.9/32 10.1.4.2 100 0 65001i * 10.1.2.2 0 65001i
[~DeviceB] display bgp routing-table 1.1.1.9
BGP local router ID : 10.1.2.1 Local AS number : 200 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 1.1.1.9/32: From: 10.1.4.2 (10.1.1.2) Route Duration: 00h08m42s Direct Out-interface: GigabitEthernet0/0/2 Original nexthop: 10.1.4.2 Qos information : 0x0 AS-path 65001, origin igp, MED 100, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.2.2 10.1.4.2 BGP routing table entry information of 1.1.1.9/32: From: 10.1.2.2 (10.1.2.2) Route Duration: 16h33m10s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 65001, origin igp, pref-val 0, valid, external, pre 255, not preferred for MED Not advertised to any peer yet
从上述显示信息可以看到,DeviceB的BGP路由表中存在两条目的地址是1.1.1.9/32的路由,其中下一跳为10.1.4.2的路由MED是100,而下一跳为10.1.2.2的路由由于没有MED,所以按照4294967295处理,因此下一跳为10.1.4.2的路由由于MED小而成为最优路由。
此外,实际在选路过程中,BGP会按照路由接收的顺序依次进行比较,最终选路的结果和路由的接收顺序是相关的。例如,假设在某台设备上存在如下三条BGP路由:
Route A1: AS_Path { 65001 200 }, med 100, igp cost 13, internal, Router id 4.4.4.4
Route A2: AS_Path { 65001 100 }, med 150, igp cost 11, internal, Router id 5.5.5.5
Route B: AS_Path { 65002 300 }, med 0, igp cost 12, internal, Router id 6.6.6.6
- Case1:如果路由收来的顺序为Route A1、Route B、Route A2:
- 先比较Route A1和Route B。因为Route A1和Route B的最左AS不相同,设备不比较MED,然后优选IGP Metric(IGP Cost)较小的路由Route B。
- 再比较Route A2和Route B,因为Route A2和Route B的最左AS不相同,设备不比较MED,然后优选IGP Metric较小的路由Route A2。
- Case2:如果路由收来的顺序为Route A2、Route B、Route A1:
- 先比较Route A2和Route B,因为Route B和Route A2的最左AS不相同,设备不比较MED,然后优选IGP Metric较小的路由Route A2。
- 再比较Route A1和Route A2,因为Route A1和Route A2的最左AS相同,所以优选MED较小的路由Route A1。
- Case3:如果使能了deterministic-med命令,在对从多个不同AS收到的相同前缀的路由进行选路时,首先会按路由的AS_Path最左边的AS号进行分组。在组内进行比较后,再用组中的优选路由和其他组中的优选路由进行比较,所以设备的处理步骤是:
- 先比较Route A1和Route A2。因为Route A1和Route A2的最左AS相同,所以优选MED较小的路由Route A1。
- 再比较Route A1和Route B,因为Route A1和Route B的最左AS不相同,设备不比较MED,然后优选IGP Metric较小的路由Route B。
从Case1和Case2比较可以看到,未使能deterministic-med命令时,最终优选的路由和路由接收的顺序相关。而在Case3中使能了deterministic-med命令后,就消除了选路的结果和路由接收顺序的相关性。
邻居类型
当IBGP路由和EBGP路由同时存在时,BGP优选从EBGP邻居学来的路由。
邻居类型的比较存在以下特点:如果在多条路由中存在唯一一条EBGP路由,则BGP通过邻居类型的比较可以快速选出最优路由。但是如果不存在EBGP路由,或者存在多条EBGP路由,则通过邻居类型的比较,BGP无法选出一条最优路由。
从图10-29中也可以看出,Device A和Device B选择EBGP路由还可以避免出口流量在Device A和Device B之间的链路穿越,这也是选择EBGP路由的一个优势。
比较邻居类型的例子在前文已经提到,此处不再赘述。详细可以参考本地优先级。
IGP Cost
BGP优选到下一跳IGP Cost较小的路由。
上述部署完成后,在DeviceC和DeviceD上执行display bgp routing-table [ ip-address ]命令验证配置结果。本例以DeviceC为例。
# 查看DeviceC的路由表。
[~DeviceC] display bgp routing-table
BGP Local router ID is 10.1.1.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 1.1.1.9/32 10.1.5.2 0 100 0 100i * i 10.1.6.2 0 100 0 100i *>i 10.1.5.0/30 10.1.3.2 0 100 0 i *>i 10.1.6.0/30 10.1.2.2 0 100 0 i
从以上显示信息可以看出,到达1.1.1.9/32存在两条路由。而DeviceC优选了DeviceA发布的路由。
[~DeviceC] display bgp routing-table 1.1.1.9
BGP local router ID : 10.1.1.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 1.1.1.9/32: From: 10.1.3.2 (2.2.2.9) Route Duration: 00h00m44s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/0/0 Original nexthop: 10.1.5.2 Qos information : 0x0 AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255 Not advertised to any peer yet BGP routing table entry information of 1.1.1.9/32: From: 10.1.2.2 (10.1.2.2) Route Duration: 00h00m39s Relay IP Nexthop: 10.1.1.2 Relay IP Out-Interface: GigabitEthernet0/0/1 Original nexthop: 10.1.6.2 Qos information : 0x0 AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 2, not preferred for IGP cost Not advertised to any peer yet
从以上显示信息可以看出,下一跳为10.1.6.2的路由因为IGP Cost较大被淘汰。DeviceC从DeviceA和DeviceB学习到的路由属性对比如表10-26所示。
路由属性 |
从DeviceA学习到的路由 |
从DeviceB学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
100 |
100 |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
0 |
0 |
相同 |
Peer Type |
IBGP |
IBGP |
相同 |
IGP Cost |
- |
2 |
从DeviceA学习到的路由更优。 说明:
如果BGP路由没有IGP Cost值,则在BGP选路过程中按照0处理。一般情况下,如果BGP邻居建立过程中没有使用IGP路由或者使用的IGP路由Cost为0,则执行display bgp routing-table ip-address命令都不显示IGP Cost值。 |
Cluster_List
BGP优选Cluster_List最短的路由(Cluster_List中的Cluster_ID个数最少)。
路由反射器RR(Route Reflector)和它的客户机(Client)组成一个集群(Cluster)。在一个AS内,每个路由反射器使用唯一的Cluster_ID作为标识。
Cluster_List由路由反射器产生,它由一系列的Cluster_ID组成,描述了一条路由所经过的反射器路径,这和描述路由经过的AS路径的AS_Path属性有相似之处。
当RR在它的客户机之间或客户机与非客户机之间反射路由时,RR会把本地Cluster_ID添加到Cluster_List的前面。如果Cluster_List为空,RR就创建一个。
当RR接收到一条更新路由时,RR会检查Cluster_List。如果Cluster_List中已经有本地Cluster_ID,丢弃该路由;如果没有本地Cluster_ID,将其加入Cluster_List,然后反射该更新路由。
下面结合实例讲述Cluster_List在BGP选路过程中的作用。如图10-31所示,AS65001内部相邻的设备间建立IBGP邻居关系。其中DeviceB做为一级RR,DeviceD是其客户机;DeviceD做为二级RR,DeviceE是其客户机。DeviceC也被配置成RR,DeviceE是其客户机。DeviceE上BGP引入路由1.1.1.9/32。
上述部署完成后,在DeviceA上执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.3.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 1.1.1.9/32 10.1.5.2 0 100 0 i * i 10.1.4.2 0 100 0 i
从以上显示信息可以看出,到达1.1.1.9/32存在两条路由。而DeviceA优选了DeviceC发布的路由。
[~DeviceA] display bgp routing-table 1.1.1.9
BGP local router ID : 10.1.3.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 1.1.1.9/32: From: 10.1.3.2 (2.2.2.9) Route Duration: 00h53m08s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/0/1 Original nexthop: 10.1.5.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255, IGP cost 3 Originator: 1.1.1.9 Cluster list: 0.0.0.3 Not advertised to any peer yet BGP routing table entry information of 1.1.1.9/32: From: 10.1.1.2 (10.1.2.1) Route Duration: 00h28m05s Relay IP Nexthop: 10.1.1.2 Relay IP Out-Interface: GigabitEthernet0/0/0 Original nexthop: 10.1.4.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 3, not preferred for Cluster List Originator: 1.1.1.9 Cluster list: 0.0.0.2, 0.0.0.1 Not advertised to any peer yet
从以上显示信息可以看出,来自DeviceB的路由因为Cluster_List较长被淘汰。DeviceA从DeviceB和DeviceC学习到的路由属性对比如表10-27所示。
路由属性 |
从DeviceB学习到的路由 |
从DeviceC学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
- |
- |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
0 |
0 |
相同 |
Peer Type |
IBGP |
IBGP |
相同 |
IGP Cost |
3 |
3 |
相同 |
Cluster_List |
0.0.0.2, 0.0.0.1 |
0.0.0.3 |
从DeviceC学习到的路由更优 |
通过上述分析可以发现,虽然路由反射器的实现放宽了对“BGP在AS内学到的路由不会在AS中转发”的要求,但是通过人为引入Cluster_List属性有效的防止了AS内部的环路。
Originator_ID
如果路由携带Originator_ID属性,选路过程中将比较Originator_ID的大小(不再比较Router ID),并优选Originator_ID最小的路由。
Originator_ID属性长4字节,由路由反射器(RR)产生,携带了本地AS内部路由发起者的Router ID。
当一条路由第一次被RR反射的时候,RR将Originator_ID属性加入这条路由,标识这条路由的发起路由器。如果一条路由中已经存在了Originator_ID属性,则RR将不会创建新的Originator_ID。
当其他BGP Speaker接收到这条路由的时候,将比较收到的Originator_ID和本地的Router ID,如果两个ID相同,BGP Speaker会忽略掉这条路由,不做处理。
下面结合实例讲述Originator_ID在BGP选路过程中的作用。如图10-32所示,AS65001内部相邻的设备间建立IBGP邻居关系。其中DeviceB和DeviceC的Router ID分别是2.2.2.9和3.3.3.9,DeviceB和DeviceC都被配置成RR,DeviceD和DeviceE分别是它们的客户机。DeviceD和DeviceE上BGP引入路由10.1.4.0/30。
上述部署完成后,在DeviceA上执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 10.1.3.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.4.0/30 10.1.5.2 0 100 0 i * i 10.1.2.2 0 100 0 i
从以上显示信息可以看出,到达10.1.4.0/30存在两条路由。而DeviceA优选了DeviceC发布的路由。
[~DeviceA] display bgp routing-table 1.1.1.9
BGP local router ID : 10.1.3.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.1.4.0/30: From: 10.1.3.2 (3.3.3.9) Route Duration: 00h00m01s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/0/1 Original nexthop: 10.1.5.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best, select, pre 255, IGP cost 2 Originator: 10.1.4.1 Cluster list: 0.0.0.3 Not advertised to any peer yet BGP routing table entry information of 10.1.4.0/30: From: 10.1.1.2 (2.2.2.9) Route Duration: 00h00m17s Relay IP Nexthop: 10.1.1.2 Relay IP Out-Interface: GigabitEthernet0/0/0 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path Nil, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 255, IGP cost 2, not preferred for router ID Originator: 10.1.4.2 Cluster list: 0.0.0.2 Not advertised to any peer yet
从以上显示信息可以看出,来自DeviceB的路由因为Router ID被淘汰。但是从以上显示信息还可以看出DeviceB的Router ID是2.2.2.9,而DeviceC的Router ID是3.3.3.9,如果是比较Router ID,则来自DeviceB的路由应该是优选路由,回显信息似乎前后矛盾。实际上如果路由携带Originator_ID属性,则选路过程中将比较Originator_ID的大小(不再比较Router ID),并优选Originator_ID最小的路由。从以上显示信息可以看出来自DeviceB的路由的Originator_ID是10.1.4.2,而来自DeviceC的路由的Originator_ID是10.1.4.1,所以来自DeviceC的路由成为优选路由。
DeviceA从DeviceB和DeviceC学习到的路由属性对比如表10-28所示。
路由属性 |
从DeviceB学习到的路由 |
从DeviceC学习到的路由 |
比较结果 |
---|---|---|---|
协议首选值(PrefVal) |
0 |
0 |
相同 |
本地优先级(Local_Pref) |
100 |
100 |
相同 |
Route type |
从邻居学习而来 |
从邻居学习而来 |
相同 |
AIGP |
- |
- |
相同 |
AS_Path |
- |
- |
长度相同 |
Origin |
IGP |
IGP |
相同 |
MED |
0 |
0 |
相同 |
Peer Type |
IBGP |
IBGP |
相同 |
IGP Cost |
2 |
2 |
相同 |
Cluster_List |
0.0.0.2 |
0.0.0.3 |
长度相同 |
Originator_ID |
10.1.4.2 |
10.1.4.1 |
从DeviceC学习的路由更优 |
通过上述分析可以发现,分析路由因Router ID而落选的原因时还需要考虑Originator_ID的因素,否则分析结果可能不全面。
Router ID
存在到达同一目的地址的多条路由时,BGP优选Router ID最小的设备发布的路由。
- router-id { ipv4-address | vpn-instance auto-select }。如果没有配置router-id(BGP)命令,则BGP会自动选取系统视图下的Router ID作为BGP协议的Router ID。
- BGP VPN实例IPv4/IPv6地址族视图下可以使用router-id(BGP) { ipv4-address | auto-select }配置Router ID,router-id(BGP VPN实例IPv4/IPv6地址族视图)命令优先级比router-id(BGP)高。
此外,还需要注意以下规则对BGP选路的影响:如果路由携带Originator_ID属性,选路过程中将比较Originator_ID的大小(不再比较Router ID),并优选Originator_ID最小的路由。缺省情况下,BGP在选择最优路由时在Cluster-List之后比较Originator-ID。配置bestroute routerid-prior-clusterlist命令后,BGP在选择最优路由时在Cluster-List之前比较Originator-ID。
对等体地址
优选从具有较小IP地址的对等体学来的路由。
对等体地址是指peer { group-name | ipv4-address | ipv6-address } as-number { as-number-plain | as-number-dot }命令中通过ipv4-address和ipv6-address参数指定的地址。此外,用户使用peer { ipv4-address | ipv6-address } group group-name将对等体加入对等体组时已经指定了对等体地址,所以group-name参数指定的对等体地址由peer group (BGP)指定。
如果BGP在比较对等体地址之前还没有选出最优路由,则表明本设备和另外一台设备之间通过等价链路建立了多个BGP邻居关系。一般情况下,在两台设备之间存在用于备份的物理链路时,推荐使用Loopback接口来建立BGP邻居,但是实际上,两台设备之间通过多个物理链路建立多个BGP邻居关系也不违反协议规定。
在DeviceA上进行以下配置:
# bgp 65001 peer 10.1.1.2 as-number 65002 peer 10.1.2.2 as-number 65002 # ipv4-family unicast peer 10.1.1.2 enable peer 10.1.2.2 enable #
在DeviceB上进行以下配置:
# bgp 65002 peer 10.1.1.1 as-number 65001 peer 10.1.2.1 as-number 65001 # ipv4-family unicast network 2.2.2.9 255.255.255.255 peer 10.1.1.1 enable peer 10.1.2.1 enable #
完成上述配置后,执行display bgp routing-table [ ip-address ]命令验证配置结果。
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table
BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 2.2.2.9/32 10.1.1.2 0 0 65002i * 10.1.2.2 0 0 65002i
从以上显示信息可以看出,路由表中存在两条2.2.2.9/32路由,其中下一跳是10.1.1.2的路由是优选路由。
[~DeviceA] display bgp routing-table 2.2.2.9
BGP local router ID : 192.168.2.3 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 2.2.2.9/32: From: 10.1.1.2 (192.168.2.4) Route Duration: 00h19m10s Direct Out-interface: GigabitEthernet1/0/5 Original nexthop: 10.1.1.2 Qos information : 0x0 AS-path 65002, origin igp, MED 0, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.1.2 10.1.2.2 BGP routing table entry information of 2.2.2.9/32: From: 10.1.2.2 (192.168.2.4) Route Duration: 00h19m05s Direct Out-interface: GigabitEthernet1/0/10 Original nexthop: 10.1.2.2 Qos information : 0x0 AS-path 65002, origin igp, MED 0, pref-val 0, valid, external, pre 255, not preferred for peer address Not advertised to any peer yet
从以上显示信息可以看出,下一跳是10.1.1.2的路由由于对等体地址较小而成为优选路由。