边界网关路由协议(BGP)
文章目录
- BGP网络概述
- 网络结构
- IP地址的配置与管理
- OSPF作为IGP协议在AS200中的应用
- BGP跨AS间路由配置策略
- 内部BGP协议的优化配置
- 路由数据的有效传播路径
- 网络结构
- 二、BGP邻居
-
- 分类
第3节 BGP消息类型
第4节 BGP同步
第5节 BGP表
第6节 BGP维护
* 硬重置(很不推荐);软重置(推荐)
- 七、BGP路由黑洞解决
-
- 全互联
- BGP路由重发步仅IGP
- 路由反射器
八、BGP常见属性
AS
- 在同一个组织下管理的网络集合通常被称为自制系统。
- 一个自制系统通常会拥有统一的路由管理和策略设定。
- AS通过不同的AS号码来区分;AS号码原本的范围是0至65535;后来扩展到了0至232。
- 中国电信163网络对应的AS号码为4134。
- 中国电信CN2网络对应的AS号码为4809。
- 中国网通网络对应的AS号码为9929。
IGP
-
内部路由器协议
-
进行拓扑探测
-
在网络安全变化时及时更新路由信息
-
努力实现迅速收敛
-
当网络发生变化时,在所有设备上达到稳定状态所需的时间被称为收敛时间
-
IGP协议的收敛速率被视为路由协议优化的一个衡量标准
-
定期更新是保证路由选择信息精确性的重要环节。
-
该管理机构拥有对该网络的所有权。
-
系统遵循相同的路由选择策略。
-
该系统赋予其优先级控制能力。
-
以度量值作为其唯一的手段实现路径管理。
EGP
- IP中间代理协议 其主要功能在于实现不同自治系统(AS)之间的路由信息传递
- 在技术演进过程中 初始阶段这类协议统称为EGP 然后逐渐被更先进的BGP取代
- 每个EGP实例可能服务于多个独立的网络段
一、BGP
Border Gateway Protocol 边界网关路由协议(距离矢量)
主要作用是在AS之间传递路由信息
目前BGP有4个版本:V1、V2、V4、V4+(即MBGP)
为什么使用BGP
- 需要承载大量路由的任务中
IGP类网络设备仅能支持数千条路由
而BGP则可轻松管理数十万条乃至上千万级别规模的路由表 - BGP不仅能支撑MPLS VPN和传统VPN的应用场景
还能将客户网络中的VPN配置信息进行传输 - 该方案展现出较强的策略性
在实现动态路由决策的同时也能有效管控数据流量走向
BGP使用TCP 为传输层协议,TCP端口号为179
通过TCP协议建立连接的BGP路由器之间形成的互连实体(MIA),也可称为邻域(neighbor)。其中增强型互连实体(E-MIA)对应于EBGP标识符,并简称为E-MIA;而增强型互连实体(I-MIA)则对应于IBGP标识符,并简称为I-MIA。
对等体之间交换整个BGP路由表
BGP路由器只发送增量更新或者触发更新(不会周期更新)
具有丰富的路径属性
BGP会话将向数以千上万的路由发送响应;按照TCP传输控制协议中的滑动窗口机制进行;在到达确认之前最多可发送65576个字节
例如不同运营商将各自内部的服务标识利用BGP协议进行全球范围内的传递与共享, 从而使得各个运营商之间能够互相访问
一般来说各个AS不会将所有的地址都上报给BGP

拓扑

IP地址配置
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#int e0/0
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#no sh
==============================
R2(config)#int lo0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#int e0/0
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int e0/1
R2(config-if)#ip add 192.168.23.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int e0/2
R2(config-if)#ip add 192.168.24.2 255.255.255.0
R2(config-if)#no sh
==========================
R3(config)#int lo0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#int e0/0
R3(config-if)#ip add 192.168.23.3 255.255.255.0
R3(config-if)#no sh
R3(config-if)#int e0/1
R3(config-if)#ip add 192.168.35.3 255.255.255.0
R3(config-if)#no sh
==============================
R4(config)#int lo0
R4(config-if)#ip add 4.4.4.4 255.255.255.0
R4(config-if)#int e0/0
R4(config-if)#ip add 192.168.24.4 255.255.255.0
R4(config-if)#no sh
R4(config-if)#int e0/1
R4(config-if)#ip add 192.168.45.4 255.255.255.0
R4(config-if)#no sh
=============================
R5(config)#int lo0
R5(config-if)#ip add 5.5.5.5 255.255.255.0
R5(config-if)#int e0/0
R5(config-if)#ip add 192.168.35.5 255.255.255.0
R5(config-if)#no sh
R5(config-if)#int e0/1
R5(config-if)#ip add 192.168.45.5 255.255.255.0
R5(config-if)#no sh
R5(config-if)#int e0/2
R5(config-if)#ip add 192.168.56.5 255.255.255.0
R5(config-if)#no sh
===========================
R6(config)#int lo0
R6(config-if)#ip add 6.6.6.6 255.255.255.0
R6(config-if)#int e0/0
R6(config-if)#ip add 192.168.56.6 255.255.255.0
R6(config-if)#no sh
AS200中的IGP(OSPF)
此处须注意,在R2及R5与其他AS之间的接口不宜开启路由协议。否则可能导致路由泄露。
R2(config)#int range e0/1-2,lo0
R2(config-if-range)#ip ospf 1 area 0
===============================
R3(config-if)#int range e0/0-1,lo0
R3(config-if-range)#ip ospf 1 area 0
================================
R4(config-if)#int range e0/0-1,lo0
R4(config-if-range)#ip ospf 1 area 0
==================================
R5(config)#int range e0/0-1,lo0
R5(config-if-range)#ip ospf 1 area 0
配置AS之间的BGP协议
首先建立R1和R2的BGP邻居
R1(config)#router bgp 100
R1(config-router)#neighbor 192.168.12.2 remote-as 200
# BGP无法自己发现邻居,要自己去指定邻居关系,因为BGP就不是拿来做拓扑发现作用的,是用来传递现有的路由
================================
R2(config)#router bgp 200
R2(config-router)#neighbor 192.168.12.1 remote-as 100
查看邻居关系
R1#sh ip bgp summary
BGP router identifier 1.1.1.1, local AS number 100
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.12.2 4 200 4 4 1 0 0 00:00:09 0
# 一定要确认Up/Down下面有时间,因为BGP summary中会显示所有被指定的邻居,即使从来没建立过
# 所以邻居条目即使有,后面写的never也是无效
建立R5和R6的邻居
R5(config)#router bgp 200
R5(config-router)#neighbor 192.168.56.6 remote 300
=======================
R6(config)#router bgp 300
R6(config-router)#neighbor 192.168.56.5 remote 300
# 这边如果AS号写错了,比如我写成了300
*Apr 5 02:32:30.617: %BGP-3-NOTIFICATION: sent to neighbor 192.168.56.5 passive 2/2 (peer in wrong AS) 2 bytes 00C8
# 如果出现了peer in wrong AS,就说明你配置错误的AS号
查看邻居关系
R6#show ip bgp summary
BGP router identifier 6.6.6.6, local AS number 300
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.56.5 4 200 5 5 1 0 0 00:01:28 0
然而在AS之间实现连接时,则必须依赖于冗余链路的存在。如果直接为相邻节点分配对方的物理接口地址,则这种配置方式同样不够稳定。
建议BGP所有的邻居关系都最好使用环回接口
AS之间无法启动IGP协议建立连接
R1(config)#ip route 2.2.2.0 255.255.255.0 192.168.12.2
=======================
R2(config)#ip route 1.1.1.0 255.255.255.0 192.168.12.1
检查连通性
R1#ping 2.2.2.2 so 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
两边都设置邻居,并且设置更新源
R1(config)#router bgp 100
R1(config-router)#nei 2.2.2.2 remote 200
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
=====================
R2(config)#router bgp 200
R2(config-router)#nei 1.1.1.1 remote 100
R2(config-router)#neighbor 1.1.1.1 update-source Loopback0
发现无法建立邻居
R1#sh ip bgp sum
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 200 0 0 1 0 0 never Idle
我们尝试抓取EBGP邻居之间数据包

