前置
0x01:Prefix-list 操作 BGP 路由
> 操作完上面策略后,本身 R3 会学习到的 12.12.12.0/24 的 BGP 路由,会被前缀列表所匹配过滤
!! R3 show ip bgp 参考
BGP table version is 2, local router ID is 33.33.33.33
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 20.1.1.1 0 100 i
0x02:Distribute-list 操作路由
第一种:
第二种:
第三种 (参考即可):
0x03:Route-map 操作 BGP 路由
可以在以下的 BGP 命令中使用 route-map 关键字
-
neighbor
-
bgp dampening
-
network
-
redistribute
可以为特定的目的在不同的命令中调用定义号的 route-map
-
suppress-map
-
unsuppress-map
-
advertise-map
-
*inject-map
-
*exist-map
-
*non-exist-map
-
*table-map
match 语句能匹配如下等条件或属性
-
Access-list
-
ip prefix-list
-
local-preference
-
metric
-
Tag
-
AS-PATH
-
BGP community
-
IGP route-type (internal / external )
-
......
set 语句能设置
-
Origin
-
Weight
-
BGP community
-
Local preference
-
MED
-
....
配置示例:关联 network 执行策略 (改变路由匹配不同 community 值传递)
!! 查看 R2 获取到 network 的路由 community 属性参考
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 5
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Not advertised to any peer
100
10.1.1.1 from 10.1.1.1 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, external, best
`Community: 100:1`
R2#show ip b 2.2.2.0
BGP routing table entry for 2.2.2.0/24, version 6
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x880
Not advertised to any peer
100
10.1.1.1 from 10.1.1.1 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, external, best
`Community: 100:2`
!! 我们可以看到 二者的 community 属性不一致
!! 该效果通过 route-map 操作 community 值,关联 prefix-list 以及 network route-map test 实现
配置实例:关联 neighbor,针对特定邻居执行策略 🔺
!! 最终查看 R2 的 metric 值属性,这里我们通过 route-map 关联 Prefix-list 匹配路由
!! 使用 route-map 操作了 metric 值,操作关键字为 `neighbor`
R2#show ip bgp
BGP table version is 5, local router ID is 10.1.1.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 10.1.1.1 1000 0 100 i
*> 2.2.2.0/24 10.1.1.1 2000 0 100 i
配置实例:重发布关联 route-map
0x04:Route-map 的插件 policy-list
关于 policy-list 为什么我会把它叫做一个插件呢?
因为对我来说,一个浏览器上比如 chrome 存在的插件,其作用就是增强用户体验,增强浏览器可操作性的一种帮助工具
而在 route-map 中的 policy-list 也是如此,
我们可以将 policy-list 看作是一个只有 match 语句的 route-map
它能够将 match 条件打一个包,而不使用,每一个包就只需要我们在 route-map 中调用即可
route-map test permit 10
match policy 10
1:policy-list 简介
-
可预先将包含一组 match 语句的 route-map 定义成一个命令列表,这个列表称为 policy-list
-
这些 policy-list 可以在 route-map 中被调用
-
一个 policy-list 就像只包含 match 语句的 route-map
-
当 route-map 被执行,被其调用的 policy-list 中所包含的 match 语句将一并被遍历且执行 match 动作
-
这是一种子啊大中型网络中运用、使得配置 "模块化,可维护" 的特性
注意点:关于 policy-list 我们需要注意该特性只在 BGP 路由协议中支持现在可能已经支持了
2:policy 配置命令参考
ip policy as100 permit
match as-path 1
match community 1
route-map RP permit 10
match policy-list as100
set local-preference 300
3:配置实验参考
该实验需求如下:
我在 AS-400 的 BGP 路由器只想收到关于 AS 100、AS 200 的路由跟新
那么我们可以直接在 AS-400 的 BGP 路由器做 in 方向策略
配置关键命令如下:
ip prefix-list 1 permit 10.0.0.0/8
ip as-path access-list 1 permit ^100_
ip as-path access-list 2 permit ^200_
-------------------------------------------------------------------------------------
ip policy-list as100 permit
match as-path 1
ip policy-list as200 permit
match as-path 2
-------------------------------------------------------------------------------------
route-map test permit 10
match ip address prefix-list 1
`match policy-list as100 as200` !! 逻辑 or 关系
set metric 1000
route-map test permit 20
其实通过这个实验,我们对 policy-list 并不会有很大的印象,我这里最为有印象的还是 BGP 的 AS-PATH 属性
因为我们可以通过 BGP 的各种属性,去实现我们各种各样的需求和策略
比如该实验环境中的需求:只要来自 AS-200,AS-100 的路由跟新
那么我们就可以关联其 AS-path 值,实在是感叹,BGP 路由设计,太过强大了
0x05:Advertise-map
0x06:ORF 🔺🔺
观察上图:
1:R1 通告给 R2 10000 BGP 路由,其实 R2 只想要其中的 100 条对他有用的路由
-
这个时候,对于 R2 来说,它可以在 in 方向本地部署 prefix-list 前缀列表等工具来匹配自己想要的路由
-
但是,其实 R1 是已经明确的发送了这 10000 条路由给 R2 了,虽然 R2 部署了策略获得了自己想要 100条路由,但是,那其他剩余的 9900 条路由仍然会发送给 R2,R2 只不过是将其过滤在 BGP 表之外而已,这种情况就会使得,路由白白通告出去,去浪费链路的带宽与资源,和设备的性能 CPU 资源,
最理想的方式:R1 就把 R2 需要的路由更新给 R2
观察过度到下方的图:
通过 ORF 的关系建立,R2 会把自己的过滤方案,发送给 R1,使得 R1 能够发送 R2 想要的路由,
其发送消息,存在 Refresh 报文 route refresh with ORF Message
ORF 实验应用
验证命令:show ip bgp neighbors ip-address advertised-routes
!! R1 配置如下
router bgp 100
neighbor 10.1.1.2 remote-as 200
!
address-family ipv4
`neighbor 10.1.1.2 activate
neighbor 10.1.1.2 capability orf prefix-list receive`
network 1.1.1.0 mask 255.255.255.0
network 2.2.2.0 mask 255.255.255.0
!
end
!! R2 配置如下
!
`address-family ipv4
neighbor 10.1.1.1 activate
neighbor 10.1.1.1 capability orf prefix-list send
neighbor 10.1.1.1 prefix-list 1 in
exit-address-family `
!
ip prefix-list 1 seq 5 deny 1.1.1.0/24
ip prefix-list 1 seq 15 permit 0.0.0.0/0 le 32
!
end
配置完毕后,R1 激活 ORF 能力支持,接收 R2 prefix-list refresh 信息,只发送除了 1.1.1.0/24 的路由给 R2
!! R1 验证
R1#show ip bgp neighbors 10.1.1.2 advertised-routes
BGP table version is 3, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 2.2.2.0/24 0.0.0.0 0 32768 i
Total number of prefixes 1
0x07:路由拆分 BGP Deaggregation 🔺
所谓的路由拆分,其实是建立在拥有汇总路由的基础之上做的拆简
如果我们需求如下:
1:需要精简路由条目,减少下游 BGP 路由器的工作负担
2:同时下游 BGP 路由器,能够拆简这条汇总路由,形成数据分流
那么这个时候,基本上就只有路由拆分能完美符合该需求,参考下图:
背景详解:
拆分可以通过使用条件注入 ( conditional injection ) 来完成,所谓 conditional injection 指的就是:
当特定的汇总路由存在时,我可以生成其下属的特定明细,这些明细路由将被注入到本地 BGP RIB (本地路由表也会加载明细路由信息),以便在本地 AS 中提供比汇总路由更加详细的路由选择信息 (更长的前缀)
哎,简单说只有我这个汇总路由存在,该明细才会拆分成功,如果汇总路由不存在,则拆分自然失效
配置:
配置步骤如下 🔺🔺
1:创建 Prefix-list 匹配汇总路由
2:创建 Prefix-list 匹配这条汇总路由的更新源
3:创建 Prefix-list 匹配我要拆分汇总路由中,要注入的明细路由
4:创建 route-map match 汇总路由,match 汇总路由源
5:创建 route-map set 我要注入的明细
6:进入 BGP 进程关联明细,关联汇总。
实验参考
topo 图如下:
!! R1 配置过程如下:
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial0/0
ip address 10.1.1.1 255.255.255.0
!
router bgp 100
network 1.1.1.0 mask 255.255.255.0
aggregate-address 1.0.0.0 255.0.0.0 as-set summary-only
neighbor 10.1.1.2 remote-as 200
!
end
!! R2 配置过程如下:* 主要配置在于 R2
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Serial0/0
ip address 10.1.1.2 255.255.255.0
!
interface Serial0/1
ip address 20.1.1.1 255.255.255.0
!
router ospf 1
network 2.2.2.2 0.0.0.0 area 0
network 20.1.1.1 0.0.0.0 area 0
!
router bgp 200
bgp inject-map mingxi exist-map huizong
neighbor 3.3.3.3 remote-as 200
neighbor 3.3.3.3 update-source Loopback0
neighbor 10.1.1.1 remote-as 100
!
ip prefix-list 1 seq 5 permit 1.0.0.0/8
!
ip prefix-list 111 seq 5 permit 1.1.1.0/24
!
ip prefix-list source seq 5 permit 10.1.1.1/32
!
route-map mingxi permit 10
set ip address prefix-list 111
!
route-map huizong permit 10
match ip address prefix-list 1
match ip route-source source
!
end
!! R3 配置过程如下:
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface Serial0/1
ip address 20.1.1.2 255.255.255.0
!
router ospf 1
network 3.3.3.3 0.0.0.0 area 0
network 20.1.1.2 0.0.0.0 area 0
!
router bgp 200
neighbor 2.2.2.2 remote-as 200
neighbor 2.2.2.2 update-source Loopback0
!
end