BGP建邻配置
- BGP的宣告是依赖路由表的,宣告需要满足:
- 被宣告的路由必须在路由表中
- 被宣告的路由必须和路由表中的前缀掩码一致
- 无论本地路由表中的条目是通过何种方式获取的,均可宣告到BGP协议中。BGP协议宣告时必须和本地路由表中的记录完全一致。
- 宣告:
r1(config-router)#network 100.1.1.1 mask 255.255.255.255
- 路由表
-IBGP建邻建议使用回环;EBGP建立邻居没有特殊情况一般使用直连建立,如果使用非直连建立需要修改跳数,默认情况下跳数为1(不修改跳数用非直连建立邻居会建不起来)
r2(config)#router bgp 1
r2(config-router)#bgp router-id 100.2.2.2
r2(config-router)#neighbor 100.5.5.5 remote-as 2
r2(config-router)#neighbor 100.5.5.5 ebgp-multihop 修改跳数
- BGP的路由传递,传递的是BGP路由表中的路由信息。
- BGP的路由表在收到路由以后需要检验该路由的下一跳是否可达,如果不可达路由一定不优。
- 使用对等体组建邻BGP邻居:(可以减少建邻过程的重复操作步骤)
r1(config)#router bgp 1
r1(config-router)#bgp router-id 100.1.1.1
r1(config-router)#neighbor a peer-group
r1(config-router)#neighbor a remote-as 1
r1(config-router)#neighbor a update-source lo0
r1(config-router)#neighbor 100.2.2.2 peer-group a
r1(config-router)#neighbor 100.3.3.3 peer-group a
BGP属性
1.weight
- Cisco私有属性,对于离开AS的路由在路由器选择哪一条最优,本台路由器产生的路由weight值为32768,学习到的路由的weight值为0,不能传递。 适用于一台路由器在多条路径下的选路,无视邻居属性。
r1(config)#router bgp 1
r1(config-router)#bgp router-id 100.1.1.1
r1(config-router)#neighbor 100.1.12.2 remote-as 1
r1(config-router)#neighbor 100.1.12.2 weight 4 修改该邻居所有传递过来的路由weight值为4.
r1(config)#ip prefix-list b permit 100.5.5.5/32
r1(config)#route-map k permit 10
r1(config-route-map)#match ip address prefix-list b
r1(config-route-map)#set weight 3
r1(config-route-map)#exit
r1(config)#route-map k permit 20
r1(config-route-map)#exit
r1(config)#router bgp 1
r1(config-router)#neighbor 100.5.5.5 route-map k in //只针对某一个路由修改weight值
weight的值的修改只能影响本路由器,不能影响到其他路由器,意味着如果AS只有一个出口,weight的选路是适用的,但是用多个出口路由器的情况下weight就不太适用。
- origin
- 起源属性,标识该路由的来源方式,0表示宣告(i),1表示EGP学到(E),3表示其他手段得到(重发布 ? ),用 i > E > ? 的比较方式进行选路。
- 配置方式
r3(config)#ip prefix-list a permit 100.6.6.6/32
r3(config)#route-map org permit 10
r3(config-route-map)#match ip address prefix-list a
r3(config-route-map)#set origin incomplete
r3(config-route-map)#exit
r3(config)#route-map org permit 20
r3(config-route-map)#exit
r3(config)#router bgp 1
r3(config-router)#neighbor 100.6.6.6 route-map org in //用in和out方向都行,适用于任何邻居之间。
r3(config-router)#exit
- as path
- 一条路由在传输过程中经历了哪些AS(不算自己),顺序是最近经过的AS排前面,一个AS拒绝接收携带有自己AS号的路由,可用来防环,也可用于选路,as path短的优先。
- 配置方式
r3(config)#ip prefix-list o permit 100.5.5.5/32
r3(config)#route-map as permit 10
r3(config-route-map)#match ip address prefix-list o
r3(config-route-map)#set as-path prepend ?
<1-4294967295> AS number
<1.0-XX.YY> AS number
last-as Prepend last AS to the as-path
r3(config-route-map)#set as-path prepend 2
r3(config-route-map)#exit
r3(config)#route-map as permit 20
r3(config-route-map)#exit
-
我们一般在选路当中添加AS会重复添加已经历的AS,一般不会添加没有经历的AS。
适用于任何邻居之间,in和out方向都行。 -
neighbor x.x.x.x allows-in 允许和具有自己相同的AS路由进入本AS。 //打破防环,在本路由器上使用。
neighbor x.x.x.x as-override 把具有和其他相同AS号的路由放入这个AS。 //邻居路由器上使用。
- next-top
- 到达路由的下一跳路由器ip地址,IBGP之间传路由next-hop不变,为0的时候会修改为更新源地址,EBGP之间传路由next-hop修改为更新源地址——下一跳为0的优于其他路径
- 配置方式
r3(config)#ip prefix-list e permit 100.8.8.8/32
r3(config)#route-map p permit 10
r3(config-route-map)#match ip address prefix-list e
r3(config-route-map)#set ip next-hop 10.1.23.3
r3(config-route-map)#exit
r3(config)#route-map p permit 20
r3(config-route-map)#exit
- 注意:修改下一跳的方向无所谓,邻居无所谓,均可。
- local-pref
- 与weight相同也是选路属性
- 不能再EBGP邻居之间传递,可以再IBGP邻居之间传递,值越高越优先(默认100),常用于当本AS有多个出口路由器时,选择拥有local值大的路由器作为出口路由器。也可以是到达一个网段有多个出口路径时,选择local值大的路径。
- 配置方式
1>修改路由器的默认local-pref值,该路由器通过给IBGP邻居的路由都会携带修改后的local值。
r3(config)#router bgp 1
r3(config-router)#bgp default local-preference 100
r3(config-router)#exit
2>通过route-map 修改某路由的local-pref值,EBGP只能在in方向。IBGP可以是in,也可以是out方向。
r3(config)#ip prefix-list t permit 100.9.9.9/32
r3(config)#route-map i permit 10
r3(config-route-map)#match ip address prefix-list t
r3(config-route-map)#set local-preference 120
r3(config-route-map)#exit
r3(config)#route-map i permit 20
r3(config-route-map)#exit
r3(config)#router bgp 1
r3(config-router)#neighbor 100.9.9.9 route-map i in
r3(config-router)#exit
- MED
- 选路属性,本质就是metric,默认为0,一般只能用于自同一个AS发出路由的不同路径med值比较。用于选择流入AS的入口路由器,可以再两个AS之间传递,不能传给第三个AS,越低越好。一般用于影响对方AS,如果在本AS使用和local等同(注意med不能在路由器上修改默认值)。
- 配置方式
r3(config)#ip prefix-list y permit 100.1.12.1/32
r3(config)#route-map r permit 10
r3(config-route-map)#match ip address prefix-list y
r3(config-route-map)#set metric 10
r3(config-route-map)#exit
r3(config)#route-map r permit 20
r3(config-route-map)#exit
r3(config)#router bgp 1
r3(config-router)#neighbor 10.1.12.1 route-map r in
r3(config-router)#exit
bgp always-compare-med //开启比较不同AS的med
ip bgp-community new-format //开启扩展格式匹配
- atomic-aggredate
- 用来警告下游路由器路由聚合后产生的路由路径丢失。
- BGP支持向BGP邻居传送重叠路由,可以选择多种方式。
- as-set命令会使得该属性消失。
-
明细和粗略都公布
aggregate-address 10.0.0.0 255.0.0.0 -
只公布明细
aggregate-address 10.0.0.0 255.0.0.0 suppress-map -
只公布没有重叠的as-path
aggregate-address 10.0.0.0 255.0.0.0 summary-only as-set -
聚合后公布聚合后的路由
aggregate-address 10.0.0.0 255.0.0.0 summary-only -
明细和粗略都不公布
-
- aggregator
- 用来通告汇总路由的汇聚路由器BPR-ID(cisco),方便寻找汇总者
9.community——团体属性
- 目的是为了更好的表示是BGP路由,标识格式为x:y
- 团体值的设置不能在EBGP之间(IBGP之间可以)。他的传递可以在IBGP之间也可以在EBGP之间。standard(做路由标识) extended(MPLS VPN),可读性好。
- 设置必须在IBGP之间可以用in也可以用out。
- 传递设置:
neighbor x.x.x.x send-community both/standard/extended
//团体属性如果需要传递必须开启该指令。
- 查看
show ip bgp 10.1.1.1 //查看路由详情,可以看到团体值
show ip bgp community //该命令可以查看所有具有团体值的路由
show ip bgp community //查看某团体值的所有路由
-
匹配设置:
使用正则表达式进行匹配。
ip community-list ? //专用的community匹配工具
ip community-list expanded k permit 111
用community匹配完成后route-map 调用即可。 -
子属性
1. internet 默认属性,可以给任何BGP发送 //不对携带团体值的路由做任何限制。
2. no_export 只能在一个AS内传递,可以在联盟内传递,该属性就是限制携带团体值的路由传递给EBGP邻居,联盟的EBGP除外。
场景:
正常情况下,a去b的流量走电信和联通之间的线路。但当该条线路故障时,会走AS这条线路,影响AS内部的网路。在AS上设置no_export后,a去b的流量即使经过AS,但AS会将其丢弃,保证AS内部的正常流量通信。
3. no_advertise 不在IBGP、EBGP邻居间传递,禁止传递给任何邻居。
4. local_as 不向任何EBGP邻居发送包括联盟的EBGP邻居。
- originator-id
- 路由器反射使用,是路由发起者产生的一个32比特的值,该值是本地路由发起者的RID,如果路由发起者从属性上看到自己的RID,说明有环路就忽略
- 场景
- RR为反射器。当有一条路由从a出发到RR上,a会给该条路由标记一个32比特的值,当这条路由再次回到a上时,若发现该值,即自己的RID,则表示出现了环路,a会自动的将该条路由丢弃以达到防环的目的。
- cluster-list
- 路由反射使用,是路由经过反射器簇ID的一个序号,如果反射器再属性里看到自己的簇ID,说明有环路就忽略。
- 场景
- 当a路由从RR 1中发出时,会给a的属性中添加上RR1的簇ID,经过RR2、3上会添加上RR2、3的簇ID,再次回到RR1时,RR1发现属性中存在自己的簇ID,就表示出现了环路,会将a这条路由丢弃。并且采用originator-id不能解决该场景的环路问题。
反射器
- 反射器可以反应客户端之间,客户端与分客户端之间的路由,但是不能反映非客户端之间的路由。
- 只需要在服务器端定义谁是客户端,未定义的即为非客户端
neighbor 10.3.3.3 route-reflector-client
//在反射服务端上指定反射客户端,未指定的就是非客户端
- 反射器的缺点:
反射器收到两个或两个以上到达同一目标的路径时需要判断出最优的路由,然后反射给客户端,这样会导致这些设备丧失多条路径判断最优路径的权力。 - 场景
-