研究团队发现,在EBGP邻居配置中,默认会生成的时间限制长度仅设置为1的数据包序列。这表明如果路由器R1向相邻路由器R2发送EBGP信息数据包,则完全无法通过R2的lo0接口接收该数据包。
如果是两个节点作为EBGP邻居通过环回接口进行连接,则可以通过配置相应的BFD信息来实现该功能;若节点间属于跨网段关系,则应采取BFD协议进行连接。
R1(config)#router bgp 100
R1(config-router)#nei 2.2.2.2 ebgp-multihop
=====================
R2(config)#router bgp 200
R2(config-router)#neighbor 1.1.1.1 ebgp-multihop
配置AS200内部的BGP协议
该协议采用端口号179/tcp作为传输通道,并通过四层架构进行传播机制。数据将穿越广播域范围(其覆盖范围仅限于本地广播域(组播不可行)),因此,在实践中,BGP设备虽然地理位置分散,但仍能相互连接形成全球性网络架构。
然而,在设置邻居时,默认情况下只需要配置一个接口即可完成与另一台设备的通信连接。如果设备之间存在多条通信路径,则需要根据具体需求合理选择合适的接口进行配置以确保通信顺畅。
因为物理接口的稳定性较低,并且无法像环回接口那样可靠地发送数据包到同一网络中。因此,在配置BGP邻居时,我们通常会选择使用环回接口来作为其邻居地址。
比如R5的e0/0,e0/1任何一个接口失效了,R2依旧可以访问R5的环回接口。
R2(config)#router bgp 200
R2(config-router)#neighbor 5.5.5.5 remote 200
=======================
R5(config)#router bgp 200
R5(config-router)#neighbor 2.2.2.2 remote 200
等待一段时间后发现R2和R5无法完成邻居的建立。使用 debug bgp all 命令后发现:R5试图通过 192.168.45.5 与其他设备进行邻居连接;然而,在此过程中,R2仅将 5.5.5.5 视为有效的来源地址。
*Apr 5 02:42:13.641: BGP: 2.2.2.2 open active, local address 192.168.45.5
所以需要指定建立邻居的时候路由更新的源接口
R2(config)#router bgp 200
R2(config-router)#neighbor 5.5.5.5 update-source lo0
===================
R5(config)#router bgp 200
R5(config-router)#nei 2.2.2.2 up lo0
检查邻居关系
R5#sh ip bgp summary
BGP router identifier 5.5.5.5, local AS number 200
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 200 4 4 1 0 0 00:00:58 0
192.168.56.6 4 300 18 18 1 0 0 00:13:06 0
BGP路由的传递
然而,在构建邻居关系时也不会发送任何信息
我们需要手动的将需要传递的路由加入BGP表,才可以被传递
我们将R1的lo0和R6的lo0作为通信的双方,将路由加入BGP表
R1(config)#router bgp 100
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
===============================================
R6(config)#router bgp 300
R6(config-router)#netw 6.6.6.0 mask 255.255.255.0
在R2上检查路由
R2#show ip route bgp
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 192.168.12.1, 00:01:18
在R5上检查路由
R5#show ip route bgp
6.0.0.0/24 is subnetted, 1 subnets
B 6.6.6.0 [20/0] via 192.168.56.6, 00:01:07
观察到R2和R5分别掌握了各自的路由信息,并未进行互信息的交换;随后对R5的BGP表信息进行了核查。
bgp表中存储了BGP接收的所有数据项及其属性信息,并且即便这些数据项无效也会被记录下来。
R5#show ip bgp
Network Next Hop Metric LocPrf Weight Path
* i 1.1.1.0/24 192.168.12.1 0 100 0 100 i
*> 6.6.6.0/24 192.168.56.6 0 0 300 i
R5虽然收到了 1.1.1.0/24 条目,但是 Next Hop 无效。因为R5并不知道AS100中地址。
IGP是一种基于Router—-Router协议的技术,在处理数据包的时候,在下一个路由阶段会根据当前路由器的信息将目标地址更新为前一阶段路由器的接口编号。
BGP是一种基于 AS—-AS 协议的路由协议,在一个路由条目从一个 AS 传递到另一个 AS 时,在下一跳处会自动更改为当前 AS 的出口地址,在同一 AS 内部传播时,默认下一跳信息不会更改。
所以在AS边缘的路由器需要将条目的下一跳改为自己
R2(config)#router bgp 200
R2(config-router)#nei 5.5.5.5 next-hop-self
==================
R5(config)#router bgp 200
R5(config-router)#nei 2.2.2.2 next-hop-self
查看R5的BGP表,发现下一跳已经被改变
R5#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 2.2.2.2 0 100 0 100 i
*> 6.6.6.0/24 192.168.56.6 0 0 300 i
查看R5的路由表
R5#sh ip route bgp
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 2.2.2.2, 00:00:34
6.0.0.0/24 is subnetted, 1 subnets
B 6.6.6.0 [20/0] via 192.168.56.6, 00:06:44
查看R1和R6的路由表
R1#show ip route bgp
6.0.0.0/24 is subnetted, 1 subnets
B 6.6.6.0 [20/0] via 192.168.12.2, 00:00:40
=========================
R6#sh ip route bgp
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 192.168.56.5, 00:01:16
尝试在R6上 ping 1.1.1.1 source 6.6.6.6
结果并不通,逐条分析流量的源目的IP地址发现了原因。
在R1与R6之间进行通信时,在线路上未设置相应的端口配置参数,在这种情况下会导致网络设备无法正常建立连接通道
在这种情况下,在BGP协议中较为常见的一种现象我们将其称为路由黑洞问题。针对这一问题存在多种解决方案,请根据具体情况具体分析采取相应的措施。
二、BGP邻居
R5#show ip bgp summary
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 200 29 30 11 0 0 00:21:23 1
6.6.6.6 4 300 7 8 11 0 0 00:02:47 1
-
Neighbor
-
建立邻居的设备Router-ID
-
V
- 版本,默认是v4
-
AS
- 邻居所属的AS号
-
MsgRcvd MsgSent
- 收到和发送的消息计数
-
TblVer
- 最后一次邻居表版本号
-
-
InQ OutQ
-
入队列和出队列通常为零值
-
如果其值不为零,则意味着存在等待处理的任务
-
如果入队列和出队列的数值不为零,则表明网络出现拥堵现象
- Up/Down
- 邻居建立的时间
- 没有建立过的邻居会写never
- Up/Down
State/PfxRcd
- 明确地设置BGP为每个相邻节点配置,并创建与相邻节点之间的TCP连接。该协议默认每60秒发送一次BGP/TCP存活消息(即每分钟发送一次),其存活期设定为180秒。
- 当发生网络状态变化时会触发数据更新请求;此外还支持基于增量机制的数据同步功能。
分类
BGP对等体(peer)也叫BGP邻居,建立基于TCP
-
IB GP 邻接关系
-
同一自治系统内的路由器之间的 B GP 邻接关系
-
通过 IB GP 学习到的路由具有一个固定的距离值(例如 200),从 IB GP 学习到的路由不会传递给其他 IB GP 邻居
-
当启用 B GP 同步时,如果 IG P 未学习到某条路由,则该路由也不会被 B GP 使用
-
IB G P 邻居传递路由时,默认不会将下一跳地址指向发送该路由的那一台路由器;建立 IB G P 邻接关系需满足以下条件:
- 具有相同的Autonomous System号
- 定义邻居间的TCP连接过程
- 确保建立起来的IBG P 邻居之间能够通过IBG P 实现可达性
-
在测试两台路由器之间的可达性时,在执行ping命令后需附加源地址参数(source),因为 B gp 邻居关系对于源地址非常敏感
-
EBGP相邻关系
-
不同自治系统内的路由器之间通过B GP建立的相邻关系
-
通过EB GP 学习到的路由具有一个固定的管理距离值即20
-
EB GP 邻居为了安全考虑会在数据包中设置特定参数其中TTL值默认为1
-
在数据包中会自动将下一跳地址更改为发送该数据包的那一台路由器以便实现正确路由传递
-
创建EB GP 邻居需要遵循以下三个条件:
- 参与连接的两个B GP 必须运行于不同的自治系统号
- 配置邻居端口间建立双向的TCP 连接
- 指定的目标IP 地址必须能够互相通信以确保正常路由交换
三、BGP消息类型



