CCNP BGP

一.概述

1. AS号

  • AS:autonomous system 自治系统,指的是在同一个组织管理下使用相同策略的设备的集合
  • 不同AS通过AS号区分,AS号取值范围1-65535,其中64512-65535 是私有AS号
  • 中国电信163 AS号:4134
  • 中国电信CN2 AS号:4809
  • 中国网通AS号:9929

2. 概述

  • BGP:Border Gateway Protocol 边界网关路由协议,为路径矢量
  • 主要作用在AS之间传递路由信息
  • 目前BGP有4个版本:V1、V2、V4、V4+(即MBGP)

3. 路径矢量

  • 路径矢量信息中包含一个BGP自治系统号列表
  • EBGP路由器不接受路径列表中包含自身AS号的路由更新,避免环路
  • BGP支持对BGP自治系统路径应用路由策略
  • BGP路由器只能将其使用的路由通告给邻接自治系统中的对等体

4. 特性

  • BGP使用TCP 179端口
  • BGP路由器之间建立TCP连接,网络层可达即可建邻居,这些路由器称为BGP对等体也叫BGP邻居:EBGP、IBGP
  • 对等体之间交换整个BGP路由表
  • BGP路由器只发送增量更新
  • BGP通告成千上万条路由,可采用TCP滑动窗口机制,停止并等待确认前,可以发送65576个字节

二.BGP邻居

注:默认路由不能用于建邻居,必须要有明细路由存在,一台设备只能属于一个AS

1. IBGP

AS号相同为IBGP,通常使用环回口建立邻居关系,因为默认使用出接口ip,所以需要指定更新源

Router(config)# router bgp 65001

Router(config-router)# bgp router-id interface Loopback0

Router(config-router)# neighbor 1.1.1.1 remote-as 65002

Router(config-router)# neighbor 2.2.2.2 update-source Loopback0

2. EBGP

AS号不同为EBGP,通常使用直连建立邻居,如果非直连需要修改ebgp-multihop,默认为TTL为1

Router(config)# router bgp 65001

Router(config-router)# bgp router-id interface Loopback0

Router(config-router)# neighbor 10.1.12.2 remote-as 65002

Router(config-router)# neighbor 10.1.12.2 ebgp-multihop 2

3. peer group

通常用于IBGP建立全互联

Router(config)# router bgp 65001

Router(config-router)# bgp router-id interface Loopback0

Router(config-router)# neighbor 1.1.1.1 peer-group PEER

Router(config-router)# neighbor 2.2.2.2 peer-group PEER

Router(config-router)# neighbor PEER remote-as 65001

Router(config-router)# neighbor PEER update-source Loopback0

4. 身份验证

  • BGP支持MD5邻居验证
  • 启用身份验证后,将对通过对等体之间的TCP连接传输的所有数据进行验证
  • 认证是在TCP建立连接时完成的,因此BGP报文中看不到验证信息
Router(config-router)# neighbor 10.1.12.2 password 123456

5. 查看BGP邻居

Router# show ip bgp ipv4 unicast summary		//默认为ipv4 unicast,可省

三.报文及状态机

1. 报文类型

2. 状态机

四.路由传递

1. 传递方式

① network

  • 需要严格按照路由表中的表项进行network
  • origin标识为 i
Router(config-router)# network 10.1.13.0 mask 255.255.255.0

② 重分布

  • OSPF重分布进BGP时默认只携带internal路由,需要手动指定其他路由
  • 默认情况下只能将EBGP的路由重分布进IGP,重分布IBGP可能会导致环路
  • BGP重分布进OSPF或EIGRP时,会将AS-path中最前面的一个AS号作为tag值
  • origin标识为 ?
Router(config-router)# redistribute ospf 110 match internal external 1 external 2 nssa-external 1 nssa-external 2		//支持各种路由工具

③ 下发

2. next-hop-self

AS边界的BGP设备向内部IBGP传递路由时,需要设置next-hop-self,防止内部的IBGP设备无法访问下一跳而导致路由无法优选

3. IBGP水平分割

从IBGP学到的路由不会再传递给其他的IBGP邻居,用以防环

打破水平分隔有三种方式

① 全互联

