您的位置:首页 > 其它

配置13条BGP选路原则

2013-03-04 14:52 302 查看


weight
R1和R2分别NETWORK192.12.1.0这个网段(用S2口连接的网段)。
R3的BGP表为:
Network Next Hop Metric LocPrf Weight Path
* 192.12.1.0 192.23.1.2 0 0 12 i
*> 192.13.1.1 0 0 12 i
通过修改WEIGHT使其优化下一跳为192.23.1.2这条路由。
R3上修改:
①.neighbor 192.23.1.2 weight 10,便会选择192.23.1.2这条路由,由于从别的路由器学来的路由的WEIGHT默认为0,自己通告的为32768,权重越大越好。
②.也可以通过ROUTE-MAP来修改:
ip prefix-list 12 seq 5 permit 192.12.1.0/24
route-map weight permit 10
match ip address prefix-list 12
set weight 10
neighbor 192.23.1.2 route-map weight in

local-preference
本地优先级用于在本AS内部传递。影响路由器的出站流量。默认优先级为100,越大越好。
R3通告3.3.3.3 (环回口)
R2的BGP表为:
* i3.3.3.0/24 192.13.1.3 0 100 0 30 i
*> 192.23.1.3 0 0 30 i
R1的BGP表为:
* i3.3.3.0/24 192.23.1.3 0 100 0 30 i
*> 192.13.1.3 0 0 30 i
通过修改LP,使其都优化下一跳为192.23.1.2这条路由。

在R2上修改:
bgp default local-preference 200
ip prefix-list 3 seq 5 permit 3.3.3.0/24
route-map lp permit 10
match ip address prefix-list 3
set local-preference 200
neighbor 192.23.1.3 route-map lp in
R1上还需要一条ip route 192.23.1.0 255.255.255.0 192.12.1.2 如果没有这条,192.23.1.3这个下一跳将不可达,路由无法优化。
通过修改后,BGP改为
R1:
*>i3.3.3.0/24 192.23.1.3 0 200 0 30 i
* 192.13.1.3 0 0 30 i
R2:
*> 3.3.3.0/24 192.23.1.3 0 200 0 30 i
R2之所以只有1条路由,是因为R1收到的192.13.1.3下一跳这个路由没有优化,没有传递给R2.

本地起源
关于本地起源的错误:
路由器本地始发的路径优先。在BGP的转发表里显示为0.0.0.0。

正确: (官方文档)

Prefer the path that was locally originated via a network or aggregate BGP subcommand or through redistribution from an IGP.Local paths that are sourced by the network or redistribute commands are preferred over local aggregates that are sourced by the aggregate-address command.
AS-PATH
评估AS-PATH的长度,越短的越优先。
在R2和R3上分别通告192.23.1.0
默认下R1上的BGP表
*>i192.23.1.0 192.12.1.2 0 100 0 i
* 192.13.1.3 0 0 30 i
由于这2条路由的权重,优先级,以及都不是起源于自己的,所以比较到第4步,AS-PATH的长度,下一跳为192.12.1.2这条更短。

起源代码
比较起源代码的大小,越小越优,I=0 E=1 ?=2 I>E>?
在R3通告3.3.3.0,R4学到后的BGP表如下:
* 3.3.3.0/24 192.14.1.1 0 12 30 i
*> 192.24.1.2 0 12 30 i
R4上的这条优化路由应该是通过EBGP最老的路由选出的。
下面通过修改起源代码来使R3选择192.14.1.1 这条路由优化。可以用ROUTE-MAP在入向或出向执行。

R2:
ip prefix-list 3 seq 5 permit 3.3.3.0/24
route-map or permit 10
match ip address prefix-list 3
set origin egp 90
neighbor 192.24.1.4 route-map or out

通过修改后R4的BGP表:
*> 3.3.3.0/24 192.14.1.1 0 12 30 i
* 192.24.1.2 0 12 30 e
R4选择了源头为I的路由,因为I优先于E。

MED(METRIC)
MED也叫metric,用于向外部邻居指出进入我本地AS的首选路径。一般在EBGP邻居之间传递。默认情况下,仅当路径来自来自同一个AS中的不同邻居时,路由器才比较它们的MED属性。除非打上了bgp always-compare-med,则可以比较来自不同AS的路径的MED属性。MED默认为0,越小越好。
在R1和R2上都通告192.12.1.0
R3的BGP表为:
* 192.12.1.0 192.23.1.2 0 0 12 i
*> 192.13.1.1 0 0 12 i
通过修改MED值,来使R3选择下一跳为192.23.1.2的这个路由优化。