四、BGP同步
BGP路由器不应发布由IBGP获得的信息到外部网络,并不会将此信息通知外部邻居……
通常情况下,在从IGP获取了路由信息后就不会再启用BGP配置;因此,在这种情况下,默认状态会被设置为关闭并不会被手动开启
R2(config)#router bgp 200
R2(config-router)#synchronization
五、BGP表
R5#show ip bgp
BGP table version is 11, local router ID is 5.5.5.5
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 2.2.2.2 0 100 0 100 i
*> 6.6.6.0/24 6.6.6.6 0 0 300 i
BGP表将存储路由器通过BGP协议学习获取的所有路由信息以及自身所生成的BGP路由条目。
-
-
- 表示有效的
-
-
- 最佳的,有了>才可以进入路由表
-
i
- 表示是ibgp邻居发过来的
-
Network
- 网段和前缀长度
-
Next Hop
- 下一跳信息
-
指标
-
度量值
-
在本地系统中,默认情况下生成的路由条目数量设置为零。
-
由EBGP邻居提供的路由信息字段为空。
-
LocPrf
- 本地优先级
- 用于告知内部路由器如何优选离开本AS
-
-
Weight
-
用于指导自己选择最优路径
-
自生成的内容条目具有最高权重
-
继承来源的内容未赋予任何权重
-
Path*
该数据结构记录了路由经过的所有AS号。
该字段用于避免路由器自身重复学习同一个路径条目。
最后一个字符i用于标识该路径的来源。
路由器属性i起源于IGP协议。
它是通过系统管理员手动配置添加到网络中的。* e-
起源于egp协议(然而这个协议已经消失)
- ?
-
未知来源
-
比如重发布会丢失起源信息
-
六、BGP维护
硬重置(很不推荐)
clear ip bgp *
因为会删除所有BGP邻居(由于删除了所有的),随后再进行重建。由于BGP条目数量庞大(非常之多),这将导致网络中断或连接问题(这么做可能导致断网)。或者导致邻居无法再次成功建立。
软重置(推荐)
R5#clear ip bgp * soft in/out
软重置分为两种:
- 表示为
- 广播route_refresh信息给相邻节点;随后的相邻节点会广播新的路由信息以更新本地路径表。
- 在更新前不会移除路径表条目。
完成操作并返回结果至指定地址
七、BGP路由黑洞解决
路由黑洞在上面已经产生,解决方案多样
全互联
将R2-R3-R4-R5之间的直连线路都建立邻居关系
先删除R2-R5的邻居关系
R2(config)#router bgp 200
R2(config-router)#no nei 5.5.5.5
=============
R5(config)#router bgp 200
R5(config-router)#no nei 2.2.2.2
建立邻居关系
R2(config)#router bgp 200
R2(config-router)#nei 3.3.3.3 remote 200
R2(config-router)#nei 3.3.3.3 up lo0
R2(config-router)#nei 3.3.3.3 next-hop-self
R2(config-router)#nei 4.4.4.4 remote 200
R2(config-router)#nei 4.4.4.4 up lo0
R2(config-router)#nei 4.4.4.4 next-hop-s
===================
R3(config)#router bgp 200
R3(config-router)#nei 2.2.2.2 remote 200
R3(config-router)#nei 2.2.2.2 up lo0
R3(config-router)#nei 5.5.5.5 remote 200
R3(config-router)#nei 5.5.5.5 up lo0
================
R4(config)#router bgp 200
R4(config-router)#nei 2.2.2.2 remote 200
R4(config-router)#nei 2.2.2.2 up lo0
R4(config-router)#nei 5.5.5.5 remote 200
R4(config-router)#nei 5.5.5.5 up lo0
===================
R5(config)#router bgp 200
R5(config-router)#nei ibgp peer-group
R5(config-router)#nei ibgp remote 200
R5(config-router)#nei ibgp next-hop-s
R5(config-router)#nei ibgp up lo0
R5(config-router)#nei 3.3.3.3 peer ibgp
R5(config-router)#nei 4.4.4.4 peer ibgp
使用对等体组,将需要相同配置的邻居加入,可以简便配置。
下面我们检查R3和R4的路由表,发现可以学习到1.1.1.0/24和6.6.6.0/24
R3#sh ip route bgp
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 2.2.2.2, 00:03:29
6.0.0.0/24 is subnetted, 1 subnets
B 6.6.6.0 [200/0] via 5.5.5.5, 00:01:30
=============================
R4#sh ip route bgp
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [200/0] via 2.2.2.2, 00:02:00
6.0.0.0/24 is subnetted, 1 subnets
B 6.6.6.0 [200/0] via 5.5.5.5, 00:01:50
下面检查R1–R6连通性
R1#ping 6.6.6.6 so 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
.....
Success rate is 0 percent (0/5)
通过BGP表中的Path属性可以在不同AS之间实现防环。然而,在同一个AS内部该Path保持不变。因此,在使用IBGP时会实施水平分割机制(即从其他IBGP邻居获得的信息不再发送到其他IBGP路由器),从而有效避免同一AS内的路由环路。
- 接收一条新的路由信息
- 如果是一个 ebgp 邻居发来的,则会将该路由发送至每个 BGP 邻居。
- 如果是一个 ibgp 邻居发来的,则不会向任何 ibgp 邻居转发该路由信息;反而仅会向对应的 ebgp 邻居转发。
可以在R2—R5之间建立邻居关系,这样就可以学到路由条目了
R2(config)#router bgp 200
R2(config-router)#nei 5.5.5.5 remote 200
R2(config-router)#nei 5.5.5.5 up lo0
R2(config-router)#nei 5.5.5.5 next-hop-s
=====================
R5(config)#router bgp 200
R5(config-router)#nei 2.2.2.2 peer ibgp
检查连通性
R1#ping 6.6.6.6 so 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
然而,在实际应用场景中实现全互联几乎是不可能的。原因在于,并非所有设备都具备BGP的支持能力。即便具备BGP的支持条件,在处理规模达到千万级别的数据量时仍显力有未逮。
然而全互联的配置与维护极为繁琐;如果拥有100台路由器并希望实现全互联,则必须创建9,900个邻居关系;同时这些更新可能导致整个网络出现波动。
BGP路由重发步仅IGP
删除AS200中的BGP
no router bgp 200
然后R2和R5建立邻居关系
R2(config)#router bgp 200
R2(config-router)#nei 5.5.5.5 remote 200
R2(config-router)#nei 5.5.5.5 up lo0
R2(config-router)#nei 5.5.5.5 next-hop-s
R2(config-router)#nei 1.1.1.1 remote 100
R2(config-router)#nei 1.1.1.1 up lo0
R2(config-router)#nei 1.1.1.1 eb
===================
R5(config)#router bgp 200
R5(config-router)#nei 2.2.2.2 remote 200
R5(config-router)#nei 2.2.2.2 up lo0
R5(config-router)#nei 2.2.2.2 next-hop-s
R5(config-router)#nei 6.6.6.6 remote 300
R5(config-router)#nei 6.6.6.6 up lo0
R5(config-router)#nei 6.6.6.6 eb
在R2和R5上重发布BGP条目到IGP中,让IGP学习到,来消除路由黑洞
R2(config)#router ospf 1
R2(config-router)#redistribute bgp 200 subnets
============
R5(config)#router ospf 1
R5(config-router)#redistribute bgp 200 subnets
检查R3R4的路由表
R3#sh ip route ospf
1.0.0.0/24 is subnetted, 1 subnets
O E2 1.1.1.0 [110/1] via 192.168.23.2, 00:01:01, Ethernet0/0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/11] via 192.168.23.2, 00:05:10, Ethernet0/0
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/21] via 192.168.35.5, 00:05:10, Ethernet0/1
[110/21] via 192.168.23.2, 00:05:10, Ethernet0/0
5.0.0.0/32 is subnetted, 1 subnets
O 5.5.5.5 [110/11] via 192.168.35.5, 00:05:10, Ethernet0/1
6.0.0.0/24 is subnetted, 1 subnets
O E2 6.6.6.0 [110/1] via 192.168.35.5, 00:00:40, Ethernet0/1
O 192.168.24.0/24 [110/20] via 192.168.23.2, 00:05:10, Ethernet0/0
O 192.168.45.0/24 [110/20] via 192.168.35.5, 00:05:10, Ethernet0/1
====================
R4#sh ip route ospf
1.0.0.0/24 is subnetted, 1 subnets
O E2 1.1.1.0 [110/1] via 192.168.24.2, 00:01:18, Ethernet0/0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/11] via 192.168.24.2, 00:05:24, Ethernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/21] via 192.168.45.5, 00:05:24, Ethernet0/1
[110/21] via 192.168.24.2, 00:05:24, Ethernet0/0
5.0.0.0/32 is subnetted, 1 subnets
O 5.5.5.5 [110/11] via 192.168.45.5, 00:05:24, Ethernet0/1
6.0.0.0/24 is subnetted, 1 subnets
O E2 6.6.6.0 [110/1] via 192.168.45.5, 00:00:57, Ethernet0/1
O 192.168.23.0/24 [110/20] via 192.168.24.2, 00:05:24, Ethernet0/0
O 192.168.35.0/24 [110/20] via 192.168.45.5, 00:05:24, Ethernet0/1
检查连通性
R1#ping 6.6.6.6 so 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
然而,在真实场景中,IGP可能无法有效处理BGP所拥有的规模宏大的路由条目,这可能导致其本职工作受到波及。
这样执行后也会将外部的数据项整合到内部路由协议中,并可能导致一系列潜在的问题
路由反射器
删除R2R5的BGP邻居,并且删除重发布操作
R2(config)#router ospf 1
R2(config-router)#no redistribute bgp 200 subnets
R2(config-router)#router bgp 200
R2(config-router)#no nei 5.5.5.5
============
R5(config)#router ospf 1
R5(config-router)#no redistribute bgp 200 subnets
R5(config-router)#router bgp 200
R5(config-router)#no nei 2.2.2.2
当遇到IBGP网络中出现水平划分导致无法实现将数据包再次发送给IBGP邻居的情况时,建议配置该端口为路由反射器客户端以解除一次划分机制。
在实际应用场景中,在一个Autonomous System(AS)内,我们配置了一个路由器充当Reflective Router,并将所有的BGP(Border Gateway Protocol)路由与之建立邻居关系。每当存在任何路由更新时, 这些更新会仅发送到该Reflective Router, 并由其转发给所有IBGP(Interior Border Gateway Protocol)邻居。


