目录
BGP Link Bandwidth Extended Community
实验:cost community在联邦eBGP邻居之间的传递
neighbor remove-private-as命令注解
| 报文名称 | 作用是什么 | 什么时候发包 |
| open | 协商BGP邻居的各项参数,建立邻居关系 | 通过TCP建立BGP连接,发送open报文 |
| update | 进行路由信息的交换 | 连接建立后,有路由需要发送或路由变化时,发送update通告对端路由信息 |
| notification | 报告错误,中止邻居关系 | 当BGP在运行中发现错误时,要发送notification报文通告BGP对端 |
| keepalive | 维持邻居关系 | 定时发送keepalive报文以保持BGP邻居关系的有效 |
| route-refresh | 为保证网络稳定,触发更新路由的机制 | 当路由策略发生变化时,触发请求邻居重新通告路由 |
| Peer状态名称 | 发什么包 | 在做什么 |
| ldle | 尝试建立TCP连接 | 开始准备TCP的连接并监视远程peer启动TCP连接,启用BGP时,要准备足够的资源 |
| Connect | 发TCP包 | 正在进行TCP连接,等待完成中,认证都是在TCP建立期间完成的。如果TCP连接不上则进入Active状态,反复尝试连接 |
| Active | 发TCP包 | TCP连接没建立成功,反复尝试TCP连接 |
| OpenSent | 发Open包 | TCP连接建立已经成功,开始发送Open包,Open包携带参数协商对等体的建立 |
| OpenConfirm | 发Keepalive包 | 参数、能力特性协商成功,自己开始发送Keepalive包,等待对方的Keepalive包 |
| Established | 发Update包 | 已经收到对方的Keepalive包,双方能力特性一致,开始使用Update通告路由信息 |
运行BGP的路由器被称为BGP speaker
BGP对等体也叫BGP邻居,建立基于TCP的关系EBGP : BGP位于不同自治系统的路由器之间,称为EBGP
EBGP邻接关系,必须满足三个条件
-EBGP之间自制系统号不同
-定义邻居建立TCP会话
-neighbor中指定的IP地址要可达IBGP:位于同一个自治系统的路由器之间运行
建立IBGP邻接关系,满足的条件-自治系统号相同
-定义邻居建立TCP会话
BGP同步规则指出,BGP路由器不应使用通过IBGP获悉的路由或将其通告给外部邻居,除非该路由是本地的或通过IGP获悉的
CiscoIOS默认关闭同步同步关闭:不需要从IGP学到该路由就转发(会产生路由黑洞问题)
同步开启:则路由器通过IBGP获悉路由后,将等待IGP将该路由传遍整个自治系统,然后再将其通告给外部领居