R1:
ip prefix-list 12 seq 5 permit 192.12.1.0/24
route-map med permit 10
match ip address prefix-list 12
set metric 100
neighbor 192.13.1.3 route-map med out
R3的BGP表变为:
*> 192.12.1.0 192.23.1.2 0 0 12 i
* 192.13.1.1 100 0 12 i
此时R1传过来的这条路由MED值变成了100,而R2还是默认0,所以选择了MED小的路由。
Default-metric 这条命令影响的只是本地,比如默认情况下为0,当打了这条命令后,所有的路由默认度量值改为你设置的值。这条命令好像没什么作用。

EBGP优于IBGP
EBGP>联邦EBGP>IBGP
在R3上通告3.3.3.0
R1上的BGP表:
*> 3.3.3.0/24 192.13.1.3 0 0 30 i
* i 192.23.1.3 0 100 0 30 i
R2上的BGP表:
* i3.3.3.0/24 192.13.1.3 0 100 0 30 i
*> 192.23.1.3 0 0 30 i
R1和 R2都选择了EBGP邻居来的路由,因为EBGP优于IBGP。前提:前6条比较条件必须相同,才会比较到第7条。

最近的IGP邻居。
选择经过最近的IGP邻居的路径,将BGP表中的下一跳进行对比,度量值最小的优先。一般这些比较的路由要都是IBGP邻居得到的。
在R1,R2,R3上分别运行OSPF。
现在将R4划分到AS 12中,R3通告3.3.3.0,R4的BGP表为:
* i3.3.3.0/24 192.23.1.3 0 100 0 30 i
*>i 192.13.1.3 0 100 0 30 i
这里的这条优化路由是R4通过最小的ROUTE-ID选出的。
在这里,要求通过修改IGP的METRIC,来让R4选择下一跳为192.23.1.3这个路由。
R4:
interface Serial0/0
ip ospf cost 20
路由表:
O 192.23.1.0/24 [110/1582] via 192.24.1.2, 00:02:25, Serial0/0
O 192.13.1.0/24 [110/3124] via 192.14.1.1, 00:02:25, Serial0/1
BGP表:
*>i3.3.3.0/24 192.23.1.3 0 100 0 30 i
* i 192.13.1.3 0 100 0 30 i
由于到达下一跳192.23.1.3的度量值最小,所以R4选择了这条路由。

如果配置了maximum-path【IBGP】N,如果存在多条等价的路由,会插入多条路由。
BGP默认的MAXI值为1,只能有一条最优路由。要实现负载均衡的条件必须是上面8条都没有比出哪条最优的情况下,才有可能出现负载。若没有打这条命令,将会跳过这条,继续往下比下面的条目。这条命令只对从EBGP邻居学来的路由起作用,IBGP无效。做有负载后,在BGP表里还是一个最优,但在路由表里有2个下一跳。
在R4上通告4.4.4.0
此时R3的BGP表为:
* 4.4.4.0/24 192.13.1.1 0 12 i
*> 192.23.1.2 0 12 i
这是通过最老的EBGP邻居选出的路由
在R3上配置了maximum-path 2后,BGP变为:
*> 4.4.4.0/24 192.13.1.1 0 12 i
* 192.23.1.2 0 12 i
路由表为:
B 4.4.4.0 [20/0] via 192.13.1.1, 00:00:16
[20/0] via 192.23.1.2, 00:00:16
这里出现一个很奇怪的现象,当我配置MAXI命令后,为什么在BGP表中最优的下一跳发生了改变,从192.23.1.2变成了192.13.1.1,如果不是比第10条最老的EIGRP,那这条最优路由又是如何得出的?

最老的EBGP邻居学来的路由。
在R4上通告4.4.4.0
此时R3的BGP表为:
* 4.4.4.0/24 192.13.1.1 0 12 i
*> 192.23.1.2 0 12 i
我将邻居192.13.1.1比192.23.1.2后建立,这是通过最老的EBGP邻居选出的路由,对于EBGP在这里肯定会选出一条最优的路由,因为邻居的建立不可能达到同时。

最低的ROUTE-ID
BGP优选来自具有最低的路由器ID的BGP路由器的路由。这条好像专门针对IBGP提出的。
R3通告3.3.3.3
此时R4上的BGP表为:(R4和R1,R2为IBGP邻居)
*>i3.3.3.0/24 192.14.1.1 0 100 0 30 i
* i 192.24.1.2 0 100 0 30 i
192.14.1.1 from 192.14.1.1 (1.1.1.1)
192.24.1.2 from 192.24.1.2 (2.2.2.2)
下一跳192.14.1.1的路由器的ROUTE-ID为1.1.1.1,更小,所以选择它。
通过修改R1的ROUTE-ID改大,来让R4选择192.24.1.2这个路由最优。
R4:
* i3.3.3.0/24 192.14.1.1 0 100 0 30 i
*>i 192.24.1.2 0 100 0 30 i
192.14.1.1 from 192.14.1.1 (5.5.5.5)
192.24.1.2 from 192.24.1.2 (2.2.2.2)
如果路径包含RR属性,那么在路径选择过程中,就用originator-id来替代路由器ID。