假设有100台路由器,则只需选择节点并与路由反射器形成邻居关系即可;即便都采用BGP协议,也不会超过99个邻居关系。
下图是规则的补充

之前的路由黑洞实验中,在我们的前期测试中发现了一个问题:当网络拓扑发生变化时会导致性能下降。为此,在之前的路由黑洞实验中,在我们的前期测试中发现了这一问题,并采取了相应的措施来解决它。
R2&R4&R5
router bgp 200
nei 3.3.3.3 remote 200
nei 3.3.3.3 up lo0
nei 3.3.3.3 next-hop-s # R4不需要这条
===============
R3
R3(config)#router bgp 200
R3(config-router)#nei as200 peer
R3(config-router)#nei as200 remote 200
R3(config-router)#nei as200 up lo0
R3(config-router)#nei as200 route-reflector-client
R3(config-router)#nei 2.2.2.2 peer as200
R3(config-router)#nei 4.4.4.4 peer as200
R3(config-router)#nei 5.5.5.5 peer as200
检查连通性
R1#ping 6.6.6.6 so 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
八、BGP常见属性
BGP属性分类
-
通用属性 Universal(所有路由器都必须认识)
-
通用强制属性Universal mandatory(所有路由在更新的时候都必须携带;如果不携带则直接报错)
-
通用自由决定属性Universal discretionary(可以更新的时候不携带)
-
可选择的属性 Optional(路由器不具备无)
-
可以选择传递的Optional transitive(该属性意味着将其传播下去)
-
可以选择非传播性的Optional non-transitive(该属性应避免传播)
拓扑

