技术分享

您当前所在的位置:首页>>技术分享

实验—BGP的十三条选路

1、实验需求:
测试BGP路由的选路的13条

2、拓扑:

3.配置以及现象:

一.Weight
a.修改的weight值仅在本地路由器上有效,weight的值越大越优先;
b.本地发布的路由weight值为32768,学习来的为0;
c.只可以在in方向设置;
d.可以使用①nei x.x.x.x weight xx ②router-map 配置

配置:

方法1:

R1(config-router)#router bgp 100
R1(config-router)#nei 2.2.2.2 weight 11

方法2:

R1(config)#access-list 1 permit 3.3.3.0
R1(config)#route-map W
R1(config-route-map)#match ip add 1
R1(config-route-map)#set weight 11
R1(config-route-map)#ex
R1(config)#route-map W permit 999  ❶
R1(config-route-map)#router bgp 100
R1(config-router)#nei 2.2.2.2 route-map W in  ❷

批注:
❶放行其他路由
❷Weight只能在in方向做

配置前:

修改后:

二.Local preference
a. LP值越大越优先,默认情况下本地始发路由LP值为100;
b.可以在in/out方向配置;
c.只可以在IBGP中传播,不能在EBGP中传播;
b.用bgp default local-preference xx修改默认值;
 

R2(config)#access-list 1 permit 1.1.1.0
R2(config)#route-map L
R2(config-route-map)#match ip add 1
R2(config-route-map)#set local-preference 101 ❶
R2(config-route-map)#ex
R2(config)#route-map L permit 999
R2(config-route-map)#router bgp 200
R2(config-router)#nei 2.2.2.2 route-map L in

批注:
❶修改lp值为101

修改前:

修改后:

修改后可以看到在weight值相同的情况下LP值越大的成为了最优路径。

三.本地起源
a. next-hope为本地(0.0.0.0)时是最优路径;
b.优先顺序:network>redistribute>aggregate
在R2上创建一条指向null0的路由发布到BGP中,可以看到R3收到三条路由中,最优路径为本地起源(0.0.0.0)的。

R2(config)#ip route 3.3.3.0 255.255.255.0 null 0
R2(config-router)#router bgp 200
R2(config-router)#net 3.3.3.0 ma 255.255.255.0

为了排除weight的影响将另外两条路由的weight也改为32768,发现依然是本地起源为最优路径如下图所示。

R3(config)#router bgp 100
R3(config-router)#nei 13.1.1.1 weight 32768
R3(config-router)#nei 23.1.1.2 weight 32768

四.As-path
a.长度最短的AS-path为最优路径,仅在EBGP有效;
b.as-path prepend和last-as 一起配置last-as会先生效;
c.在向EBGP邻居通告路由时,将自己的AS号加在As-path的最左端;
d.可以对EBGP邻居的in/out方向使用route-map,in方向做加在本来的AS号的左边,out方向做加在本来AS号的右边;
e.bgp bestpath as-path ignore可以跳过选路原则

配置:

R2(config)#access-list 1 per 2.2.2.0
R2(config)#route-m AS ❶
R2(config-route-map)#match ip add 1
R2(config-route-map)#set as-path prepend 200 200 200 200 ❷
R2(config)#route-m AS per 999
R2(config)#router bgp 200
R2(config-router)#nei 23.1.1.3 route-map AS ou t  ❸ 

R3(config)#access-list 1 permit 2.2.2.0
R3(config-route-map)#match ip add 1
R3(config)#route-map AS
R3(config-route-map)#set as prepend 200 200 200 ❹
R3(config)#route-map AS permit 999
R3(config)#router bgp 100
R3(config-router)#nei 13.1.1.1 route-m AS in

注释:
❶用route-map实现增加as-path长度
❷增加4个AS号,一般情况下使用本AS号来避免环路和对后续AS的干扰
❸调用route-map在out方向
❹增加3个AS号

排除了weight,local preference,本地起源的影响后可以看到AS path越短的越优先。

五.Origin属性
a.三种不同origin属性的优先顺序:IGP>EGP>incomplete;
b. Origin属性会一直在BGP路由中携带;
c.使用重分布(incomplete)进BGP时,在路由表中用“?”表示,而network和aggregate产生的路由表标识为“i”;

配置:

R2(config)#access-list 2 permit 3.3.3.0
R2(config)#route-map origin
R2(config-route-map)#mat ip add 2
R2(config-route-map)#set origin incomplete
R2(config)#route-map origin permit 999
R2(config)#router bgp 200
R2(config-router)#nei 23.1.1.3 route-map origin in

修改后可以看到在路由表最后一栏path中下一跳为23.1.1.3的路由被修改为origin,在此时带有“i”标识的为最优,由于weight值,local preference,本地起源因素都可以排除,可以发现是该属性影响了选路