② 路由反射器RR

  • 只有非客户端和非客户端情况无法反射,其他组合均可反射
  • 默认情况下RR的router-id会被用作clust-id,可通过bgp cluster-id x.x.x.x修改
Router(config-router)# neighbor 2.2.2.2 route-reflector-client

Router(config-router)# no bgp client-to-client reflection			//如果IGP全互联可以直接使用此条命令

③ 联邦

  • 将大AS划分成若干个小AS,小AS之间是EBGP关系
  • 两个联邦AS之间也要解决多跳问题,大AS边界路由器必须向内做next-hop-self
  • 联邦外路由器和联邦边界路由器建立邻居关系时,neighbor为大AS号;联邦内部建邻居时,neighbor为小AS号
Router(config)# router bgp 12		//联邦AS号

Router(config-router)# bgp confederation identifier 123		//声明大AS号

Router(config-router)# bgp confederation peers 45		//对端联邦AS号

4. 路由聚合

  • 会同时发出汇总路由和明细路由,可以使用 summary-only 抑制明细路由
  • 聚合时默认会删除原有的 AS-path 信息,可能会造成环路,可以使用 as-set 参数还原 AS-path 信息
Router(config-router)# aggregate-address 10.1.0.0 255.255.0.0 summary-only

5. 同步规则

  • 从EBGP邻居学到的路由,必须在IGP中存在,才能传递给IBGP邻居
  • 防止路由黑洞问题(AS内存在非BGP路由器),默认关闭

6. backdoor

EBGP路由可以标记为后门链路,它将设置这些路由的管理距离与BGP本地或200相同.因为这个管理距离要高于IGP,所以首选IGP路由

Router(config-router)# net 10.1.12.0 mask 255.255.255.0 backdoor

7. 默认路由

下发默认路由前提需要路由表中有默认路由

Router(config-router)# default-information originate			//向所有BGP邻居传递默认路由

Router(config-router)# neighbor 10.1.12.1 default-originate		//通知指定邻居产生一条默认路由

8. 排错命令

Router# show ip bgp

Router# show ip bgp 3.3.3.0/24

Router# show ip bgp neighbor 2.2.2.2 advertised-routes

Router# show ip bgp neighbor 2.2.2.2 received-routes		//需要开启 neighbor 2.2.2.2 soft-reconfigration inbound

Router# clear ip bgp * [soft] [in/out]

9. 传递原则

① IBGP路由器从直连IBGP对等体学来的路由条目不会再传给另外一个直连IBGP对等体

② IBGP路由器会将自己从其他IBGP对等体学来的条目传给自身直连的EBGP对等体

③ 从EBGP对等体学来的路由条目会传递给自身直连的IBGP对等体

④ 从EBGP对等体学来的路由条目会传递给其他EBGP对等体

⑤ 从IBGP对等体学来的路由条目再传给EBGP对等体,下一跳会改成自己的出口

⑥ 从EBGP对等体学来的路由条目再传送给IBGP对等体,下一跳不会改为自己的出口

⑦ 从EBGP对等体学来的路由条目,再传送给EBGP路由器,下一跳更改为自己的出口

五.BGP选路

1. 属性分类

2. 选路规则

3. WEIGHT

  • cisco私有属性
  • 在路由器本地配置,只提供本地路由策略,不会传递给任何BGP邻居
  • 范围:0~65535;越大越优先
  • 路由器本地通告的路径默认权重为32768,从其它BGP邻居学习到的为0
Router(config-router)# neighbor 10.1.12.1 weight 1

4. LOCAL PREFENCE

  • 通知AS内的路由器,哪条路径离开AS为首选路径
  • LP越高越优先
  • 只发送给IBGP邻居,不能传递给EBGP邻居
  • 默认本地优先级为100
  • 一般用于控制本AS的出口设备
Router(config-router)# bgp default local-prefence 200		//全局修改默认本优先级

使用route-map针对某条路由单独修改

Router(config)# access-list 1 permit 1.1.1.1

Router(config-route-map)# route-map LP

Router(config-route-map)# match ip address 1

Router(config-route-map)# set local-preference 300

Router(config-route-map)# route-map LP permit 20			//route-map默认deny,不加此条会导致其它路由被deny