初始配置
===============R1===============
interface Loopback0
no shutdown
ip address 1.1.1.1 255.255.255.0
!
interface Ethernet0/0
no shutdown
ip address 192.168.12.1 255.255.255.0
!
interface Ethernet0/1
no shutdown
ip address 192.168.13.1 255.255.255.0
router bgp 100
bgp log-neighbor-changes
network 1.1.1.0 mask 255.255.255.0
neighbor 2.2.2.2 remote-as 200
neighbor 2.2.2.2 ebgp-multihop 255
neighbor 2.2.2.2 update-source Loopback0
neighbor 3.3.3.3 remote-as 300
neighbor 3.3.3.3 ebgp-multihop 255
neighbor 3.3.3.3 update-source Loopback0
ip route 2.2.2.2 255.255.255.255 192.168.12.2
ip route 3.3.3.3 255.255.255.255 192.168.13.3
===============R2===============
interface Loopback0
no shutdown
ip address 2.2.2.2 255.255.255.0
!
interface Ethernet0/0
no shutdown
ip address 192.168.12.2 255.255.255.0
!
interface Ethernet0/1
no shutdown
ip address 192.168.24.2 255.255.255.0
router bgp 200
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 100
neighbor 1.1.1.1 ebgp-multihop 255
neighbor 1.1.1.1 update-source Loopback0
neighbor 4.4.4.4 remote-as 450
neighbor 4.4.4.4 ebgp-multihop 255
neighbor 4.4.4.4 update-source Loopback0
ip route 1.1.1.1 255.255.255.255 192.168.12.1
ip route 4.4.4.4 255.255.255.255 192.168.24.4
===============R3===============
interface Loopback0
no shutdown
ip address 3.3.3.3 255.255.255.0
!
interface Ethernet0/0
no shutdown
ip address 192.168.13.3 255.255.255.0
!
interface Ethernet0/1
no shutdown
ip address 192.168.35.3 255.255.255.0
router bgp 300
bgp log-neighbor-changes
network 3.3.3.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 100
neighbor 1.1.1.1 ebgp-multihop 255
neighbor 1.1.1.1 update-source Loopback0
neighbor 5.5.5.5 remote-as 450
neighbor 5.5.5.5 ebgp-multihop 255
neighbor 5.5.5.5 update-source
ip route 1.1.1.1 255.255.255.255 192.168.13.1
ip route 5.5.5.5 255.255.255.255 192.168.35.5
===============R4===============
interface Loopback0
no shutdown
ip address 4.4.4.4 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/0
no shutdown
ip address 192.168.24.4 255.255.255.0
!
interface Ethernet0/1
no shutdown
ip address 192.168.45.4 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/2
no shutdown
ip address 192.168.46.4 255.255.255.0
ip ospf 1 area 0
router bgp 450
bgp log-neighbor-changes
network 4.4.4.0 mask 255.255.255.0
neighbor 2.2.2.2 remote-as 200
neighbor 2.2.2.2 ebgp-multihop 255
neighbor 2.2.2.2 update-source Loopback0
neighbor 6.6.6.6 remote-as 450
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self
ip route 2.2.2.2 255.255.255.255 192.168.24.2
===============R5===============
interface Loopback0
no shutdown
ip address 5.5.5.5 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/0
no shutdown
ip address 192.168.45.5 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/1
no shutdown
ip address 192.168.35.5 255.255.255.0
!
interface Ethernet0/2
no shutdown
ip address 192.168.56.5 255.255.255.0
ip ospf 1 area 0
router bgp 450
bgp log-neighbor-changes
network 5.5.5.0 mask 255.255.255.0
neighbor 3.3.3.3 remote-as 300
neighbor 3.3.3.3 ebgp-multihop 255
neighbor 3.3.3.3 update-source Loopback0
neighbor 6.6.6.6 remote-as 450
neighbor 6.6.6.6 update-source Loopback0
neighbor 6.6.6.6 next-hop-self
ip route 3.3.3.3 255.255.255.255 192.168.35.3
===============R6===============
interface Loopback0
no shutdown
ip address 6.6.6.6 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/0
no shutdown
ip address 192.168.46.6 255.255.255.0
ip ospf 1 area 0
!
interface Ethernet0/1
no shutdown
ip address 192.168.56.6 255.255.255.0
ip ospf 1 area 0
router bgp 450
bgp log-neighbor-changes
network 6.6.6.0 mask 255.255.255.0
neighbor 4.4.4.4 remote-as 450
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 route-reflector-client
neighbor 5.5.5.5 remote-as 450
neighbor 5.5.5.5 update-source Loopback0
neighbor 5.5.5.5 route-reflector-client
权重(weight)
- 基于思科架构的产品并非专有命名;尽管如此,在其他厂商中也可找到类似设备。
- 当在路由器进行本地配置时,默认仅支持本地路由策略,并无法向外发送给BGP邻居。
- 该模块允许设置范围从0至65535;数值越大表示优先级越高。
- 当在路由器上进行本地配置时,默认生成的路径权重为32768;若来自其他BGP邻居,则权重设为0。
通过检查R4关于1.1.1.1 bgp路由表的数据发现:实际上存在两条通往同一目的地址的路径;其中一条路径将通过R4连接到2.2.2.2节点来实现。
R4#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
* i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i
*> 2.2.2.2 0 200 100 i
*> 2.2.2.0/24 2.2.2.2 0 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i
*> 4.4.4.0/24 0.0.0.0 0 32768 i
*>i 5.5.5.0/24 5.5.5.5 0 100 0 i
我们修改5.5.5.5这条路线的权重,可以影响R4的选路
R4(config)#router bgp 450
R4(config-router)#nei 5.5.5.5 weight 10
R4#clear ip bgp * so in
R4#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 100 10 300 100 i
* 2.2.2.2 0 200 100 i
*> 2.2.2.0/24 2.2.2.2 0 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 10 300 i
*> 4.4.4.0/24 0.0.0.0 0 32768 i
*>i 5.5.5.0/24 5.5.5.5 0 100 10 i
看到所有属于5....*节点的学习相关的条目其权重被重新计算。这会导致整个邻居节点的数据受到影响。通常情况下我们不建议采用这种方法。
R4(config)#router bgp 450
R4(config-router)#no nei 5.5.5.5 weight 10
可以使用route-map对特定路由的权重进行修改
R4(config)#access-list 1 permit 1.1.1.0
R4(config)#route-map R5 per
R4(config-route-map)#mat ip ad 1
R4(config-route-map)#set weight 10
R4(config)#route-map R5 per 20
R4(config)#router bgp 450
R4(config-router)#nei 5.5.5.5 route-map R5 in
R4(config-router)#do clea ip bgp * so in
R4(config-router)#do sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 100 10 300 100 i
* 2.2.2.2 0 200 100 i
*> 2.2.2.0/24 2.2.2.2 0 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i
*> 4.4.4.0/24 0.0.0.0 0 32768 i
*>i 5.5.5.0/24 5.5.5.5 0 100 0 i
本地优先级(local preference)
- 确定自由决定属性
- 指示给AS内的路由器选择离开该AS的最优先路径
- 路径的整体成本值越高,则该路径越优
- 仅向IBGP类型的邻居发送
- 避免将此信息传递给EBGP类型的邻居
- 默认本地优先级设置为100
将上面的实验环境还原
R6#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
* i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i
*>i 4.4.4.4 0 100 0 200 100 i
*>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i
*>i 4.4.4.0/24 4.4.4.4 0 100 0 i
*>i 5.5.5.0/24 5.5.5.5 0 100 0 i
*> 6.6.6.0/24 0.0.0.0 0 32768 i
通过观察发现,在目标地址1.1.1.0/24前有两个可用路径可选,默认情况下该设备会采用地址4.4.4.4作为下一跳。为了引导数据流量通过指定路径前往目标服务器,在设备管理界面中需对相关路由器进行配置调整:首先在设备A(R5)端口处设置相应的端口转发规则;其次在设备B(R6)端口处实施本地优先级策略以影响下一跳的路由选择。
R5(config)#router bgp 450
R5(config-router)#bgp default local-preference 500
R5(config-router)#do clea ip bgp * so out
查看R6的BGP表
R6#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 500 0 300 100 i
*>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 500 0 300 i
*>i 4.4.4.0/24 4.4.4.4 0 100 0 i
*>i 5.5.5.0/24 5.5.5.5 0 500 0 i
*> 6.6.6.0/24 0.0.0.0 0 32768 i
如果需要将某台路由器配置为整个网络区域划分(AS)的主要出口节点,则应调整其设备上的默认本地优先级设置
如果只是想改某一条路由的路径,建议用route-map
R5(config)#access-list 1 permit 1.1.1.0
R5(config)#route-map R6 per
R5(config-route-map)#mat ip add 1
R5(config-route-map)#set local-preference 110
R5(config-route-map)#exit
R5(config)#route-map R6 per 20
R5(config-route-map)#router bgp 450
R5(config-router)#nei 6.6.6.6 route-map R6 out
R5(config-router)#do clea ip bgp * so out
查看R6的BGP表
R6#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 110 0 300 100 i
*>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i
*>i 4.4.4.0/24 4.4.4.4 0 100 0 i
*>i 5.5.5.0/24 5.5.5.5 0 100 0 i
*> 6.6.6.0/24 0.0.0.0 0 32768 i
AS_PATH
公认强制属性
表示前往目标网络的路由经过的自制系统号列表,并告知该路由的自治系统号位于列表末尾
目的:防止循环;当向EBGP发送时会包含本机的AS号;而向IBGP发送时不调整AS-path
仅当AS之间发生传递时才会发生改变;若在AS_PATH中包含自身对应的AS号,则该节点将不会进行学习与传播
如果R1不想让AS450学习到 1.1.1.0 这个条目,我们可以在AS_PATH中手动加上AS450
首先在R2上查看一下 1.1.1.0 的AS_PATH,只有AS100
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 1.1.1.1 0 0 100 i
在R1上配置 1.1.1.0 离开AS100的 route-map 追加AS450
R1(config)#access-list 1 permit 1.1.1.0
R1(config)#route-map AS100out per
R1(config-route-map)#ma ip add 1
R1(config-route-map)#set as-path prepend 450
R1(config-route-map)#exit
R1(config)#route-map AS100out per 20
R1(config-route-map)#router bgp 100
R1(config-router)#nei 2.2.2.2 route-map AS100out out
R1(config-router)#nei 3.3.3.3 route-map AS100out out
R1(config-router)#do clea ip bgp * so out
在R2上再次查看 1.1.1.0 的AS_PATH
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 1.1.1.1 0 0 100 450 i
我们发现AS450中就学习不到这个条目了
R6#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i
*>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i
*>i 4.4.4.0/24 4.4.4.4 0 100 0 i
*>i 5.5.5.0/24 5.5.5.5 0 100 0 i
*> 6.6.6.0/24 0.0.0.0 0 32768 i
AS_PATH同样可用于评估路径的好坏程度。当前往同一目的地时,在权重与本地优先级相同的情况下,则可能依据AS_PATH的长度来选择最优路径。AS_PATH数值越短则代表离目标点越近,路径更为理想。
还原实验环境,查看R6的bgp表,我们通过修改AS_PATH长度来影响路线选择
R6#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 4.4.4.4 0 100 0 200 100 i
* i 5.5.5.5 0 100 0 300 100 i
将位于 R2 上的 1.1.1.0 路由器交由 R4 进行配置,并增加其 AS_PATH 长度。以防止对其他 AS 的影响,请注意推荐追加的 AS 号应为其自身的 AS 号。如 R2 则可选择 200。
R2(config)#access-list 1 permit 1.1.1.0
R2(config)#route-map R4out per
R2(config-route-map)#ma ip add 1
R2(config-route-map)#set as pre 200 200 200
R2(config-route-map)#route-map R4out per 20
R2(config-route-map)#router bgp 200
R2(config-router)#nei 4.4.4.4 route-map R4out out
R2(config-router)#do clea ip bgp * so out
查看R4的BGP表
R4#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i
* 2.2.2.2 0 200 200 200
200 100 i
AS_PATH有4种
-
有序AS_PATH
- 正常的AS_PATH都是会按照顺序进行排列,称为有序
- 450 300 100 i
-
非顺序AS_PATH
-
当多个来自不同 AS 的路由条目被汇总时, 所产生的汇总路由携带的 AS_PATH 将是非顺序的
-
其明细数据来源于 AS300 和 AS100, 不管处理顺序如何, 因此会存在非顺序状态
-
450 {300 100} i
- 联邦内有序AS_PATH
- 联邦内无序AS_PATH
ORIGIN
- 公认强制属性
-
标识路由源有三种可能:
- 经由BGP网络(源自IGP)
- 来自EGP早期协议重发布
- 不完整/缺失信息(如其他渠道提供的不完整/缺失信息)
-
路由优选顺序: lowest origin code (IGP > EGP > Incomplete)
-
还原实验环境
R2(config)#access-list 1 per 1.1.1.0
R2(config)#route-map R4out per
R2(config-route-map)#mat ip ad 1
R2(config-route-map)#set origin incomplete
R2(config-route-map)#route-map R4out per 20
R2(config-route-map)#router bgp 200
R2(config-router)#nei 4.4.4.4 route-map R4out out
R2(config-router)#do clea ip bgp * so out
查看R4上路径的选择
R4#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i
* 2.2.2.2 0 200 100 ?
MED
可选非传递属性
是一种指标, 用来指示进入Autonomous System (AS)的最佳路径, 特别是当一个AS拥有多个连接入口时, 自治系统可以通过MED动态地影响其他AS选择最佳进入路径。
具有较小度量值的路径更为优秀
MED通过Autonomous System边界交换, 并且仅限于当前Autonomous System内部传播, 不会向外发送。
R1(config)#access-list 1 permit 1.1.1.0
R1(config)#route-map R2out per
R1(config-route-map)#ma ip add 1
R1(config-route-map)#set met
R1(config-route-map)#set metric 100
R1(config-route-map)#route-map R2oute per 20
R1(config-route-map)#router bgp 100
R1(config-router)#nei 2.2.2.2 route-map R2out out
R1(config-router)#do clea ip bgp * so
查看修改的效果
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 1.1.1.1 100 0 100 i
BGP在重发布IGP条目的时候,会将IGP条目的度量值用作MED
R4(config)#access-list 1 permit 192.168.56.0
R4(config)#route-map o-b per
R4(config-route-map)#ma ip ad 1
R4(config-route-map)#router bgp 450
R4(config-router)#redistribute ospf 1 route-map o-b
在R2上查看度量值,发现将OSPF的开销作为MED属性
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 192.168.56.0 4.4.4.4 20 0 450 ?
Next_Hop
- 标识必须遵循特性
- 当EBGP邻居间进行信息传递时,默认会更新下一跳为advertisements。
- 在IBGP邻居间的信息传递过程中,默认下一跳属性不会发生变化。
- 建议在接收到来自EBGP邻居的更新信息时(即收到update消息),应将其转发给IBGP邻居,并添加Next-hop-self字段。
- 不同AS之间的连接通常采用多路访问网络(MPLS)技术,在这种情况下可以通过next-hop-unchange机制实现类似路由重定向的效果。
Community(团体属性/社区属性)
- 支持可选择传递
- 提供一种标识符旨在简化对路由策略的操作
- 拥有某种属性后,则可以根据该社区值而非每条单独的路由来配置 BGP 属性设置