若多条路由的始发路由器的ID相同,那么选择CLUSTER_LIST长度短的,因为每经过一个RR,会将在CLUSTER-LIST中加入自己的ROUTE-ID。
需要换一个TOPOLOGY图



所有路由器都在同一个AS 1 中。在R2上通告2.2.2.0,所有路由器上都运行EIGRP。
R3指R4为自己的反射器客户;R1指R5为自己的反射器客户,R5指R4为自己的反射器客户。
最终R4上的BGP表为:
*>i2.2.2.0/24 192.23.1.2 0 100 0 i
* i 192.12.1.2 0 100 0 i
Local
192.23.1.2 (metric 2681856) from 192.34.1.3 (3.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal, best
Originator: 2.2.2.2, Cluster list: 192.34.1.3
Local
192.12.1.2 (metric 2681856) from 192.45.1.5 (5.5.5.5)
Origin IGP, metric 0, localpref 100, valid, internal
Originator: 2.2.2.2, Cluster list: 192.45.1.5, 192.15.1.1
多条路由的始发路由器ID相同,这里用originator-id来替代路由器ID。那么选择最短的Cluster list,这里选择为下一跳为192.23.1.2这条路由。

配置:
R1:
router eigrp 90
network 192.12.1.0
network 192.15.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp cluster-id 3222208769
bgp log-neighbor-changes
neighbor 192.12.1.2 remote-as 1
neighbor 192.15.1.5 remote-as 1
neighbor 192.15.1.5 route-reflector-client
no auto-summary

R2:
router eigrp 90
network 192.12.1.0
network 192.13.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
neighbor 192.12.1.1 remote-as 1
neighbor 192.23.1.3 remote-as 1
no auto-summary

R3:
router eigrp 90
network 192.23.1.0
network 192.34.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp cluster-id 3223453955
bgp log-neighbor-changes
neighbor 192.23.1.2 remote-as 1
neighbor 192.34.1.4 remote-as 1
neighbor 192.34.1.4 route-reflector-client
no auto-summary

R4:
router eigrp 90
network 192.34.1.0
network 192.45.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp cluster-id 3224174852
bgp log-neighbor-changes
neighbor 192.34.1.3 remote-as 1
neighbor 192.45.1.5 remote-as 1
no auto-summary

R5:
router eigrp 90
network 192.15.1.0
network 192.45.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 5.5.5.5
bgp cluster-id 3224174853
bgp log-neighbor-changes
neighbor 192.15.1.1 remote-as 1
neighbor 192.45.1.4 remote-as 1
neighbor 192.45.1.4 route-reflector-client
no auto-summary

如果BGP路由器的ID相同,如果有CLUSTER-LIST话,若也相同,则要比较IP地址最小的路由,是BGP的NEIGHBOR命令中的那个地址。



现在改变拓扑结构,取消R3到R4和R4到R5的IBGP邻居关系。建立R3-R5的IBGP邻居关系。
在R2上通告2.2.2.0,R3上指定R5为反射器客户端,R1指定R5为反射器客户端,
此时R5的BGP表为:
* i2.2.2.0/24 192.23.1.2 0 100 0 i
*>i 192.12.1.2 0 100 0 i
Local
192.23.1.2 (metric 2681856) from 192.34.1.3 (3.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
Originator: 2.2.2.2, Cluster list: 192.34.1.3
Local
192.12.1.2 (metric 2681856) from 192.15.1.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, valid, internal, best
Originator: 2.2.2.2, Cluster list: 192.15.1.1
针对2.2.2.0 这2条路由的Originator:-ID和Cluster list长度都一样,这时就会比较最后一步,我NEIGHBOR命令中IP地址最小的那个,最终选择了邻居地址为192.15.1.1这条路由,因为其IP地址最小。

此配置命令只与上面的R1和R3的不同:
R1:
router eigrp 90
network 192.12.1.0
network 192.15.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp cluster-id 3222208769
bgp log-neighbor-changes
neighbor 192.12.1.2 remote-as 1
neighbor 192.15.1.5 remote-as 1
neighbor 192.15.1.5 route-reflector-client
no auto-summary

R3:
router eigrp 90
network 192.23.1.0
network 192.34.1.0
no auto-summary
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp cluster-id 3223453955
bgp log-neighbor-changes
neighbor 192.23.1.2 remote-as 1
neighbor 192.45.1.5 remote-as 1
neighbor 192.45.1.5 route-reflector-client
no auto-summary

综合这13条选路原则,证明BGP无论如何都会选出一条最优的路由。证明了BGP运用在SP环境中,是需要高可靠信的,一定要提供一条最好的路由。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: