BGP(Border Gateway Protocol)
用来在不同的AS之间进行的路由交换的路由选择协议。
AS
是一组被统一管理的使用相同内部网关协议和统一度量值的路由器集合。
在不同的AS之间使用igp会出现问题:
可靠性不高容易出现环路
频繁的路由抖动
有限的邻居数量和路由数量
有限的路由策略控制和管理策略控制
AS
64512-65535私有AS【1111110000000000—1111111111111111】
1-64511共用的AS【0000000000000001—1111101111111111】
注意:在AS的内部,下一跳的路由不会改变,因为,BGP的跳是基于AS的。
BGp特点:
· 可靠性
· tcp可靠连接
· 精确路由选择信息
· 稳定性
· 计时器来防止接口flapping,在cisco的iso中,外部bgp为30s
· 可以跟踪指定路由,根据震荡历史进行惩罚
· 可扩展性
· 对等体(peer)【邻居】的数量,数百和会话
· 路由条目的数量10-20万以上
· 灵活性
· 丰富的路由属性
· 多种的策略管理
查看互联网路由:Router-server.ip .att.net
BGP的各种包
open:用来建立最初的BGP连接。(包含hold-time,router-id)
Keepalive:对等体之间周期性的交换这些消息以保持会话有效。(默认60秒)
Update:对等体之间使用这些消息来交换网络层可达性信息。
Notification:这些消息用来通知出错信息。

建邻居的过程
 • idle
 • connect(已经建立完成了TCP三次握手)
 • open sent
 • open confirm
 • establish

 


bgp基本配置:
IBGP
IBGP直连建立邻居
router bgp 100(as号相同)
 no synchronization
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 192.168.12.1 remote-as 100
 no auto-summary
 neighbor的含义
neighbor命令的含义
例:neighbor 1.1.1.1 remote-as 1
指定对方属于哪一个AS。所指的1.1.1.1地址,必须在IGP中可达。(双方都为默认路由不可以)
a.允许邻居用这个地址来访问我的179端口,但没有指明访问本路由器的哪个地址,只检查源地址
b.本路由器以更新源地址去访问neighbor后面这个地址的179端口,是否可以建立TCP链接要看对方是否允许我的更新源来访问它。
bgp的建立邻居的过程中,路由不能从bgp学过来。
Nei  192.168.12.1 shutdown
不同与no nei 192.168.12.1 remot-as 234
Sh ip bgp nei 4.4.4.4 advertised-routers
Sh ip b 1.1.1.0

为了节约session数目和冗余链路
IBGP回环扣建立邻居
router bgp 100
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 100
 neighbor 2.2.2.2 update-source Loopback0
 no auto-summary


EBGP
EBGP建立邻居
router bgp 100(as号不同)
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 200
 no auto-summary
 
 
直连lo口建立邻居
router bgp 100
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 200
 neighbor 2.2.2.2 update-source Loopback0
 
 
非直连会环口建立ebgp【注意ebgp如果是多条一定要注意多条可达,否则邻居建立不起来】
router bgp 100
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 3.3.3.3 remote-as 200
 neighbor 3.3.3.3 update-source Loopback0
Nei 3.3.3.3 ebgp multihop (n)ttl
 【neighbor 1.1.1.1 disable-connected-check】【关闭直连自动检测,忽略默认1跳的限制】
注意什么是TTl报文,TTl报文是怎么改变的?
为什么在IBGP是255,而EBGP是1.而IBGP可以跨着建邻居,二EBGP不行。
Nei 3.3.3.3 ebgp multihop (n)ttl可以修改TTl的值。
 
小feature
Nei 2.2.2.2 disable connected-check(可选)
当双方建立直连邻居超过一跳的时候要进行一个disable,关闭了后邻居就建立起来了。

修改几个bgp参数:
nei xxxxx advertisementinterval seconds 修改bgp的触发时间
nei xxxx  times  keepalives  holdtimes  修改keepalive和hold时间。

对等体组:
首先定义一个组和组名:
 neighbor zuming peer-group
然后对组所有成员指定邻居关系和更新源等:
 neighbor zuming remote-as 12
 neighbor zuming update-source Loopback0
最后把成员加入到组中:
 neighbor 1.1.1.1 peer-group zuming
 neighbor 3.3.3.3 peer-group zuming
 neighbor 4.4.4.4 peer-group zuming


network方法:
1、主类引入
192.168.12.0
2、非主类引入
192.168.12.0 mask 255.255.255.0
 
network含义:
1、No auto-summary
Network 的条目凡是精确匹配路由表中的非bgp条目时将会被引入bgp
2、auto-summary
Network 的条目凡是精确匹配路由表中的非bgp的主类路由条目会引入。
不加no auto-summary会使路由不准确。
12.2 版本以后的都自动关闭
当路由最优的时候:
向路由器提交路由表最优条目
把最优路径和下一跳发往邻居。作为最优路径的updata发送其他邻居。
Show ip bgp
Sh ip bgp rib-failure
查看路由表失败条目

bgp路由条目最优的条件:
1. 下一跳可达
2. 同步
 
同步:关闭bgp的同步,使其同步;
     如果想要bgp把从IBGP邻居学到的路由发送给EBGP,那么从IBGP学到的路由也必须从他们所在的AS内部的igp协议学到这些路由,否则,它不发送。【即,不发送从ibgp中学到的路由给ebgp,除非从igp中也能学到】
     比如一个AS内部,有一个网段没有在igp中宣布,却在BGP中宣告了,那么此时bgp同步又开启了,将会导致bgp不能传递这个路由给外部的BGP,这就是同步造成的问题。

下一条可达,意思是路由表中的下一跳必须可以同路由一步一步到达,否则也不会最优。