全互联IBGP邻居关系
IBGP全互联虽然能解决transit AS内的路由黑洞问题,但是却造成BGP路由器需耗费大量资源维护BGP连接的新问题
解决办法:
路由反射器、联邦
BGP防环是通过AS_PATH实现的,而AS_PATH仅仅在路由离开AS才回被更改,因此在AS内,IBGP就没有EBGP的防环能力,为了防止环路的出现,BGP路由器不会将从IBGP邻居学习过来的路由再通告给自己其他IBGP邻居。(在AS内部,AS-PATH不会改变,因此很容易出现环路)
·当存在多条路径时,BGP Router只选取最优的路由来使用(没有负载均衡的情况下)
·BGP只把自己使用的路由传递给BGP领居·从EBGP获得的路由会向它所有BGP领居通告(包括EBGP和IBGP)
·从IBGP获得的路由不向它的IBGP邻居通告(水平分割)
·从IBGP获得的路由是否通告给它的EBGP领居要视IGP和BGP同步的情况来决定
·BGP表:包含了从邻居学习所有路由,以及到达目的网段的多个路径和属性
·路由表∶列出了到达目的网段的最佳路径,EBGP路由AD为20,IBGP路由AD为200
默认60s ,keepalive计时器不会在Open消息中交互
如果当前手工配置的 keepalive timer 小于min ( holdtime ) /3,则取配置值
如果当前手工配置的keepalive timer 大于min ( holdtime ) /3,则取 int[min ( holdtime ) /3]其中min ( holdtime )为两台BGP邻居间holdtime的最小值
小结:选小的
CISCO默认180s ( 3倍KEEPLIVE timer ),该计时器包含在open报文中
必须收到一个KEEPLIVE 或更新消息前所允许经过的最大时间。如果两端Holdtime不一致,双方接受较小的的时间
***创建BGP进程***
Router(config)#router bgp autonomous-system
·仅仅执行命令router bgp并不能在路由器上激活BGP,必须至少执行一个子命令才能在路由器上激活BGP进程
·在路由器上只能配置一个BGP实例
-----------------------------------------------------------------------------------------
***指定BGP邻居及激活BGP会话***
Router(config-router)# neighbor {ip-address | peer-group-name} remote-as autonomous-system
·指定邻居的IP地址必须路由可达
.BGP邻居需手工指定
·AS决定了与邻居建立的是EBGP会话还是IBGP会话
-----------------------------------------------------------------------------------------
***指定BGP将通告的网络***
Router(config-router)network network-number [mask network-mask] [route-map map-tag]
·BGP命令network为通告哪些IGP路由进BGP进程,而不是在接口上启用BGP
·network支持无类前缀,前缀必须与路由表中的条目完全匹配
·如果不指定mask,只通告主类网络号,而且仅当主类网络中至少有一个子网出现在IP路由表中,BGP才会将该主类网络作为一条BGP路由通告
·指定了mask,则仅当路由选择表中有与该网络完全匹配的条目时才被通告出去
-----------------------------------------------------------------------------------------
***BGP同步***
Router(config-router)#no synchronization //关闭同步(默认关闭)
Router(config-router)#synchronization //开启同步
-----------------------------------------------------------------------------------------
***BGP router-id***
Router(config-router)# bgp router-id x.x.x.x //手工设置BGP routerID
-----------------------------------------------------------------------------------------
***修改next-hop***
·BGP是AS-by-As的路由协议,而不是router-by-router的路由协议
·在BGP中,next-hop并不意味着是下一台路由器,而是到达下一个AS的IP地址
·EBGP中,默认next-hop为发送更新的邻居路由器的IP地址
·IBGP中,从EBGP传来的next-hop属性在IBGP中保持不变的被传递
-----------------------------------------------------------------------------------------
***EBGP multihop***
Router(config-router)#neighbor {ip-address | peer-group-name} ebgp-multihop [ttl]
·建立对等关系时,如果不进行额外配置,EBGP路由器只能使用与外部EBGP路由器直接相连的接口地址
·以上命令如若不显式指定跳数时,则为255跳
-----------------------------------------------------------------------------------------
***BGP身份验证***
Router(config-router)#neighbor {ip-address | peer-group-name} password string
·BGP支持MD5邻居身份验证
·启用身份验证后,将对通过对等体之间的TCP连接传输的所有数据等进行验证
·认证都是在TCP建立连接的时候完成的
断开相应的TCP连接,通过这些会话收到的所有信息都将失效,并从BGP表中删除
clear ip bgp {neighbor-address}
clear ip bgp *
软重置( soft reconfiguration )
-不拆除并重建TCP或BGP连接,而是仅触发更新操作以便让新的路由策略生效
-软重置可以仅用于出站或入站策略,也可同时用于出入站策略
出站软重置
–不会拆除TCP连接,不会重置BGP会话,仅触发更新操作以便让新的路由策略生效(发送update消息)
–需要修改出站策略时,建议使用该命令
-clear ip bgp soft out
入站软重置
-本地发送route-refresh给所有BGP邻居
-clear ip bgp soft in
cisco ios 12.1开始全面支持入站路由的动态软重配置,但在之前的版本在使用入站软重配置之前必须首先在BGP进程中增加如下配置∶
neighbor x.x.x.x soft-reconfiguration inbound
然后再使用clear ip bgp soft in命令
这条命令会将x.x.x.x邻居发送过来的BGP路由存储在内存中,当配置入站软重置后,路由器不再向邻居发送更新请求,而是直接在内存中存储的路由中执行新配置的入站策略,以此来防止触发大批量的路由更新而造成资源的浪费,但是这种操作仍会耗费内存,因此在使用的时候要非常慎重
***show ip bgp***
Network Next Hop Metric LocPrf Weight Path
*>i4.4.4.0/24 3.3.3.3 0 100 0 400 i
第一栏的可能取值如下:
* 可用的路由(但不一定是最优)
s 被抑制的路由条目,例如做了路由汇总,抑制了明细
d 被惩罚( dampening )的路由,路由受到了惩罚,虽该路由当前可能正常,但惩罚期结束前不会被通告
h 被惩罚( dampening )的路由,路由可能出现了故障( down ),有历史信息,但没有最佳路由
r 路由没有被装载进RIB表,例如由于AD值等原因导致
S 大写的s ,stale,表示过期的路由
第二栏
> BGP算法选出的最优路径
第三栏
为空,或为i。为空表示该路由从EBGP邻居获取,为i表示这是从IBGP学习到的路由
-------------------------------------------------------------------------------------------
***show ip bgp 4.4.4.0***
BGP routing table entry for 4.4.4.0/24, version 2
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
Not advertised to any peer
400
3.3.3.3 (metric 65) from 3.3.3.3 (3.3.3.3)
// ^ ^ ^ ^
// next_hop 到达该next_hop BGP领居的 领居的RouterID
// 的metric(IGP) 更新源地址
Origin IGP, metric 0, localpref 100, valid, internal, best
| 公认属性 Well-Known | 公认强制属性 Well-known mandatory(BGP路由器要支持,包含在update包) 公认自由决定属性 Well-known discretionary(BGP路由器要支持,不一定包含在update包) | Origin AS-Path Next hop Local-Preference ATOMIC_Aggregate |
| 可选属性 Optional | 可选传递的 Optional transitive(可以不支持该属性,但即使不支持也应当接受包含该属性的路由并传递给其他邻居) 可选非传递的 Optional non-transitive(可以不支持该属性,不识别的BGP进程可以忽略包含这个属性的更新消息,并且不传递给其他BGP邻居) | Community Aggregator MED Originator_ID Cluster_list Weight |
Cisco私有
本地路由器有效
- 在路由器本地配置,只提供本地路由策略,不会传播给任何BGP邻居
- 范围:0~65535;越大越优先
- 路由器本地始发的路径默认权重为32768,从其他BGP邻居学习到的为0
- 告诉AS中的路由器,哪条路径是离开AS的首选路径
- 值越高路径越优
- 只发送给IBGP邻居,而不能传递给EBGP邻居
- 默认本地优先级为100
bgp default local-preference 500 //修改默认LP值
- 是前往目标网络的路由经过的自制系统号列表,通告该路由的自治系统号位于列表末尾
- 作用︰确保无环,通告给EBGP时会加上自己的AS号;通告给IBGP时不修改AS-path
- AS_SEQENCE:一个有序的AS号列表
- AS_SET:一个去往特定目的地所经路径上的无序AS号列表
标识路由的起源,有下列3种可能:
- i通过BGP network,也就是起源于IGP,因为BGPnetwork必须保证该网络在路由表中
- e是由EGP这种早期的协议重发布而来
- ?Incomplete从其他渠道学习到的,路由来源不完全(确认该路由来源的信息不完全)。(重发布的路由)
- 是一种度量值,用于向外部邻居指出进入AS的首选路径,即当入口有多个时,自治系统可以使用MED动态的影响其他AS如何选择进入路径
- 度量值越小路径越优
- MED是在AS之间交换,MED发送给EBGP对等体,这些路由器在AS内传播MED,不传递给下一个AS
- 默认情况下,仅当路径来自同一个AS中的不同EBGP邻居时,路由器才比较他们的MED属性
- CISCO默认MED为0
MED设置方法:
- 将IGP路由引入BGP时关联Route-map进行设置
- 对BGP Peer应用INOUT方向的Route-map进行设置
- 非 Route-map(自动)方式:
使用network或redistribute方式将IGP路由引入BGP时,MED将继承IGP路由的Metric(直 连路由及静态路由的Metric为0)
使用aggregate-address方式引入路由,则MED为空
总结如下∶
- network 本地从IGP路由协议学习到的路由进BGP,MED值继承IGP协议中的metric
- network 本地直连接口的网段进BGP,MED值为0;network本地静态路由进BGP,MED值为0
- redistribute 本地从IGP路由协议学习到的路由进BGP;MED值继承IGP协议中的metric
- redistribute 本地直连接口网段进BGP,MED值为0;redistribute本地静态路由进BGP,MED值为0
- 从EBGP领居收到路由更新,下一跳是领居发送更新的接口IP
- 路由来自IBGP邻居,并描述的是AS外的目的地(下一跳是AS外发送这条路由更新的接口IP)
- 如果路由传递自IBGP邻居,并由AS内BGP路由器引入
- 如果是通过aggregate-address 命令被注入的,那么next-hop等于执行汇总路由器(的更新源IP)
- 如果是通过network或重发布注入的,那么在注入前该前缀的IGP下一跳将成为BGP的next-hop