还原实验环境
假设 1.1.1.0/24、10.10.10.0/24 是属于某公司的AB两个个部门。AS300需要对B部门的条目修改,不让AS450收到。做到让AS450优选从AS200去往这个部门。
A:标签100:1
B:标签100:2
一个条目可同时拥有多个标签用于标识不同类别或组别。例如包含关系标签的设置可进一步细化这些分类并以设定不同区域或区间的方式分配具体范围
银河系——太阳系——地球——亚洲——中国——江苏——镇江
R1(config)#access-list 1 per 1.1.1.0
R1(config)#access-list 2 per 10.10.10.0
R1(config)#route-map R2R3out per
R1(config-route-map)#ma ip ad 1
R1(config-route-map)#set community 100:1
R1(config-route-map)#route-map R2R3out per 20
R1(config-route-map)#ma ip ad 2
R1(config-route-map)#set community 100:2
R1(config-route-map)#route-map R2R3oute per 30
R1(config-route-map)#router bgp 100
R1(config-router)#nei 2.2.2.2 route-map R2R3out out
R1(config-router)#nei 3.3.3.3 route-map R2R3out out
R1(config-router)#nei 2.2.2.2 send-community
R1(config-router)#nei 3.3.3.3 send-community
# 别忘了开启团体属性的发送
查看团体属性
R3(config)#ip bgp-community new-format
R3(config)#do sh ip bgp 10.10.10.0
BGP routing table entry for 10.10.10.0/24, version 11
Paths: (1 available, best #1, table default)
Advertised to update-groups:
1
Refresh Epoch 1
100
1.1.1.1 from 1.1.1.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, valid, external, best
Community: 100:2
rx pathid: 0, tx pathid: 0x0
后面可以根据不同的community属性加上策略
R3(config)#ip community-list 1 permit 100:1
R3(config)#route-map R5out deny
R3(config-route-map)#match community 1
R3(config-route-map)#route-map R5out per 20
R3(config-route-map)#router bgp 300
R3(config-router)#nei 5.5.5.5 route-map R5out out
R3(config-router)#do clea ip bgp * so
查看R5的bgp表,发现现在已经无法从R3学习到有100:1标签的路由了
R5#sh ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 14
Paths: (1 available, best #1, table default)
Advertised to update-groups:
1
Refresh Epoch 1
200 100
4.4.4.4 (metric 11) from 6.6.6.6 (6.6.6.6)
Origin IGP, metric 0, localpref 100, valid, internal, best
Originator: 4.4.4.4, Cluster list: 6.6.6.6
rx pathid: 0, tx pathid: 0x0
有默认操作的团体属性
属性具备默认功能,在不需额外设置策略的情况下,默认配置的条目会自动触发对应的行为
<1-4294967295> community number
# 正常的团体属性
aa:nn community number in aa:nn format
# 正常的团体属性
internet Internet (well-known community)
# 表示所有的条目,如果想匹配any,可以用这个
local-AS Do not send outside local AS (well-known community)
# 不要让这个条目离开自己这个AS,也就是不会对EBGP邻居更新这个条目
no-advertise Do not advertise to any peer (well-known community)
# 告知下一个AS,不要让这个条目给第三个路由器知道
no-export Do not export to next AS (well-known community)
# 告知下一个AS,不要让这个条目给第三个AS知道
none No community attribute
# 去除所有community标签
还原实验环境
让R6的6.6.6.0带上 local-AS 属性
R6(config)#access-list 1 permit 6.6.6.0
R6(config)#route-map R4R5out per
R6(config-route-map)#ma ip ad 1
R6(config-route-map)#set commu local-AS
R6(config-route-map)#route-map R4R5out per 20
R6(config-route-map)#router bgp 450
R6(config-router)#nei 4.4.4.4 route-map R4R5out out
R6(config-router)#nei 5.5.5.5 route-map R4R5out out
R6(config-router)#nei 4.4.4.4 send-comm
R6(config-router)#nei 5.5.5.5 send-comm
R6(config-router)#do clea ip bgp * so
查看R4上的条目是否有这个属性
R4#sh ip bgp 6.6.6.0
BGP routing table entry for 6.6.6.0/24, version 12
Paths: (1 available, best #1, table default, not advertised outside localAS)
Not advertised to any peer
Refresh Epoch 2
Local
6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
Origin IGP, metric 0, localpref 100, valid, internal, best
Community: local-AS
rx pathid: 0, tx pathid: 0x0
查看其他AS是否能学习到 6.6.6.0
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 1.1.1.1 0 0 100 i
*> 2.2.2.0/24 0.0.0.0 0 32768 i
* 3.3.3.0/24 4.4.4.4 0 450 300 i
*> 1.1.1.1 0 100 300 i
*> 4.4.4.0/24 4.4.4.4 0 0 450 i
*> 5.5.5.0/24 4.4.4.4 0 450 i
* 1.1.1.1 0 100 300 450 i
让 6.6.6.0 携带上 no-advertise
R6(config)#route-map R4R5out per 10
R6(config-route-map)#no set commu local-AS
R6(config-route-map)#set commu no-adv
查看R4是否有这个属性
R4#sh ip bgp 6.6.6.0
BGP routing table entry for 6.6.6.0/24, version 13
Paths: (1 available, best #1, table default, not advertised to any peer)
Not advertised to any peer
Refresh Epoch 4
Local
6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6)
Origin IGP, metric 0, localpref 100, valid, internal, best
Community: no-advertise
rx pathid: 0, tx pathid: 0x0
然后查看R2是否学习到
R2#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 1.1.1.1 0 0 100 i
*> 2.2.2.0/24 0.0.0.0 0 32768 i
* 3.3.3.0/24 4.4.4.4 0 450 300 i
*> 1.1.1.1 0 100 300 i
*> 4.4.4.0/24 4.4.4.4 0 0 450 i
*> 5.5.5.0/24 4.4.4.4 0 450 i
* 1.1.1.1 0 100 300 450 i
还原实验环境,在R4通告R2的时候让6.6.6.0携带上 no-advertise
R4(config)#access-list 1 per 6.6.6.0
R4(config)#route-map R2 per
R4(config-route-map)#ma ip ad 1
R4(config-route-map)#set commu no-ex
R4(config-route-map)#route-map R2 per 20
R4(config-route-map)#router bgp 450
R4(config-router)#nei 2.2.2.2 route-map R2 out
R4(config-router)#nei 2.2.2.2 send-comm
R4(config-router)#do clea ip bgp * so
查看R2是否有这个属性
R2#sh ip bgp 6.6.6.0
BGP routing table entry for 6.6.6.0/24, version 8
Paths: (2 available, best #2, table default, not advertised to EBGP peer)
Not advertised to any peer
Refresh Epoch 1
100 300 450
1.1.1.1 from 1.1.1.1 (1.1.1.1)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 1
450
4.4.4.4 from 4.4.4.4 (4.4.4.4)
Origin IGP, localpref 100, valid, external, best
Community: no-export
rx pathid: 0, tx pathid: 0x0
到R1上查看路由条目,发现已经不能从R2学到这个条目了
R1#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
*> 2.2.2.0/24 2.2.2.2 0 0 200 i
*> 3.3.3.0/24 3.3.3.3 0 0 300 i
* 4.4.4.0/24 3.3.3.3 0 300 450 i
*> 2.2.2.2 0 200 450 i
* 5.5.5.0/24 2.2.2.2 0 200 450 i
*> 3.3.3.3 0 300 450 i
*> 6.6.6.0/24 3.3.3.3 0 300 450 i
如果AS200希望AS100能够持续学习这个条目,则可以通过以下操作使no-export属性失效
R2(config)#ip community-list 1 per no-export
R2(config)#access-list 1 per 6.6.6.0
R2(config)#route-map R4 per
R2(config-route-map)#ma ip add 1
R2(config-route-map)#set comm-list 1 delete
R2(config-route-map)#route-map R4 per 20
R2(config-route-map)#router bgp 200
R2(config-router)#nei 4.4.4.4 route-map R4 in
R2(config-router)#do clea ip bgp * so in
查看R2上 6.6.6.0 的属性
R2#sh ip bgp 6.6.6.0
BGP routing table entry for 6.6.6.0/24, version 9
Paths: (2 available, best #2, table default)
Advertised to update-groups:
1
Refresh Epoch 3
100 300 450
1.1.1.1 from 1.1.1.1 (1.1.1.1)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 3
50
4.4.4.4 from 4.4.4.4 (4.4.4.4)
Origin IGP, localpref 100, valid, external, best
rx pathid: 0, tx pathid: 0x0
查看R1是否可以学习到这个条目
R1#sh ip bgp
BGP table version is 8, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
*> 2.2.2.0/24 2.2.2.2 0 0 200 i
*> 3.3.3.0/24 3.3.3.3 0 0 300 i
* 4.4.4.0/24 3.3.3.3 0 300 450 i
*> 2.2.2.2 0 200 450 i
* 5.5.5.0/24 2.2.2.2 0 200 450 i
*> 3.3.3.3 0 300 450 i
* 6.6.6.0/24 2.2.2.2 0 200 450 i
*> 3.3.3.3 0 300 450 i
