BGP--笔记04
应用场景:
1)-在
路由重分发时
2)-
BGP进行路由策略配置时
3)-进行策略路由时
--------------------------------
在BGP中如何应用Route-Map进行选路?
1,BGP路由策略
1)【Local Preference】
特点:
a)只会在【iBGP间】传播
b)缺省值为100,优先级越大越好!!!
配置1:
**
更改本路由器缺省的Local Preference参数-
Router(config-router)#bgp default local-preference 优先级
作用:
修改本路由器从任何iBGP学到的【所有的BGP路由】,我们都将Local Preference更改为相关参数
配置2: route-map 针对【部分路由】进行更改,将
标准ACL:
access-list 1 permit 172.16.1.0 0.0.0.255 (
标准ACL
只控制网络号,不控制掩码)
access-list 1 permit 172.16.2.0 0.0.0.255
扩展ACL:
access-list 100 permit 172.16.1.0 0.0.0.0 255.255.255.0 0.0.0.0
[---网络号-------] [------掩码---------]
route-map
policy_localpref permit
10
matchip address 1
set local-preference 120
route-map
policy_localpref permit
20
route-map bgp ***
neighbor x.x.x.x route-map policy_localpref
in
[in]:学习路由时in,修改入口策略,达到控制本AS
离开的流量的目的
问题:若 对方AS 中存在172.16.1.0/24路由以及其子网路由,如何将这些路由的LocalPref更改?
并且只接受子网掩码小于等于/28的路由!!
答:*
IP前缀列表 【匹配路由】
ip prefix-list my_prefix seq 5 permit 172.16.1.0/24 ge 25 le 28
哪些路由匹配该规则?
i.路由的前/24比特必须和172.16.1.0完全匹配
ii.路由的掩码长度必须小于等于28 (若末指明le,则 <=32)
iii.路由的掩码长度必须大于等于25(若末指明ge,则 >=第一部分参数中的掩码)
iv.若le,ge均末指定,则路由的掩码长度必须为第一部分参数中的掩码
需要匹配【
所有的主机】路由---
ip prefix-list my_prefix seq 5 permit
ge
需要匹配 【
缺省】 路由---
ip prefix-list my_prefix seq 5 permit
0.0.0.0/0
需要匹配【
所有】路由---
ip prefix-list my_prefix seq 5 permit
0.0.0.0/0 le 32
ip prefix-list my_prefix seq 5 permit 172.16.1.0/24 le 28
ip prefix-list my_prefix seq 5 permit 172.16.1.0/24 le 28
2) MED控制【进入】本AS的流量 特点:传播给【eBGP邻居】,并在
eBGP所属的AS内传播(eBGP所属的AS不能将该MED属性传播到其他AS中)
Cisco路由器上缺省MED为0
MED值越小,路由越优先
配置1:
router(config-router)#default-metric [metric值]
补充内容
如何
解决在Transit AS中的iBGP全互联问题?(因为水平分割原则,若没全互联)
(1)【路由反射器(Route-Reflector)】
基本思路:改变iBGP之间通告路由时水平分割原则,
减少iBGP全互连的个数,iBGP邻居个数n*(n-1)/2减少为n-1
RR配置
命令:
只需要在RR上配置即可(指定哪些路由器是RRC)
router(config)#router bgp xxx
router(config-router)#
bgp cluster-id x.x.x.x (指定该RR的cluster-id)若一个Cluster中
存在多个RR,则必须配置相同的cluster-id
router(config-router)#neighbor x.x.x.x
route-reflector-client
【RR
工作方式】
1)Client转发更新给它的对等体(RR)
2)RR接收到来自Client的路由更新后,将这些路由更新
转发给其他client以及nonclient(包括iBGP和eBGP对等体)
RRC--->RR--->RRC/non-RRC
--->
iBGP/eBGP
3)若RR接收到多条路径,则RR负责
挑选最优的路径
4)若nonclient转发更新给它的对等体(恰好是RR),RR接收到来自nonclient的更新后,
仅将此更新
转发给其client
non-RRC----->Peer(是另一个cluster的RR)---->
仅RRC
5)若eBGP对等体发送更新给RR,RR将此更新反射给所有的client和nonclient
eBGP----->RR------>RRC/non-RRC
[注]
route reflector: RR
client: RRC
nonclient:
cluster: RR+RRC=Cluster(集群)
RRC---->RR---->其他RRC
---->nonclient
成为另一个RR------>RRC
------>RRC
【一个RR从一个
非客户端收到一个更新之后
只可以 发给其他客户端】
----------------------
图示:
【BB1】 【BB2】
| |
eBGP| |eBGP
| |
11.11.11.11【P1R1】RRC RRC【P1R2】22.22.22.22
| |
iBGP| AS200 |iBGP
| |
33.33.33.33【P1R3】--------------【P1R4】44.44.44.44
RR iBGP
RR
Cluster-Id:200.200.200.200
*若一个cluster内有2个RR,有可能产生"环"
因此在同一个cluster内部,
2个RR都应配置Cluster-ID且cluster-id相同
缺省情况下,cluster-id = router-id,而这二个肯定是不同的
当RR转发更新时,Originator-ID被
设置(为产生该路径的路由器的RouterID),用来确保不会形成环路
若一个Cluster中存在多个RR作为冗余,源路由器能过Cluster-ID属性来标识,同样用来确保无路由环路
eg.
P1R1/P1R2上配置2个RR neighbor 33.33.33.33
neighbor 44.44.44.44
P1R3:
router bgp 200
no synchr
no auto-summry
neighbor 11.11.11.11 remote-as 200
neighgor 11.11.11.11 update-source loopback1
neighgor 11.11.11.11 route-reflector-client
neighbor 22.22.22.22 remote-as 200
neighgor 22.22.22.22 update-source loopback1
neighgor 22.22.22.22 route-reflector-client
neighbor 44.44.44.44 remote-as 200
neighgor 44.44.44.44 update-source loopback1
bgp cluster-id 200.200.200.200
%Neighbor configured as RR-client.Deconfigure first
若先配置了客户端,不允许配置cluster-id
因此先配置完 bgp cluster-id 后再配置route-reflector-client
因些
最终配置:
P1R3:
router bgp 200
no synchr
no auto-summry
bgp cluster-id 200.200.200.200
neighbor 11.11.11.11 remote-as 200
neighgor 11.11.11.11 update-source loopback1
neighgor 11.11.11.11 route-reflector-client
neighbor 22.22.22.22 remote-as 200
neighgor 22.22.22.22 update-source loopback1
neighgor 22.22.22.22 route-reflector-client
neighbor 44.44.44.44 remote-as 200
neighgor 44.44.44.44 update-source loopback1
P1R4:
router bgp 200
no synchr
no auto-summry
bgp cluster-id 200.200.200.200
neighbor 11.11.11.11 remote-as 200
neighgor 11.11.11.11 update-source loopback1
neighgor 11.11.11.11 route-reflector-client
neighbor 22.22.22.22 remote-as 200
neighgor 22.22.22.22 update-source loopback1
neighgor 22.22.22.22 route-reflector-client
neighbor 33.33.33.33 remote-as 200
neighgor 33.33.33.33 update-source loopback1
2个RR反射路由,但是起源Originator是不变化的,即某个路由器的Router-ID
若有多条路由,也选择最优的一条路由
****若Cluster-id相同,不反射路由,只会接收路由!
eg. P1R3上:
44.44.44.44 RR in same cluster,Reflected update dropped
------------------------
路由反射器RR 配置:
只需要在RR在配置,RRC上没任何改变
eg.
RR(P1R3)上
router bgp 200
【no synchr】
【no auto-summry】
neighbor 11.11.11.11 remote-as 200
neighbor 11.11.11.11 【route-reflecotr-client】
RRC(P1R1)上
只配置neighbor到RR上
router bgp 200
no syn
no auto
neighbor 33.33.33.33 remote-as 200
neighbor 33.33.33.33 update-source loopback 1
标配RR:
router bgp xxx
no auto
no syn
bgp-routerid x.x.x.x
show ip bgp x.x.x.x 查看路由具体信息
看情况进行no syn关闭同步,no auto关闭汇总,指定routerid
图示:
【BB1】 【BB2】
| |
eBGP| |eBGP
| |
11.11.11.11【P1R1】 【P1R2】22.22.22.22
| |
iBGP| AS200 |iBGP
| |
33.33.33.33【P1R3】--------【P1R4】44.44.44.44
iBGP
配置RR之前:
#P1R3#:
Network Next Hop Metric LocPrf Weight Path
*>i 100.1.1.0/24 11.11.11.11 0 100 0 100 i
查看:
show ip bgp 100.1.1.0
BGP routing table entry for 100.1.1.0/24,version 2
Path1 available,best #1,table Default-IP-Routing-Table)
Not advertised to any peer
(因为和其它路由器是iBGP邻居关系,水平分割原则)
图示:
【BB1】 【BB2】
| |
eBGP| |eBGP
| |
11.11.11.11【P1R1】
RRC 【P1R2】22.22.22.22
RRC
| |
iBGP| AS200 |iBGP
| |
33.33.33.33【P1R3】----------【P1R4】44.44.44.44
RR iBGP
RRC
配置RR之后:
#P1R3#:
router bgp 200
neighbor 11.11.11.11 route-reflector-client
neighbor 22.22.22.22 route-reflector-client
neighbor 33.33.33.33 route-reflector-client
配置RR后指定RRC后邻居关系会复位
neighbor 11.11.11.11 Down RR client config change
neighbor 22.22.22.22 Down RR client config change
neighbor 33.33.33.33 Down RR client config change
show ip bgp summary
#P1R1#:
查看show ip bgp
Network Next Hop Metric LocPrf Weight Path
*>i 100.1.1.0/24 172.16.1.2(
eBGP) 0 100 0 100 i
通过eBGP邻居学习到的网段100.1.1.0/24
show ip bgp 100.1.1.0
BGP routing table entry for 100.1.1.0/24,version 3
Path1 available,best #1,table Default-IP-Routing-Table)
Advertised to non peer-group peers:
33.33.33.33
通过eBGP学到的100.1.1.0的路由发给P1R3
#P1R3#:
show ip bgp 100.1.1.0
BGP routing table entry for 100.1.1.0/24,version 3
Path1 available,best #1,table Default-IP-Routing-Table)
Advertised to non peer-group peers:
22.22.22.22 44.44.44.44
100,(Received from a RR-Client)
因为以上IP是我RR的客户端RRC,由RRC收到的,反射给我的其它客户端RRC
---
【若
P1R4不是RRC,P1R3和P1R4是普通的iBGP邻居】
图示:
【BB1】 【BB2】
| |
eBGP| |eBGP
| |
11.11.11.11【P1R1】
RRC 【P1R2】22.22.22.22
RRC
| |
iBGP| AS200 |iBGP
| |
33.33.33.33【P1R3】----------【P1R4】44.44.44.44
RR
iBGP
nonRRC
#P1R3:
show ip bgp 100.1.1.0
BGP routing table entry for 100.1.1.0/24,version 3
Path1 available,best #1,table Default-IP-Routing-Table)
Advertised to non peer-group peers:
22.22.22.22
44.44.44.44 100,(Received from a RR-Client)
【原则: 从一个
客户端收到的BGP路由,可以反射给
其它客户端,同时还可以
发给我的iBGP邻居!】
--------------------------------------------------------------------------------------------------------------
(2)【联邦(Confederation)】 基本思路:减少iBGP全互连问题,
将
iBGP邻居“变为”eBGP邻居,将一个大的AS划分成若干个小的AS,小AS之间原先为iBGP邻居,现在变为eBGP邻居,
从而改变原先的iBGP邻居为eBGP邻居。划分小的AS,使用私有的AS号(64512-65535),私有AS号不会传播到其它AS中
在小的AS中保证iBGP全互连,在小的AS当中,结合RR,私有的AS之间为eBGP,eBGP之间没有水平分割原则
n(n-1)/2-----RR--->n-1----------->
RR地位很重要,若RR Down,造成很大影响
配置命令:
router(config)#router bgp 联邦内部的
AS号
router(config-router)#bgp confederation
identifier
AS
联邦的标识-(即原有
大的AS)
router(config-router)#bgp confedeartion
peers
联邦内部的AS列表(
只需要配置本联邦内部和本AS建立邻居关系的AS即可)
图示:
100.1.1.1/24 200.1.1.1/24
AS100 AS300
【BB2】 【BB1】
| |
eBGP| |eBGP
| |
11.11.11.11【P1R1】 【P1R2】22.22.22.22
| |
小AS-65001 iBGP| 大
AS200 |iBGP
小AS-65002
| |
33.33.33.33 【P1R3】----------【P1R4】44.44.44.44
iBGP
P1R1,P1R3一个联邦(小AS-65001);
P1R2,P1R4一个联邦(小AS-65002);
P1R1:
router bgp
65001
no auto
no syn
bgp confederation identifier
200 *bgp confederation
peers 65002(本例中P1R1指定peer无实际
功能)
neighbor 172.16.1.2(BB2) remote-as 100
neighbor 33.33.33.33 remote-as 65001
neighbor 33.33.33.33 update-source loopback 1
neighbor 33.33.33.33 next-hop-self
P1R3:
router bgp
65001
no auto
no syn
bgp confederation identifier
200
bgp confederation peers
65002
neighbor 11.11.11.11 remote-as 65001
neighbor 11.11.11.11 update-source loopback 1
neighbor 44.44.44.44 remote-as 65002
neighbor 44.44.44.44 update-source loopback 1
neighbor 44.44.44.44
ebgp-multihop 2 (和P1R4是eBGP邻居,且用loopback作update-source,所以要指定多跳)
通过查看P1R3:
show ip bgp summary
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
44.44.44.44 4 65002 0 0 0 0 0 Never
Idle(因为是eBGP邻居)末配置多跳
P1R2:
router bgp 65002
bgp confederation identifier 200
没配peer 也不用配置peer
neighbor 172.16.2.2(BB1) remote-as 300
neighbor 44.44.44.44 remote-as 65002
neighbor 44.44.44.44 update-source loopback 1
neighbor 44.44.44.44 next-hop-self
P1R4:
router bgp
65002 bgp confederation identifier
200
必须配置peer
bgp confederation peers
65001
neighbor 22.22.22.22 remote-as 65002
neighbor 22.22.22.22 update-source loopback 1
neighbor 33.33.33.33 remote-as 65001
neighbor 33.33.33.33 update-source loopback 1
neighbor 33.33.33.33
ebgp-multihop 2 (和P1R3是eBGP邻居,且用loopback作update-source,所以要指定多跳)
通过show ip bgp summary查询
P1R4:
show ip bgp
Network Next Hop Metric LocPrf Weight Path
*>100.1.1.0/24
11.11.11.11 0 100 0 (65001) 100 i
下一跳不变 65001在AS-Path计算时不算在内
P1R2:
show ip bgp
Network Next Hop Metric LocPrf Weight Path
* i100.1.1.0/24 11.11.11.11 0 100 0 (65001) 100 i
末标明最优路由
查明原因:
show ip bgp 100.1.1.0
11.11.11.11(metric 67) from 44.44.44.44(44.44.44.44)
,
not synchronized 因为同步没关闭
P1R2:
router bgp 65002
no synchronization
P1R4:
router bgp 65002
no synchronization
P1R1:
router bgp 65001
no synchronization
P1R3:
router bgp 65001
no synchronization
联邦内部的AS号(无论私有AS还是公有AS)
只会在联邦内部传递时才会出现,一旦传到联邦外AS外部,都会消失!
Peer:
若没指定P1R4 的peer 到 P1R3
P1R4显示信息:
%BGP-6-ASPATH:
Invalid AS path(65001)100 received from 33.33.33.33:
Non confederation peer
因为在联邦里面,我们的
AS-PATH有特殊属性,会
告知这个路径是联邦的内部路径,所以必须要指定一个Peer
在 有实际建立BGP邻居关系 (相邻的建立联邦内部邻居关系时) ,我们要互相指定Peer
即在 P1R3-------之间-------P1R4 互相指定peer
另例.
eBGP| |eBGP
| |
小
AS1【P1R1】 【P1R2】小
AS4
| |
| 大AS200 |
| |
小
AS2【P1R3】---------【P1R4】小
AS3
在P1R1上
指定P1R3 peer;
(小AS1) (小AS2)
在P1R3上
指定P1R4 peer;
(小AS2) (小AS3)
在P1R4上
指定P1R2 peer;
(小AS3) (小AS4)
其它路由器之间可以不用互相指定peer.
--------------------------------------------------------------------------------------------------------------
(3)【Community属性】团体属性------相当于是一个
路由的标签,方便作路由控制
公认的Community属性:
no-export: 拥有该属性的路由
不会被
发送到
其他AS(联邦中的AS算是同一个AS,即在联邦的内部AS间可以传播)中
no-advertise: 拥有该属性的路由
不会被
通告给
任何BGP邻居(包括iBGP,eBGP)
Local-AS: 拥有该属性的路由仅仅在
本AS中传播(
最小的AS中,只要是AS号不同,就不再传播出去)
图示:
111.1.1.1/24
100.1.1.1/24 200.1.1.1/24
AS100 AS300
【BBR2】 【BBR1】
172.16.1.2 |
| |
eBGP| |eBGP
| |
172.16.1.1 |
lo11.11.11.11 【P1R1】 【
P1R2】22.22.22.22
| |
| AS200 |iBGP
| |
33.33.33.33 【P1R3】----------【P1R4】44.44.44.44
iBGP
一,【No-export】:拥有该属性的路由不会被发送到其他AS(联邦中的AS算是同一个AS,即在联邦的内部AS间可以传播)中
P1R1:
route-map policy_comm permit 10
set community no-export
router bgp 65001
no syn
no auto
neighbor 172.16.1.2 route-map policy_comm
in
***Cisco设备上,缺省是不发团体值
P1R1:
P1R1(config-router)#neighbor 33.33.33.33
send-community 向邻居发布community
P1R3:
P1R3(config-router)#neighbor 44.44.44.44
send-community 向邻居发布community
P1R4:
P1R4(config-router)#neighbor 22.22.22.22
send-community
向邻居发布community
团体属性不通告给AS外部
P1R2:
show ip bgp 100.1.1.0
Not advertised to any peer
因此
BBR1 收不到
BBR2的100.1.1.0/24 和111.1.1.0/24网段
二,【No-advertise】:拥有该属性的路由不会被通告给任何BGP邻居(包括iBGP,eBGP)
BBR2:
router bgp 100
neighbor 172.16.1.1 route-map test out
route-map test permit 10
set community
no-advertise
结果:100.1.1.0/24和111.1.1.0/24网段
只传播给P1R1 ,
不传播到
P1R3及以后的路由器
三,【Local-AS】:拥有该属性的路由
仅仅在
本AS中传播(最小的AS中,只要是AS号不同,就不再传播出去)
BBR2:
router bgp 100
neighbor 172.16.1.1 route-map test
out
route-map test permit 10
set community
local-AS
或
P1R1:
router bgp 65001
neighbor 172.16.1.2 route-map test
in
route-map test permit 10
set community
local-AS
show ip bgp 100.1.1.0
Community:local-AS
P1R3:
show ip bgp 100.1.1.0
Not advdertised to any peer (即“
联邦中的 不同AS间 不能传播”)
Community:local-AS
四,【匹配团体值】:
P1R1: access-list 66 permit 111.1.1.0 0.0.0.255
route-map test permit 10
match ip address 66
set community ?
aa:nn community number in aa:nn format
aa=AS号,nn=标识
set community
200:999 route-map test permit 20
router bgp 65001
neighbor 172.16.1.2 route-map test in
clear ip bgp * soft in
show ip bgp 111.1.1.0
Community:13108199 (拥有一个团体值)
P1R4:show ip bgp 111.1.1.0
Community:13108199
1)配置community列表
ip community-list 1
2)Route-Map匹配
route-map test permit 10
match community
1 set metric 9999999
route-map test permit 20----添加一条空的route-map
3)应用到邻居上
router bgp 65002
neighbor 33.33.33.33 route-map test
in
之前
show ip bgp
Network Next Hop Metric
111.1.1.0/24 11.11.11.11
0
之后
clear ip bgp * soft in
show ip bgp
Network Next Hop Metric
111.1.1.0/24 11.11.11.11
9999999