NEXT_HOP on NBMA,要注意有没有做映射
- 一种标记,用于简化路由策略的执行
- 可以将某些路由分配一个特定的COMMUNITY属性,之后就可以基于COMMUNITY值而不是每条路由进行BGP属性的设置了
![]()

aggregate-address 172.16.0.0 255.255.0.0 summary-only
BGP自动汇总( auto-summary )只汇总重发布引入的路由,以及使用network命令有类宣告方式引入的路由。目前Cisco IOS默认关闭自动汇总

R1关闭自动汇总
- network主类
- 结果:R2上看不到BGP路由
-
- network明细
- 结果:
- Network Next Hop Metric LocPrf Weight Path
- *>i172.16.1.0/24 10.1.12.1 0 100 0 i
-
- 重分布
- Network Next Hop Metric LocPrf Weight Path
- r>i10.1.12.0/24 10.1.12.1 0 100 0 ?
- *>i172.16.1.0/24 10.1.12.1 0 100 0 ?
- *>i172.16.2.0/24 10.1.12.1 0 100 0 ?
- *>i172.16.3.0/24 10.1.12.1 0 100 0 ?
- //直连优先级最高,重发布进BGP的路由AD值为200
- //?表示是重发布进来的
R1开启自动汇总
- network主类
- Network Next Hop Metric LocPrf Weight Path
- *>i172.16.0.0 10.1.12.1 0 100 0 i
-
- network明细
- Network Next Hop Metric LocPrf Weight Path
- *>i172.16.1.0/24 10.1.12.1 0 100 0 i
-
- 重分布
- Network Next Hop Metric LocPrf Weight Path
- *>i10.0.0.0 10.1.12.1 0 100 0 ?
- *>i172.16.0.0 10.1.12.1 0 100 0 ?
小结:关闭汇总就没效了,开启汇总只有network明细不汇总

