BGP属性:

BGP一共有11种属性,分别是:weight(权重值)、origin(起源)、AS_path、next-hop(下一跳)、local_pref(本地优先级)、MED(metric)、atomic_aggregate(汇总)、Aggregator(汇总者)、community(团体)、orginator_id、cluster_lis;

针对属性的特点可以将属性分为4类,分别是:

  1. 公认必尊 --必须传递且必须识别,所有 BGP 路由器必须识别遵守的属性有:

originas_pathnext_hop

2、公认可尊--必须识别,所有路由器都能识别但是不一定要遵守,                                        local_prefatomic_aggregate

3、可选传递--不是所有 BGP 路由器都能识别,但是所有 BGP 都能传递:aggregator community

4、可选非传递--不是所有路由器都能识别,不能识别的 BGP 路由器就丢弃它:

MEDoriginator_id cluster_idweight

 

接下来针BGP所有的属性进行详细讲解:

  1. weight—cisco私有属性,对于离开AS的路由在路由器选择哪一条最优,本台路由器产生为32768,学习邻居的为0;不传递,越大越优;适用于一台路由器在多条路径下的选路,无视邻居属性,EBGP/IBGP均适用;  Weight值修改只能影响本地路由器

修改方式:

  1)针对某邻居传递的所有流量:

   R1(config)#router bgp 1

   R1(config-router)#neighbor 2.2.2.2 weight 1   //从该邻居处学到的所有路由条目weight值修改为1,不传递;

  2)Router-map——针对部分流量

抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map weight permit 10
r1(config-route-map)#
r1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set weight 1                    //设置weight值为1
r1(config)#route-map weight permit 20                //空表,匹配其他路由条目
r1(config-route-map)#exit
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map weight in  //调用时必须是in,因为weight值不传递
软请:r1#clear ip bgp * soft      
 
1. Origin(起源)——起源属性,标识该路由的来源方式,0表示宣告(i),1表示EGP学到(E),2表示其他手段得到(重发布?),选择规则:越小越好(i>E>?),该手段一般不使用,
 修改方式:
  抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:  r1(config)#route-map org permit 10
r1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set origin egp 2              
r1(config)#route-map org permit 20
r1(config-route-map)#exit
调用:  r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map org in/out
软重启:r1#clear ip bgp * soft

 

3、AS_path——用于记录一条路由在传递过程中经过的AS(不算自己),顺序是最近经过的AS排在前面,上一个AS拒绝接受携带自己AS号的路由,可用于选路(优先经过AS数量少的路径),可用来防环(EBGP水平分割);

1)修改方式:

抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map as permit 10
r1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set as_path prepend 1 1 1 1   //重复添加经过的AS号
r1(config)#route-map as permit 20
r1(config-route-map)#exit
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map  as  in/out   //进方向均可出
软请:r1#clear ip bgp * soft

一般在选路当中会选择重复添加已经过的AS,一般不会添加没有经过的AS;适用于任何邻居之间,调用时in/out均可;

2)打破防环机制:——适用于某些特定需求

r1(config-router)#neighbor 2.2.2.2 allowas-in   //允许和具有自己相同AS的路由进入【用于本路器】

r1(config-router)#neighbor 2.2.2.2 as-override  //把具有和其他AS相同AS的路由放入这个AS【邻居路由器使用】

4、next-hop——到达路由的下一跳路由器ip地址,IBGP之间传递时next-hop不变,为0时会修改为更新源地址,EBGP之间传递路由时next-hop自动修改为更新源地址;

选路规则:下一跳为0的优于其他

修改方式:

抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map K permit 10
r1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set next-hop 12.1.1.1      //修改下一跳
r1(config)#route-map as permit 20
R1(config-route-map)#exit
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map K in/out  //邻居无所谓,进出方向均可
软清:r1#clear ip bgp * soft

 

5、local_pref——与weight一样为纯选路属性;

不能在EBGP邻居传递,可以在ibgp邻居之间传递越大越优(默认100),常用于当本as有多个出口路由器时,选择local_pref值大的路由器作为出口路由器,也可以到达一个网段有多个出口路径时,选择loca_prefl值大的路径;

修改方式:

1)修改本路由器的默认local_pref值,本地发出给IBGP邻居的的所有路由条目的优先级均修改:
   r1(config-router)#bgp default local-preference 101   
2)通过route-map修改某路由的local_pref值,EBGP只能在in方向(因为Ebgp邻居之间不能传递),IBGP可以是in/out均可
 
抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map local permit 10
r1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set local_preference 101       //修改本地优先级
r1(config)#route-map as permit 20
r1(config-route-map)#exit
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map  local  in/out  //ebgp邻居只能是in方向,IBGP邻居可以是in/out均可
软清:r1#clear ip bgp * soft

6、MED——选路属性,本质是metric,默认为0

    一般只能用于干涉同一个AS发出路由的不同路径的MED值比较;可以在两个AS之间传递,不能传递给第三个AS;一般用于影响对方AS的选路,用于AS1干涉其他AS对自己的选路;如果修改本AS选路等同于local_pref( 注意MED不能在路由器修改默认值);

修改方式:

抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map med permit 10
R1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set metric 2      //加大metric值
r1(config)#route-map as permit 20
r1(config-route-map)#exit  
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map  local  in/out 
r1(config-router)#Bgp always-compare-med   //开启比较不同AS的MED

