文章目录
- 一、BGP的选路规则
- 二、详细验证
- 1,weight权重大优
- 2,本地优先级大优
- 3,本地起源最优先
- 4、经过的AS最少最优
- 5、起源码小优
- 6、MED最小
一、BGP的选路规则
比较前提–同步被关闭、下一跳可达,均可优,路由不被惩罚
1、weight权重,大优,只在本地路由器,不传递,便于人为干涉选路,Cisco私有,默认32768;
2、local-preferene本地优先级,大优,只在一个AS内的IBGP邻居传递,默认100;
3、本地起源最优先,即next-hop为0.0.0.0时最优先,即本路由器引入的路由最优先;
4、as-path,经过的AS数量少优;
5、起源码最小,即i
优于e
优于?
;
6、MED值最小;
7、EBGP邻居关系优于IBGP邻居关系(联邦ebgp和ibgp相同);
8、最近的下一跳地址,即IGP表中metric值最小的;
9、若配置maximum-path,且存在多条等价路径,会同时进路由表,只是在路由表中表现为负载均衡
10、最老的路由(前提必须是external路由,联邦内的EBGP路由当做 IBGP处理)
11、最低的router-id
12、多条路径的始发router-id相同,那么选择cluster-list长度最短的
13、BGP优选来自最低邻居IP地址的路径(BGP的neighbor配置的那 个IP地址)
二、详细验证
R2、R3、R4运行ospf,R2、R3和R3、R4为ibgp邻居,R1、R2和R1、R4和R3、R5为ebgp邻居
R1上有两个环回1.1.1.0/24和1.1.2.0/24,且通告到bgp中,用于验证
1,weight权重大优
本地产生默认值为32768,学习到的为0,大优,范围为0-65535,且只在本地路由器有效,不传递,思科私有,便于人为快速干涉选路。-修改某个邻居发送给我的全部路由的weight值
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i1.1.1.0/24 2.2.2.2 0 100 0 1 i
* i 4.4.4.4 0 100 0 1 i
* i1.1.2.0/24 4.4.4.4 0 100 0 1 i
*>i 2.2.2.2 0 100 0 1 i
由于是学习到的路由,所以weight值为0,此时R3优选了R2发来的路由,我们在R3上将R4发来的路由weight改的大些
R3(config)#router bgp 234
R3(config-router)#neighbor 4.4.4.4 weight 100
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 1 i
*>i 4.4.4.4 0 100 100 1 i
*>i1.1.2.0/24 4.4.4.4 0 100 100 1 i
* i 2.2.2.2 0 100 0 1 i
在R2、R4上做了clear ip bgp * soft out
之后,R3优选了R4的路由,但这样将R4发来的所有路由weight都改大了-修改某个邻居发送给我的某些路由的weight值
先使用acl或prefix list抓取需要的路由,然后针对某个邻居调用route-map更改其weight值。
R3(config)#access-list 1 permit 1.1.1.0
R3(config)#route-map weight permit 10
R3(config-route-map)#match ip address 1
R3(config-route-map)#set weight 100
R3(config-route-map)#exi
R3(config)#route-map weight permit 20
R3(config-route-map)#exi
R3(config)#router bgp 234
R3(config-router)#neighbor 4.4.4.4 route-map weight in // 权重值不传播的特点,只能在本地的入口调用
R3(config-router)#en
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 1 i
*>i 4.4.4.4 0 100 100 1 i
* i1.1.2.0/24 4.4.4.4 0 100 0 1 i
*>i 2.2.2.2 0 100 0 1 i
2,本地优先级大优
默认值100,大优,仅在AS内的ibgp邻居之间传递。出了本AS,恢复默认值。-修改传递给所有邻居的本地优先级
例如,在R4上修改,则R4传给ibgp邻居R3的所有路由的本地优先级均被修改
R4(config)#router bgp 234
R4(config-router)#bgp default local-preference 200
R4#clear ip bgp * soft out
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 1 i
*>i 4.4.4.4 0 200 0 1 i
*>i1.1.2.0/24 4.4.4.4 0 200 0 1 i
* i 2.2.2.2 0 100 0 1 i
-修改传递给某个邻居的某些路由的本地优先级
先使用acl抓取路由,然后针对某个邻居调用route-map更改其本地优先级的值。
调用时,控制层面出或入口均可,但必须为IBGP邻居,这里再R3的in方向调用
R3(config)#access-list 1 permit 1.1.1.0
R3(config)#route-map local permit 10
R3(config-route-map)#match ip address 1
R3(config-route-map)#set local-preference 200
R3(config-route-map)#exi
R3(config)#route-map local permit 20
R3(config-route-map)#exi
R3(config)#router bgp 234
R3(config-router)#neighbor 4.4.4.4 route-map local in
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 1 i
*>i 4.4.4.4 0 200 0 1 i
* i1.1.2.0/24 4.4.4.4 0 100 0 1 i
*>i 2.2.2.2 0 100 0 1 i
3,本地起源最优先
当两条路由相同时,则next-hop为0.0.0.0时最优先,即本路由器引入的路由最优先;
R3学习到一条1.1.1.0/24的路由,假设现在R3宣告了自己的一个环回也是1.1.1.0/24,并且把R2传递过来的1.1.1.0/24的weight值改为32768,那么weight都是32768,local-preference都是100,则R3优选本地起源的路由
R3(config)#int lo1
R3(config-if)#ip address 1.1.1.1 255.255.255.0
R3(config)#router bgp 234
R3(config-router)#network 1.1.1.0 mask 255.255.255.0
R3(config-router)#neighbor 2.2.2.2 weight 32768
R3(config-router)#en
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
* i1.1.2.0/24 4.4.4.4 0 100 0 1 i
*>i 2.2.2.2 0 100 32768 1 i
4、经过的AS最少最优
as-path属性会记录经过的AS号,那么经过的AS最少最优,策略时只能在EBGP邻居关系间操作
再R1这里针对邻居R2人为给1.1.1.0/24的路由增加as号,那么R3优选R4,不优选R2
R1(config)#access-list 1 permit 1.1.1.0
R1(config)#route-map as permit 10
R1(config-route-map)#match ip address 1
R1(config-route-map)#set as-path prepend 5
R1(config-route-map)#exi
R1(config)#route-map as permit 20
R1(config-route-map)#exi
R1(config)#router bgp 1
R1(config-router)#neighbor 12.1.1.2 route-map as out
R1(config-router)#en
R1#clear ip bgp * soft out
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i1.1.1.0/24 4.4.4.4 0 100 0 1 i
* i 2.2.2.2 0 100 0 1 5 i
* i1.1.2.0/24 4.4.4.4 0 100 0 1 i
*>i 2.2.2.2 0 100 0 1 i
注意:
入口调用:生成的结果为 3 4 5 x ,X为实际经过的AS号;最左侧为最新的AS号;
出口调用: X 3 4 5
若人为添加的AS号,在网络后端真实存在,由于EBGP水平分割规则,将导致这些路由无法进入
可以通过重复添加已经经过的AS编号,来解决;R1(config-route-map)#set as-path prepend 1 1 1
5、起源码小优
即i
优于e
优于?
针对R2发给R3的1.1.1.0/24路由,我们把他的起源码改为?
,则R3优选R4的这条路由。
R2(config)#access-list 1 permit 1.1.1.0
R2(config)#route-map ori permit 10
R2(config-route-map)#match ip address 1
R2(config-route-map)#set origin incomplete
R2(config-route-map)#exi
R2(config)#route-map ori permit 20
R2(config-route-map)#exi
R2(config)#router bgp 234
R2(config-router)#neighbor 3.3.3.3 route-map ori out
R2(config-router)#en
R2#clear ip bgp * soft out
R3#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
* i1.1.1.0/24 2.2.2.2 0 100 0 1 ?
*>i 4.4.4.4 0 100 0 1 i
*>i1.1.2.0/24 2.2.2.2 0 100 0 1 i
* i 4.4.4.4 0 100 0 1 i
6、MED最小
默认没有以0看待,多出口鉴别属性,小优。
BGP没有度量值,出现度量值的情况
1,正常宣告路由时,携带本地到达目标的度量和下一跳;
2,将igp重发布到BGP时,若关闭了自动汇总,也携带本地到达目标的度量和下一跳;
MED做法就是人为在BGP的路由条目中给予一个度量值,来干涉选路;
最常用于干涉ebgp关系下选路,常常AS1用于干涉AS2对AS1的选路;
比如这里R3有一个环回,我AS234想要AS1只能通过R2来访问这个环回,那么我们需要在R2,R4出去的时候给这条路由增加不同的MED,让AS1的R1主动优选med小的R2
R2(config)#access-list 1 permit 3.3.3.0
R2(config)#route-map med permit 10
R2(config-route-map)#match ip address 1
R2(config-route-map)#set metric 10
R2(config-route-map)#exi
R2(config)#route-map med permit 20
R2(config-route-map)#exi
R2(config)#router bgp 234
R2(config-router)#neighbor 12.1.1.1 route-map med out
R4(config)#access-list 1 permit 3.3.3.0
R4(config)#route-map med permit 10
R4(config-route-map)#match ip address 1
R4(config-route-map)#set metric 20
R4(config-route-map)#exi
R4(config)#route-map med permit 20
R4(config-route-map)#exi
R4(config)#router bgp 234
R4(config-router)#neighbor 14.1.1.2 route-map med out
R1#sho ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
*> 1.1.2.0/24 0.0.0.0 0 32768 i
*> 3.3.3.0/24 12.1.1.2 10 0 234 i
* 14.1.1.1 20 0 234 i
可以看到R1优选了med小的R2,但实际上管理员不能操作其他AS的路由器来查看结果,所以我们使用ping扩展的路由记录来观察结果。
R3#ping
Protocol [ip]:
Target IP address: 1.1.1.1 //目标ip
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Source address or interface: 3.3.3.3 //源ip
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]: r //记录路由
Number of hops [ 9 ]:
Loose, Strict, Record, Timestamp, Verbose[RV]:
Sweep range of sizes [n]:
Type escape sequence to abort.
Reply to request 0 (36 ms). Received packet has options
Total option bytes= 40, padded length=40
Record route:
(34.1.1.1)
(14.1.1.1)
(1.1.1.1)
(12.1.1.1)
(23.1.1.1)
(3.3.3.3) <*>
(0.0.0.0)
(0.0.0.0)
(0.0.0.0)
End of list
我们看到数据回来时走的是R2.