aggregate-address 汇总地址
- R3(config-router)#aggregate-address 172.16.0.0 255.255.0.0
- //R5上看到汇总和明细都有
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.34.3 0 0 300 i
- *> 172.16.1.0/24 10.1.34.3 0 300 100 i
- *> 172.16.2.0/24 10.1.34.3 0 300 100 i
- *> 172.16.10.0/24 10.1.34.3 0 300 200 i
- *> 172.16.11.0/24 10.1.34.3 0 300 200 i
aggregate-address 汇总地址 summary-only
- R3(config-router)#aggregate-address 172.16.0.0 255.255.0.0 summary-only
- //R5上只有条汇总
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.35.3 0 0 300 i
- R5#sho ip bgp 172.16.0.0
- BGP routing table entry for 172.16.0.0/16, version 6
- Paths: (1 available, best #1, table Default-IP-Routing-Table)
- Not advertised to any peer
- 300, (aggregated by 300 10.1.35.3) //汇总来自AS为300,IP为10.1.35.3的接口
- 10.1.35.3 from 10.1.35.3 (10.1.35.3)
- Origin IGP, metric 0, localpref 100, valid, external, atomic-aggregate, best
aggregate-address 汇总地址 summary-only as-set
- R3(config-router)#$ddress 172.16.0.0 255.255.0.0 summary-only as-set
- //R5
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.35.3 0 0 300 {100,200} i <-
- //在R1上重发布,R3上看
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 0.0.0.0 100 32768 {100,200} ? <-
- s> 172.16.1.0/24 10.1.13.1 0 0 100 ?
- s> 172.16.2.0/24 10.1.13.1 0 0 100 ?
- s> 172.16.10.0/24 10.1.23.2 0 0 200 i
- s> 172.16.11.0/24 10.1.23.2 0 0 200 i
- 可以继承明细路由的BGP某些路径属性。as-set继承明细属性的规则如下∶
- As-path 将收到的所有明细路由的as号都放置在{}中,计算AS_Path长度时这些AS只被算为1个AS
- origin 继承最差的origin属性
- community 继承所有明细路由的community
- MED 不继承
- LP 取明细路由中LP的最大值
- NEXT_HOP 汇总路由为0.0.0.0(因为汇总路由为本地产生)
aggregate-address 汇总地址 suppress-map xxx as-set
- R3(config-router)#$.16.0.0 255.255.0.0 summary-only as-set suppress-map 1
- //R5
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.35.3 0 0 300 {100,200} ?
- *> 172.16.10.0/24 10.1.35.3 0 300 200 i
- *> 172.16.11.0/24 10.1.35.3 0 300 200 i
- 用于宣告聚合及选定的明细路由(抑制特定的明细路由),后面跟上route-map xx,被route-map 匹配(permit)的路由将被过滤,其他放行
- 抑制列表虽然调用route-map,但是route-map只能用于匹配,不能用于设置属性(不能用set 命令)
针对特定邻居取消抑制
- R3(config-router)#neighbor 10.1.34.4 unsuppress-map 1
- //R3上放行172.16.1.0这条明细
- //R4
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.34.3 0 0 300 {100,200} ?
- *> 172.16.1.0/24 10.1.34.3 0 300 100 ?
advertise-map
- R3(config-router)#$.16.0.0 255.255.0.0 summary-only as-set advertise-map 1
- //当advertise-map匹配的路由全部都没有,汇总路由会消失;没被匹配的路由没有,只要advertise-map匹配的路由还在,汇总就还在
- //继承领居传来的community=no-adv
attribute-map
- R3(config-router)#$.16.0.0 255.255.0.0 summary-only as-set attribute-map aa
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.34.3 66 0 300 100 i
- //给汇总路由设置属性
- //这里设置的是Metric值
| . | 匹配任何单个的字符,包括空格 |
| ^ | 一个字符串的开始 |
| $ | 一个字符串的结束 |
| _ | 匹配任意的一个分隔符如^、$、空格、tab、逗号、{、} |
| | | 管道符,逻辑或 |
| \ | 转义符,用来将紧跟其后的控制字符转变为普通字符 |
示例:
| ^a.$ | 匹配一个以a开始,任意单一字符结束的字符串,如a0,a!等 |
| ^100_ | 匹配100 、100 200、100 300 400等 |
| ^100$ | 匹配100 |
| 100$|400$ | 匹配100、1400、300 400等 |
| ^ | 仅仅匹配(65000) |
| * | 匹配前面字符0次或多次出现 |
| + | 匹配前面字符1次或多次出现 |
| ? | 匹配前面字符的0次或1次出现 |
示例:
| abc*d | 匹配abd、abcd、abccd、abcccd等 |
| abc+d | 匹配abcd、abccd、abcccd等 |
| abc?d | 匹配abd、abcd、abcdefg等 |
| a(bc)?d | 匹配ad、abcd、aaabcd等 |
·一个乘法字符可以应用于一个单字符或多个字符,如果应用于多字符,需将字符串放入( )中
| [ ] | 表示一个范围。只匹配包含在范围内的字符之一。 可以在一个范围的开始使用^来排除范围内的所有字符,也可以使用下划线_来指定一个区间。 |
示例:
| [abcd] | 匹配只要出现了a、b、c、d的内容 |
| [a-c 1-2]$ | 匹配a、a1、62、1b、xv2等 |
| [^act]$ | 匹配不以a或c或t结尾的内容 |
| [123].[7-9] | 159 220、91 70 |
| ^$ | 匹配本地AS内的路由 |
| .* | 允许.匹配0次或多次(匹配所有) |
| ^100$ | 只匹配为100的AS_PATH |
| _100$ | 匹配以100结束的AS_PATH |
| ^10[012349]$ | 匹配为100~104、109的AS_PATH |
| ^10[^0-6]$ | 匹配除了为100~106的AS_PATH |
| ^10. | 匹配100~109,10 (这里有空格) |
| ^(100|200)$ | 匹配为100或200的AS_PATH |
| 12(_34)?_56 | 匹配12 56、12 34 56 |
注意as-path access-list也是默认隐含拒绝所有
示例1搭配filter-list
- //R2
- L0:172.16.1.1
- L1:172.16.11.1 //用route-map为该路由增加as-path为600的as号
- //在R3上过滤as号为600的路由更新,相关代码如下:
- ip as-path access-list 1 deny _600$
- ip as-path access-list 1 permit .*
- router bgp 300
- neighbor 10.1.23.2 filter-list 1 in
示例2搭配route-map
还是上面那张图,要求:将172.16.11.0/24这条路由限制在AS300
- R3上相关代码如下:
- ip as-path access-list 1 permit _600$
- route-map 1 permit 10
- match as-path 1
- set community local-AS
- route-map 1 permit 20
- router bgp 300
- neighbor 10.1.23.2 route-map 1 in
- //
- R3#sho ip bgp 172.16.11.0
- BGP routing table entry for 172.16.11.0/24, version 12
- Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised outside local AS)
- Flag: 0x820
- Not advertised to any peer
- 200 600
- 10.1.23.2 from 10.1.23.2 (172.16.11.1)
- Origin IGP, metric 0, localpref 100, valid, external, best
- Community: local-AS <<<<<---------
Router# show ip bgp regexp xx
显示BGP表中所有被该正则表达式匹配上的路由,这是一个非常不错的工具
为路由前缀分配Community