六.MED
a.MED值越小越优先,默认为0;
b.一般情况下路由器只比较来自同一AS中的MED值,若非得比较则使用bgp always-compare-med命令;
c.本地network产生的BGP条目会带上IGP的metric,会传给所有邻居;
d.从IBGP邻居学习到的BGP条目的metric值不会传递给其他EBGP邻居;
e.只有在AS序列中第一个AS号相同时,才会进行MED比较
f. bgp bestpath med missing-as-worst将MED值设为最大值;

R2(config)#access-list 2 permit 3.3.3.0
R2(config)#route-map med
R2(config-route-map)#match ip add 2
R2(config-route-map)#set metric 10 ❶
R2(config-route-map)#ex
R2(config)#route-map med permit 999
R2(config)#route-map MED
R2(config-route-map)#match ip add 2
R2(config-route-map)#set metric 20
R2(config-route-map)#ex
R2(config)#route-map MED per 999
R2(config)#router bgp 200
R2(config-router)#nei 23.1.1.3 route-map med in ❷
R2(config-router)#nei 1.1.1.1 route-map MED in

注释:
❶创建不同metric值的route-map
❷分别在两个不同邻居in方向调用route-map

修改前3.3.3.0最优路径为EBGP邻居R1传来的修改后为R3,这是由于R1的metric值较大,R3metric值较小引起的。

七.EBGP优于IBGP
该属性并不是由于EBGP的AD小于IBGP而是邻居类型
优先级:EBGP>联邦EBGP>IBGP

八. 最近的IGP邻居
该属性指的是去往BGP邻居所用的IBGP路由metric值,该属性适用于EBGP和IBGP



上图所示R3收到的路由分别来自R1和R2,这时候可以排除weight,local preference,本地起源,AS path,Origin,MED和EBGP优于IBGP的影响,查看如下ospf的路由表可以看到影响到路由选路的因素是由于R3到达R1的开销11<R2 的开销21。

九.BGP等价负载均衡
a.使用maximum-path x来配置等价负载均衡,取值为2-6;
b.如果不关联IBGP关键字只会对EBGP路由执行等价负载均衡;
c.如果不配置maximum-path,则默认关闭进行下一条选路原则;

R4(config)#router bgp 200
R4(config-router)#maximum-paths 2 ❶ 

注释: ❶修改为负载均衡,这条命令在实验中没有出效果是啥回事

十.最老的EBGP邻居
a.当前9条比较结果相同时且参与比较的路由都是为EBGP路由时,会根据EBGP路由安装进BGP路由表的先后顺序进行优选,先安装的会被优选;
b.使用bgp bestpath compare-routerid命令可以忽略本原则直接比较下一个原则

如下图所示最优路径为R2,中断R2和R3邻居关系再恢复后最优路径变为R1,再中断R1和R3邻居关系再恢复此时又变成了R2,因此可以判断是最老EBGP邻居发挥了选择最优路由的作用。


断开R3与R2邻居


断开R3与R1邻居

十一、最低的router-id

拓扑:

a. router-id越小越优先;
b.在有RR的情况下不比邻居的router-id而是originator-id代替router-id在选路中起作用

可以看到next-hope为1.1.1.1的路径为最优,为了确保是最小的router-id在选路过程中起了作用,因此将R1的router-id设置为比R2大。如下图所示最优路径发生了变化,变成了router-id较小的R2

R1(config)#router bgp 100
R1(config-router)#bgp router-id 111.1.1.1 ❶

注释:
❶修改较大的router-id确定是其在发挥作用

十二、Cluster-list长度最短的
a. cluster-list长度越小越优先;
b.只有在RR的环境下才会进行cluster-list长度的对比,RR在执行路由反射动作时会将自己的cluster-id添加在cluster-list中;

拓扑:

R4(config)#router bgp 100
R4(config-router)#nei 1.1.1.1 route-reflector-client ❶
R5(config)#router bgp 100
R5(config-router)#nei 6.6.6.6 route-reflector-client ❷

注释:
❶R4上做RR使R1成为客户端
❷再在R5上做RR将6做成客户端

由于存在RR此时比较的是Originator-ID而非router-id所以这里不考虑router-id的影响,可以看到来自4.4.4.4的cluster-list更短。

 

十三、最小邻居地址

拓扑:


 

a.BGP优先选择来自于最低的邻居地址的路径,是BGP的neigbor配置中的地址

R4(config)#router bgp 100
R4(config-router)#nei 1.1.1.1 route-reflector-client ❶
R3(config)#router bgp 100
R3(config-router)#nei 1.1.1.1 route-reflector-client

注释:
❶做RR使1.1.1.1为客户端

在R3和R4上做了RR后忽略第11条最小router-id, cluster-list都是最短,因此第13条最小邻居发挥选路作用。


上一篇:vi/vim多行注释和取消注释

下一篇:如何快速学习SQL命令