Router(config-router)# neighbor 10.1.57.5 route-map LP in

5. AS-Path

  • 前往目标网络的路由经过的自治系统号列表,通告该路由的自治系统号位于列表末尾
  • 作用:确保无环,通告给EBGP时会加上自己的AS号;通告给IBGP时不会修改AS-Path
  • AS-Path越短越优
Router(config)# access-list 1 permit 1.1.1.1

Router(config-route-map)# route-map AS

Router(config-route-map)# match ip address 1

Router(config-route-map)# set as-path prepend 5 4 3 2 1		//方式1:手动指定路径

Router(config-route-map)# set as-path prepend last-as 5		//方式2:重复追加最后一个AS(推荐使用)

Router(config-route-map)# route-map AS permit 20			//route-map默认deny,不加此条会导致其它路由被deny

Router(config-router)# neighbor 10.1.57.5 route-map AS in

6. Origin

  • IGP:在AS内部,用network通告路由时,用 i 表示
  • EGP:路由通过EGP获悉,用 e 表示
  • Incomplete:路由的源头未知或是通过其它方法获悉,用 ?表示,如重发布

优选顺序:IGP > EGP > Incomplete

Router(config)# access-list 1 permit 1.1.1.1

Router(config-route-map)# route-map ORI

Router(config-route-map)# match ip address 1

Router(config-route-map)# set origin incomplete

Router(config-route-map)# route-map AS permit 20			//route-map默认deny,不加此条会导致其它路由被deny

Router(config-router)# neighbor 10.1.57.5 route-map AS in

7. MED

  • 一种度量值,用于向外部邻居指出进入AS的首选路径,当入口有多个时,自治系统可以使用MED影响其他AS如何进入
  • 度量值越小路径越优
  • MED在AS之间交换,MED发送给EBGP对等体,这些路由器在AS内传播MED,不传递给下一个AS
  • 一般用于控制进入本AS的入口设备
Router(config)# access-list 1 permit 1.1.1.1

Router(config-route-map)# route-map MED

Router(config-route-map)# match ip address 1

Router(config-route-map)# set metric 200

Router(config-route-map)# route-map MED permit 20			//route-map默认deny,不加此条会导致其它路由被deny

Router(config-router)# neighbor 10.1.57.5 route-map MED out

8. 负载均衡

如果前8条选路规则一致,则支持负载均衡,默认不开。如果开启后不加参数,默认为EBGP负载均衡

Router(config-router)# maximum-paths [ibgp/eibgp] 2

9. Orginator ID和Cluster List

Originator ID记录本地AS中路由发起者的ID,Cluster List记录经过的路由反射器的Router ID

10. Aggregator和ATOMIC-Aggregate

Aggregator记录哪一台设备做了路由聚合,ATOMIC-Aggregate用于警告下游路由器,本条路由聚合后出现了路径丢失

11. COMMUNITY

  • 用于简化路由策略的执行
  • 可以将某些路由分配一个特定的COMMUNITY属性,之后就可以基于COMMUNITY值而不是每条路由进行BGP属性设置了

① 公认

  • Internet:通告给所有邻居
  • no-export:不传给EBGP(联邦之间可以传递)
  • local-as:不传给EBGP(联邦之间也不传递)
  • no-advertise:不通告

② 扩展

  • 格式为 ASN:nn
  • ASN表示AS号,nn表示设备编号

六.协议优化

1. bfd 双向转发检测

实现链路快速检测,故障切换能够达到毫秒级。

Router(config)# router bgp 65001

Router(config-router)# bgp router-id interface Loopback0

Router(config-router)# neighbor 10.1.12.2 remote-as 65002

Router(config-router)# neighbor 10.1.12.2 fall-over bfd


Router(config-if)#int e0/0

Router(config-if)#bfd interval 50 min_rx 50 multiplier 3

2. graceful-restart 优雅重启

协议重启时,能够保持邻居一段时间内不中断,路由信息不丢失。并且在重启完成后,周边设备会协助快速恢复重启前状态。

Router(config-router)# bgp graceful-restart				//全局开启GR

Router(config-router)# neighbor 10.1.12.2 ha-mode graceful-restart		//指定邻居开启GR

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值