- R1
- neighbor 10.1.12.2 send-community
- neighbor 10.1.12.2 route-map 1 out
- route-map 1 permit 10
- match ip address prefix-list 1
- set community 6553611
- ip prefix-list 1 seq 5 permit 11.11.11.0/24
为路由前缀分配多个Community
还是上面那张图,在R2上给11.11.11.0/24这条路由添加no-export属性
- //R2
- ip community-list 11 permit 100:11
- neighbor 10.1.23.3 route-map 1 out
- route-map 1 permit 10
- match community 11
- set community no-export additive
用community-list匹配团体属性
lp community-list 1 permit 100:11
匹配。匹配community中包含100:11的路由
lp community-list 1 permit 100:11 no-adv
不匹配。要求100:11及no-adv两者都有才匹配成立
lp community-list 1 permit 100:11
lp community-list 1 permit no-export( 或将no-export换成no-adv )
匹配。只要community中包含100:11或no-export
ip community-list 12 permit internet
默认所有路由都属于internet
lp community-list 11 permit no-export
route-map test permit 10
match community 11 exact-match //严格匹配
严格匹配community属性为no-export的路由,多一点,少一点都不行
删除某个或多个community值
ip community-list standard del permit no-export //匹配要删除的commu值
route-map test permit 10
set comm-list del delete //用这条命令删除//删除多个就写多行,一行写多个值不生效
配置community-list
lp community-list 1-99 permit|deny value [value...]
定义标准的community-list,使用internet关键字匹配任何community
lp community-list 100-199 permit|deny regexp
定义扩展的community-list,可使用正则表达式匹配community
show ip community-list
查看配置的community-list
show ip bgp x.X.X.X
查看BGP路由的详细信息,包括community

R2上,过滤掉172.16.2.0/24路由,其他放行

- R2(config)#ip prefix-list 1 deny 172.16.2.0/24
- R2(config)#ip prefix-list 1 permit 0.0.0.0/0 le 32
- R2(config)#router bgp 200
- R2(config-router)#neighbor 10.1.23.3 prefix-list 1 out
示例1
R2上,过滤掉172.16.2.0/24路由,其他放行

- R2(config)#access-list 1 deny 172.16.2.0
- R2(config)#access-list 1 permit any
- R2(config)#router bgp 200
- R2(config-router)#neighbor 10.1.23.3 distribute-list 1 out //对指定领居生效
示例2
R2上,过滤掉172.16.2.0/24路由,其他放行
还是上图
- R2(config)#ip prefix-list 1 deny 172.16.2.0/24
- R2(config)#ip prefix-list 1 permit 0.0.0.0/0 le 32
- R2(config)#router bgp 200
- R2(config-router)#distribute-list prefix 1 out //对所有领居生效
小结:过滤路由可以对特定领居也可以所有领居


这里的无效指的是命令无效。
redistribute ospf 1
默认只重发布Intra-Area(区域内)及Inter-Area(区域间)路由match external 只重发布E1及E2
match external 1 只重发布E1match external 2 只重发布E2
match nssa-external 只重发布NSSA外部路由














实验:
- neighbor 10.1.23.3 advertise-map 1 exist-map 2
- R3:
- Network Next Hop Metric LocPrf Weight Path
- *> 11.11.11.0/24 10.1.23.2 0 200 100 i
- *> 22.22.22.0/24 10.1.23.2 0 200 100 i
- 只关掉22路由接口
- R3上啥也没有
- 只关11路由接口
- R3:
- Network Next Hop Metric LocPrf Weight Path
- *> 22.22.22.0/24 10.1.23.2 0 200 100 i
- ------------------------------------------------------------------------
- neighbor 10.1.23.3 advertise-map 1 non-exist-map 2
- R3:
- Network Next Hop Metric LocPrf Weight Path
- *> 22.22.22.0/24 10.1.23.2 0 200 100 i
- 只关掉22路由接口
- Network Next Hop Metric LocPrf Weight Path
- *> 11.11.11.0/24 10.1.23.2 0 200 100 i
- 只关11路由接口
- Network Next Hop Metric LocPrf Weight Path
- *> 22.22.22.0/24 10.1.23.2 0 200 100 i
小结
| exist-map匹配的路由 | 存在,就传递(不管有没有没被exist-map匹配的路由) 不存在,啥也不传 |
| non-exist-map匹配的路由 | 存在,就只发自己匹配的路由 不存在,就发前面advertise-map匹配的路由 |