关闭bgp同步机制、使bgp表1245同步
r2通告r4
12.2以后的版本自动关闭。
Nei 4.4.4.4 next-hop-self

路由黑洞
IBGP
一个IBGP路由器从IBGP那里学到的路由不会在传递给其他的邻居,更不会回传,这就是IBGP的水平分割。
e-e     e-I     i-e     i0i(路由黑洞)

bgp认证:
MD5
Nei xxxx password mima 【bgp邻居加密】
Do sh ip bgp neighbor 192.168.12.1 | in md5 【检查命令】
 
 
清邻居
Clear ip bgp * (清掉所有的bgp会话)
Clear ip bgp nei xxxx (AS)
 
缺点:邻居关系down;优点,现象显示速度快
软清:clear ip bgp * solf
出方向:clear ip bgp * solf(outbound)
入方向:nei xxxx soft-reconfiguration inbound
                 clear ip bgp * solf in
BGP汇聚路由
BGP汇聚路由的方法;aggregate-address 172.16.12.0 255.255.252.0
可以在其他的AS上的路由器上更改。
但是此时在其他的路由器上也多了一条汇总路由。
因为上述的操作仅仅是aggregate 把汇总的路由放进了转发表
此时我们需要进一步的更改,多加限制。
aggregate-address 172.16.12.0 255.255.252.0 summary-noly
在R3上设置时候,会使自己称为产生源,在R5上看的时候AS路径发生了变化,进而影响了正常的路由
aggregate-address 172.16.12.0 255.255.252.0 summary-noly as set
As set 再次使as-path重现,路由获得正常,完成一次基本的聚合。
 
如果我们除了聚合路由外,我们才加两条明细,我们如何操作?
aggregate-address 172.16.12.0 255.255.252.0 summary-only as set supress-map
 
Ip prefix-list 1213 permit 172.16.12.0/24
Ip prefix-list 1213 permit 172.16.13.0/24
Route-map sup
Match ip add prefix list 1213
aggregate-address 172.16.12.0 255.255.252.0 summary-only as set supress-map sup
我们阻止 了1213
bgp汇聚
原子聚合:此时聚合路由的属性是此路由器自己新形成的,忽略以前的所有信息
Router(config-router)#aggregate-address 1.1.0.0 255.255.0.0 ?
  advertise-map  Set condition to advertise attribute
  as-set         Generate AS set path information
  attribute-map  Set attributes of aggregate
  route-map      Set parameters of aggregate
  summary-only   Filter more specific routes from updates
  suppress-map   Conditionally filter more specific routes from updates
重点是as-set属性:使用后会提取被聚合前路由的属性信息,默认会选最差的
加上advertise-map 后表示只通告匹配被汇聚路由的属性,但不能更改
如果对advertise-map 通告的属性不满意可以用attribute-map或route-map来更改
  (attribute-map和route-map作用相同,敲route-map会自动变为attribute-map)
suppress-map是同summary-only相对立的,用来表示要传递的被汇聚的路由,其写法与route-map相反,deny为要放行的。
1、suppress-map (route-map)匹配《route map 》里面的明细路由条目将会被抑制
 
2、advertise-map
     1.符合advertise-map 后面的route-map里面的路由是,竟会 产生汇聚路由(有条件的汇聚)
     2.汇聚路由只会继承匹配advertise-map后面的route-map里面的明细路由的属性
3、Attribut-map /route-map 修改汇聚路由的属性

bgp的community属性(不作为13条选路选择)
Community
是可选传递属性
 
R1要传给R2,要加上 send community
但是r2要传R3,还要加上send community

作用:
1、过滤(公有community属性)
2、打标(私有community属性)
 
1、公认的community属性
Internet 能够传递给任何的peer
No-advertese 不能把路由传给任何一个peer
Local-as和no-export关系
  在没有联邦的as内部:local-as和no-export的作用是一致的
在有联邦的as内部:local-as只能在联邦ibgp之间传递
                                       no-exportne能
私有community属性
1、aa:nn
Ip bgp community new format
2、Number 老格式

二、修改cmmuit属性
Attribut-map /route-map 修改汇聚路由的属性
Route-map att
Set commuity internet
 
Aggregat 172.16.12.0 255.255.252.0 sum  set as  attribut map ttt
Aggregat 172.16.12.0 255.255.252.0 sum  set as  route map ttt


BGP  attribute include the following
· As path
· Next-hop
· Origin
· Local referenc (用于AS的内部)公认自由决定
· med(可选非传递)【也被称为度量值,在bgp中MED是唯一一个可影响数据如何进入AS的属性,MED的值越小,越优先。】
· others(community等)可选传递
· 权重(适合本地,权重越高越优先,取值范围1-65535,路由器通告路径的默认值32768【100000000000000】)
1. Hightest weight (local to router)
2. Local (global with as)
3. Next hop (0000),始发路由最优先。
4. Aspath【越短越优先】
5. Origin igp》egp》incomplete【起源越近越明确越优先】
6. Lowst med (MED)
7. Ebgp>Ibgp (EBGP>IBGP)
8. Prefer the path through th closest IGP neighbor (metric of IGP)---------------------【在同一个AS中igp邻居越近越优先】
9. [配置maximum-path (IBGP)]n,如果存在多条等价路径,就会向路由表中插入。【以上条件相同会产生负载均衡】
10. Oldest route for EBGP paths (Oldest ebgp router)【最先发起那个ebgp路径优先】
11. BGP router ID (router ID)
12. 多条路径的始发路由器id相同,那么选择cluster-list 长度短的,因为每经过一个RR,那么cluster-list 就会加上这个RR的router-id
13. Neighbor ip address (如果是回环口则选择回环口最低的地址)(adress)
[memoral]