7、atomic_aggregate用来警告下游路由器聚合后产生的路由路径丢失,表示了该路由为聚合路由,丢失了某些属性,所以此路由可能是不精确,并且接收到该路由器的路由若需要发送该路面的明细路由,自动被抑制。

 路由器在执行最佳路径决策进程时,始终选择明细路径。但是在宣告路由时,可以通过 以下 BGP 配置选项来处理重叠路由:

·      同时宣告明细路由和较不明细的路由;

·      仅宣告明细路由;

·      仅宣告路由中的非重叠部分;

·      聚合这两条路由并宣告聚合路由;

·      仅宣告较不明细的路由;

·      不宣告任一条路由。

 

8、Aggregator

  用来通告汇总路由器的BGR_ID(cisco),方便找出汇总者;

 

9community(团体属性)——为了更好地标识BGP路由,标识为x:y;

  Standard(做路由标识),extended(MPLS VPN),可读性好;

  团体值的设置不能在ebgp之间(ibgp可以),它的传递可以在ibgp之间也可以在ebgp之间;

 

【1】设置

1)标识设置

抓流量:r1(config)#ip prefix-list a permit 10.1.12.0/24
创建:r1(config)#route-map com permit 10
R1(config-route-map)#match ip address prefix-list a
r1(config-route-map)#set community 2:100   //添加标识
r1(config)#route-map as permit 20
r1(config-route-map)#exit  
调用:r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map com in/out

2)传递设置——传递团体值得开关(团体属性需要传递时必须开启该指令)

r1(config-router)#Neighbor  x.x.x.x  send-community both/standard/extend 

  1. 匹配设置
r1(config)#ip community-list ?                       //专用的community匹配工具
  <1-99>     Community list number (standard)
  <100-500>  Community list number (expanded)
  expanded   Add an expanded community-list entry
  standard   Add a standard community-list entry
r1(config)#Ip community-list expanded K permit 111    //使用正则表达式进行匹配

使用 community匹配之后用route-map调用即可;

4)查看:

Shoe ip bgp 10.1.1.1   //查看路由详情中可以查看到团体值

r1#Show IP bgp community   //查看所有团体值得路由

r1#Show IP bgp community 111   //查看某团体值得所有路由

【2】子属性——在某些特定的情况下,设置该属性可以达到某种需求(实现过滤);

1)iinternet  默认属性,可以给任何bgp发送,不对携带团体值的路由做任何限制;

2)No_export 只能在一个AS内传递,可以在联盟内传递,该属性是限制携带团体值的路由           传递给ebgp邻居,联盟的ebgp除外;

3)No_advertise 不在ibgp、ebgp邻居间传递;即禁止传递给任何邻居;

4)Local-as  不向任何ebgp邻居发送团体值,包括联盟的ebgp邻居;

 

10、originator_id——反射器使用,

记录所有路由器传递过来的RID,如果路由发起者在该属性里看到自己的RID,则说明有环路,就忽略该路由;

 

11、cluster-list——反射器使用

   是路由反射器簇ID 的一个序号,如果反射器在属性里看到自己的簇ID就说明有环路,则忽略该路由,簇ID列表:记录了所有反射器的RID;

 

 

BGP选路原则

选路的前提是该路由必须是优的;

BGP不优的情况:

BGP路由表中BGP的下一跳不可达(原因在于递归失败);

如果开启了BGP的同步,在没有同步的情况下BGP路由不优;

同步问题——早先为了解决BGP非直连建邻下的路由黑洞问题(将IGP重发布进BGP);检查BGP的路由有没有在IGP中,方法是调用路由表查看IGP中是否有BGP的路由条目;该限制可以关闭,IOS版本12.2以上默认关闭;

 

*标示可用,当*被r取代时,表示在路由表中不优,不加表,管理距离有劣势;

BGP 的选路规则:

BGP属性有几个 bgp常见属性_动态路由

 

  1. weight——首先比较 weight,大优,不传递,Cisco 私有,本地默认 32768,邻居为0;                                                                                                                   EBGP/IBGP
  2. local_pref——比较本地优先级,默认 100;仅 IBGP 邻居传递,大优                                                                                                                    IBGP 优选
  3. next-hop——本地下一跳

    4、AS_path——比较 as-pash,经过的 AS 数量少优,EBGP 邻居可增添                                                                                                                   EBGP/IBGP

    5、origin——起源码最小 i-igp=0 e-egp=1 ?=2                                                                                                              EBGP/IBGP

6、MED——MED 值最小,影响对方选路,作用于两个 AS 之间                                                                                                                   EBGP/IBGP

7、普通的 EBGP 邻居优于联邦内 EBGP 邻居优于 IBGP 邻居

8、优选最近的 IGP 邻居(IGP 度量小)

9、最先建邻的EBGP——判断最早建邻的EBGP邻居

10、最小 BGP 邻居的 RID;

11、最小建邻地址的邻居;

BGP默认没有负载均衡,可以修改 maximun-path参数来改变负载均衡条目数,一旦修改的值大于1,那么选路原则只会工作到第八条;

选路原则应用:一个路由器选路时,优先选择weight;一个AS有多个出口路由器时,优选local_pref;针对对方AS对自己选路时用MED;针对多个AS选路时,选择AS_path;