实验结果
- //R2上看到
- Network Next Hop Metric LocPrf Weight Path
- *> 172.16.0.0 10.1.12.1 0 0 100 i
- *> 172.16.1.0/24 10.1.12.1 0 ? <<<<<<<<----------
- R2#sho ip bgp 172.16.1.0
- BGP routing table entry for 172.16.1.0/24, version 3
- Paths: (1 available, best #1, table Default-IP-Routing-Table)
- Flag: 0x820
- Advertised to update-groups:
- 1
- Local, (aggregated by 100 172.16.2.1), (injected path from 172.16.0.0/16) <<<<<<------
- 10.1.12.1 from 10.1.12.1 (172.16.2.1)
- Origin incomplete, localpref 100, valid, external, best
- //可以看到是注入进来的
代码
- R1:
- !
- interface Loopback0
- ip address 172.16.1.1 255.255.255.0
- !
- interface Loopback1
- ip address 172.16.2.1 255.255.255.0
- !
- interface Serial1/0
- ip address 10.1.12.1 255.255.255.0
- serial restart-delay 0
- !
- router bgp 100
- no synchronization
- bgp log-neighbor-changes
- network 172.16.1.0 mask 255.255.255.0
- network 172.16.2.0 mask 255.255.255.0
- aggregate-address 172.16.0.0 255.255.0.0 as-set summary-only
- neighbor 10.1.12.2 remote-as 200
- no auto-summary
- !
-
- R2:
- !
- interface Serial1/0
- ip address 10.1.12.2 255.255.255.0
- serial restart-delay 0
- !
- interface Serial1/1
- ip address 10.1.23.2 255.255.255.0
- serial restart-delay 0
- !
- router bgp 200
- no synchronization
- bgp log-neighbor-changes
- bgp inject-map 2 exist-map 1
- neighbor 10.1.12.1 remote-as 100
- neighbor 10.1.23.3 remote-as 300
- no auto-summary
- !
- ip prefix-list 1 seq 5 permit 172.16.0.0/16
- !
- ip prefix-list 2 seq 15 permit 10.1.12.1/32
- !
- ip prefix-list 3 seq 5 permit 172.16.1.0/24
- !
- route-map 1 permit 10
- match ip address prefix-list 1
- match ip route-source prefix-list 2
- !
- route-map 2 permit 10
- set ip address prefix-list 3
- !
-
- R3:
- !
- interface Serial1/1
- ip address 10.1.23.3 255.255.255.0
- serial restart-delay 0
- !
- router bgp 300
- no synchronization
- bgp log-neighbor-changes
- neighbor 10.1.23.2 remote-as 200
- no auto-summary
- !





规则示例


小结:
AS内,client发出,给client和非client;非client发出,只给client,不给非client
RR从EBGP邻居收到,发给所有领居
Originator_ID、Cluster_list
Originator_ID

Originator_ID的值









相关代码
- neighbor 10.1.34.3 route-reflector-client
- bgp cluster-id 33.33.33.33


next-hop属性在成员AS间传递不变





- R1:
- router bgp 100
- network 1.1.1.0 mask 255.255.255.0
- network 2.2.2.0 mask 255.255.255.0
- neighbor 10.1.13.3 remote-as 300 //这里的AS是联邦AS
-
- R2:
- router bgp 200
- neighbor 10.1.25.5 remote-as 300
-
- R3:
- router ospf 1
- network 3.3.3.3 0.0.0.0 area 0
- network 10.1.34.3 0.0.0.0 area 0
- router bgp 64512 //AS号为成员AS号
- bgp confederation identifier 300 //联邦AS标识
- neighbor 4.4.4.4 remote-as 64512
- neighbor 4.4.4.4 update-source Loopback0
- neighbor 4.4.4.4 next-hop-self //L0口建领居,要注意ttl(默认为1)
- neighbor 10.1.13.1 remote-as 100
-
- R4:
- router ospf 1
- network 4.4.4.4 0.0.0.0 area 0
- network 10.1.34.4 0.0.0.0 area 0
- network 10.1.45.4 0.0.0.0 area 0
- router bgp 64512
- bgp confederation identifier 300
- bgp confederation peers 64513 //指AS号(在成员AS里的EBGP路由器,指另一个成员AS的EBGP路由器)
- neighbor 3.3.3.3 remote-as 64512 //联邦AS内,成员AS指成员AS
- neighbor 3.3.3.3 update-source Loopback0
- neighbor 5.5.5.5 remote-as 64513
- neighbor 5.5.5.5 ebgp-multihop 3
- neighbor 5.5.5.5 update-source Loopback0
-
- R5:
- router ospf 1
- network 5.5.5.5 0.0.0.0 area 0
- network 10.1.45.5 0.0.0.0 area 0
- router bgp 64513
- bgp confederation identifier 300
- bgp confederation peers 64512
- neighbor 4.4.4.4 remote-as 64512
- neighbor 4.4.4.4 ebgp-multihop 3
- neighbor 4.4.4.4 update-source Loopback0
- neighbor 10.1.25.2 remote-as 200












































- R4的配置如下:
- router bgp 400
- bgp router-id 4.4.4.4
- bgp dmzlink-bw
- network 44.44.44.0 mask 255.255.255.0
- neighbor 10.1.24.2 remote-as 123
- neighbor 10.1.24.2 dmzlink-bw
- neighbor 10.1.34.3 remote-as 123
- neighbor 10.1.34.3 dmzlink-bw
- maximum-paths 2
-
- R4的BGP表项:
- R4#sho ip bgp 11.11.11.0
- BGP routing table entry for 11.11.11.0/24, version 2
- Paths: (2 available, best #1, table Default-IP-Routing-Table)
- Multipath: eBGP
- Advertised to update-groups:
- 1
- 123
- 10.1.24.2 from 10.1.24.2 (2.2.2.2)
- Origin IGP, localpref 100, valid, external, multipath, best
- DMZ-Link Bw 1250 kbytes <<<<<<<<<
- 123
- 10.1.34.3 from 10.1.34.3 (3.3.3.3)
- Origin IGP, localpref 100, valid, external, multipath
- DMZ-Link Bw 193 kbytes <<<<<<<<<
-
- R4的路由表:
- R4#sho ip ro 11.11.11.0
- Routing entry for 11.11.11.0/24
- Known via "bgp 400", distance 20, metric 0
- Tag 123, type external
- Last update from 10.1.34.3 00:13:54 ago
- Routing Descriptor Blocks:
- 10.1.34.3, from 10.1.34.3, 00:13:54 ago
- Route metric is 0, traffic share count is 37 <<<<<<<<<
- AS Hops 1
- Route tag 123
- * 10.1.24.2, from 10.1.24.2, 00:13:54 ago
- Route metric is 0, traffic share count is 240 <<<<<<<<<
- AS Hops 1
- Route tag 123

- R1的配置如下:
- router bgp 123
- bgp router-id 1.1.1.1
- bgp dmzlink-bw <<<<<<<<<<<开启(使用DMZ链路带宽作为BGP多路径的权重)
- network 11.11.11.0 mask 255.255.255.0
- neighbor 2.2.2.2 remote-as 123
- neighbor 2.2.2.2 update-source Loopback0
- neighbor 3.3.3.3 remote-as 123
- neighbor 3.3.3.3 update-source Loopback0
- maximum-paths ibgp 2
-
- R2的配置如下:
- router bgp 123
- bgp router-id 2.2.2.2
- bgp dmzlink-bw <<<<<<<<<<<开启(使用DMZ链路带宽作为BGP多路径的权重)
- neighbor 1.1.1.1 remote-as 123
- neighbor 1.1.1.1 update-source Loopback0
- neighbor 1.1.1.1 next-hop-self
- neighbor 1.1.1.1 send-community extended <<<<<<<<<<<发送community属性的extended
- neighbor 10.1.24.4 remote-as 400
- neighbor 10.1.24.4 dmzlink-bw <<<<<<<<<<<只能对EBGP领居使用
-
- R3的配置如下:
- router bgp 123
- bgp router-id 3.3.3.3
- bgp dmzlink-bw <<<<<<<<<<<开启(使用DMZ链路带宽作为BGP多路径的权重)
- neighbor 1.1.1.1 remote-as 123
- neighbor 1.1.1.1 update-source Loopback0
- neighbor 1.1.1.1 next-hop-self
- neighbor 1.1.1.1 send-community extended <<<<<<<<<<<发送community属性的extended
- neighbor 10.1.34.4 remote-as 400
- neighbor 10.1.34.4 dmzlink-bw <<<<<<<<<<<只能对EBGP领居使用
-
- R1的BGP表项:
- R1#sho ip bgp 44.44.44.0
- BGP routing table entry for 44.44.44.0/24, version 6
- Paths: (2 available, best #2, table Default-IP-Routing-Table)
- Multipath: iBGP
- Not advertised to any peer
- 400
- 3.3.3.3 (metric 11) from 3.3.3.3 (3.3.3.3)
- Origin IGP, metric 0, localpref 100, valid, internal, multipath
- DMZ-Link Bw 193 kbytes <<<<<<<<<<<
- 400
- 2.2.2.2 (metric 11) from 2.2.2.2 (2.2.2.2)
- Origin IGP, metric 0, localpref 100, valid, internal, multipath, best
- DMZ-Link Bw 1250 kbytes <<<<<<<<<<<
-
- R1的路由表:
- R1#sho ip ro 44.44.44.0
- Routing entry for 44.44.44.0/24
- Known via "bgp 123", distance 200, metric 0
- Tag 400, type internal
- Last update from 2.2.2.2 00:13:27 ago
- Routing Descriptor Blocks:
- 3.3.3.3, from 3.3.3.3, 00:13:27 ago
- Route metric is 0, traffic share count is 37 <<<<<<<<<<<
- AS Hops 1
- Route tag 400
- * 2.2.2.2, from 2.2.2.2, 00:13:27 ago
- Route metric is 0, traffic share count is 240 <<<<<<<<<<<
- AS Hops 1
- Route tag 400
注:验证的时候,ip load-sharing per-packet这条命令要打上(接口上打)





Cost Community的限制




- R1:
- router bgp 123
- no synchronization
- bgp log-neighbor-changes
- network 1.1.1.0 mask 255.255.255.0
- neighbor 10.1.12.2 remote-as 123
- no auto-summary
-
- R2:
- router bgp 123
- no synchronization
- bgp log-neighbor-changes
- neighbor 10.1.12.1 remote-as 123
- neighbor 10.1.23.3 remote-as 123
- no auto-summary
-
- R3:
- router bgp 123
- no synchronization
- bgp log-neighbor-changes
- network 1.1.1.0 mask 255.255.255.0
- neighbor 10.1.23.2 remote-as 123
- no auto-summary
- R2BGP表
- Network Next Hop Metric LocPrf Weight Path
- * i1.1.1.0/24 10.1.23.3 0 100 0 i
- *>i 10.1.12.1 0 100 0 i
- //现在用cost community实现优选从10.1.23.3来的
- router bgp 123
- neighbor 10.1.12.1 route-map 1 in
- neighbor 10.1.23.3 route-map 2 in
- route-map 1 permit 10
- set extcommunity cost igp 1 20
- route-map 2 permit 10
- set extcommunity cost igp 1 10
- --------------------------------------------------------
- Network Next Hop Metric LocPrf Weight Path
- *>i1.1.1.0/24 10.1.23.3 0 100 0 i
- * i 10.1.12.1 0 100 0 i
- R2#sho ip bgp 1.1.1.0
- BGP routing table entry for 1.1.1.0/24, version 4
- Paths: (2 available, best #1, table Default-IP-Routing-Table)
- Not advertised to any peer
- Local
- 10.1.23.3 from 10.1.23.3 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, internal, best
- Extended Community: Cost:igp:1:10
- Local
- 10.1.12.1 from 10.1.12.1 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, internal
- Extended Community: Cost:igp:1:20

- R2:
- router bgp 123
- neighbor 10.1.12.1 route-map 1 in
- route-map 1 permit 10
- set extcommunity cost igp 1 2147483647
- --------------------------------------------------------------------
- Network Next Hop Metric LocPrf Weight Path
- *>i1.1.1.0/24 10.1.12.1 0 100 0 i
- * i 10.1.23.3 0 100 0 i
- --------------------------------------------------------------------
- 1.0.0.0/24 is subnetted, 1 subnets
- B 1.1.1.0 [200/0] via 10.1.12.1, 00:01:52
- //这里是routerid最小的生效
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- R2(config-router)#maximum-paths ibgp 2
- 1.0.0.0/24 is subnetted, 1 subnets
- B 1.1.1.0 [200/0] via 10.1.23.3, 00:00:13
- [200/0] via 10.1.12.1, 00:01:26
- //可以看到负载均衡,此时说明poi没生效

- R2:
- router bgp 123
- neighbor 10.1.12.1 route-map 1 in
- neighbor 10.1.23.3 route-map 2 in
- route-map 1 permit 10
- set extcommunity cost igp 1 2147483648
- route-map 2 permit 10
- set extcommunity cost igp 2 10
-
- Network Next Hop Metric LocPrf Weight Path
- * i1.1.1.0/24 10.1.12.1 0 100 0 i
- *>i 10.1.23.3 0 100 0 i

- R1:
- router bgp 123
- neighbor 10.1.12.2 send-community extended
- neighbor 10.1.12.2 route-map 1 out
- route-map 1 permit 10
- set extcommunity cost pre-bestpath 1 20
-
- R3:
- router bgp 123
- neighbor 10.1.23.2 send-community extended
- neighbor 10.1.23.2 route-map 1 out
- route-map 1 permit 10
- set extcommunity cost pre-bestpath 1 10
-
- R2:
- Network Next Hop Metric LocPrf Weight Path
- *>i1.1.1.0/24 10.1.23.3 0 100 0 i
- * i 10.1.12.1 0 100 0 i
-
- R2#sho ip bg 1.1.1.0
- BGP routing table entry for 1.1.1.0/24, version 2
- Paths: (2 available, best #1, table Default-IP-Routing-Table)
- Flag: 0x820
- Not advertised to any peer
- Local
- 10.1.23.3 from 10.1.23.3 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, internal, best
- Extended Community: Cost:pre-bestpath:1:10
- Local
- 10.1.12.1 from 10.1.12.1 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, internal
- Extended Community: Cost:pre-bestpath:1:20

- R1:
- router bgp 64551
- bgp confederation identifier 123
- bgp confederation peers 64552
- network 1.1.1.0 mask 255.255.255.0
- neighbor 10.1.12.2 remote-as 64552
- neighbor 10.1.12.2 send-community extended
- neighbor 10.1.12.2 route-map 1 out
- route-map 1 permit 10
- set extcommunity cost pre-bestpath 1 20
-
- R2:
- router bgp 64552
- no synchronization
- bgp log-neighbor-changes
- bgp confederation identifier 123
- bgp confederation peers 64551 64553
- neighbor 10.1.12.1 remote-as 64551
- neighbor 10.1.23.3 remote-as 64553
-
- R3:
- router bgp 64553
- bgp confederation identifier 123
- bgp confederation peers 64552
- network 1.1.1.0 mask 255.255.255.0
- neighbor 10.1.23.2 remote-as 64552
- neighbor 10.1.23.2 send-community extended
- neighbor 10.1.23.2 route-map 1 out
- route-map 1 permit 10
- set extcommunity cost pre-bestpath 1 10
- R2:
- Network Next Hop Metric LocPrf Weight Path
- * 1.1.1.0/24 10.1.12.1 0 100 0 (64551) i
- *> 10.1.23.3 0 100 0 (64553) i
-
- R2#sho ip bg 1.1.1.0
- BGP routing table entry for 1.1.1.0/24, version 4
- Paths: (2 available, best #2, table Default-IP-Routing-Table)
- Flag: 0x820
- Advertised to update-groups:
- 1
- (64551)
- 10.1.12.1 from 10.1.12.1 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, confed-external
- Extended Community: Cost:pre-bestpath:1:20
- (64553)
- 10.1.23.3 from 10.1.23.3 (1.1.1.1)
- Origin IGP, metric 0, localpref 100, valid, confed-external, best
- Extended Community: Cost:pre-bestpath:1:10
-
- //这里取消pre-bestpath用负载均衡,负载均衡没有效果。





















