问题描述
BGP 路由控制包括控制路由的发布和接收。通常通过 Route Policy 实现:即通过 路由匹配工具 匹配特定路由,再通过 路由策略工具 对路由的发布和接收进行控制;
解决方案
针对 BGP 路由控制:
路由匹配工具:
1)ACL(Access Control List,访问控制列表);
2)IP Prefix List(地址前缀列表),AS_PATH Filter,Community Filter
路由策略工具:
1)Filter-Policy
2)Route-Policy;
路由匹配方法:
1)BGP 路由控制通常影响的属性包括:AS_PATH;Community;
2)通过对这两个属性的匹配,来选择需要操作的路由条目;
IP AS_PATH Filter
AS_PATH Filter 是个过滤器,将 BGP.AS_PATH 属性作为匹配条件,对路由进行过滤;
在不希望接收某些 AS 的路由时,可以利用 AS_PATH Filter 对携带这些 AS 号的路由进行过滤,从而实现拒绝某些路由。
通过正则表达式匹配
例如:
如果需要匹配 AS_Path=103 102 101 的 AS103,则可以通过 ^103 或 ^103_ 来实现; ^$ 匹配不包含任何 AS Number 的 AS_Path,也就是本 AS 内的路由 .* 匹配所有,任何路由 ^10[012349]$ 匹配 100、101、102、103、104、109 ^10[^0-6]$ 匹配除 100~106 以外的 AS_Path ^10. 匹配 100~109,以及 10 ^12(_34)?_56$ 匹配 12 56 及 12 34 56
常用的基础配置命令
// ---------------------------------------------------------------------------- // 第一步、创建 [Huawei] ip as-path-filter { number | name } { deny | permit } regular-expression AS_Path Filter 使用正则表达式来定义匹配规则。 在同个过滤器编号下,可以定义多条过滤规则(permit 或 deny 模式)。 在匹配过程中,规则间是“或”的关系,即只要路由信息通过其中一项规则,就认为通过由该过滤器编号标识的这组 AS_Path Filter。 AS_Path Filter 的默认行为是 deny,即路由如果没有在某一次过滤中被 permit 则最终不能通过该过滤器的过滤。 如果一个过滤器中的所有过滤规则都是 deny,则没有路由能通过该过滤器的过滤。 这种情况下需要在多次(或一次)deny 之后设置一次 permit,允许其余所有路由通过过滤器的过滤。 // ---------------------------------------------------------------------------- // 第二步、应用 # 直接调用方式:在 BGP AF 下,对 BGP 路由信息应用路由策略时,基于 AS_Path Filter 过滤掉不符合条件的路由信息: [Huawei-bgp-af-ipv4] peer { group-name | address } as-path-filter { number | name } { import | export } // ---------------------------------------------------------------------------- // 通过 Route Policy 处理 # 或在 Route-Policy 下,创建一个基于 AS_Path Filter 的匹配规则。 [Huawei-route-policy] if-match as-path-filter { number | name } [Huawei-bgp-af-ipv4] peer { group-name | address } route-policy {name}
配置案例
路由策略方式:
[R2] ip as-path-filter 1 deny _101$ [R2] ip as-path-filter 1 permit .* [R2] route-policy AS_Path permit node 10 [R2-route-policy] if-match as-path-filter 1 [R2] bgp 102 [R2-bgp] peer 10.1.23.3 as-number 103 [R2-bgp] ipv4-family unicast [R2-bgp-af-ipv4] peer 10.1.23.3 route-policy AS_Path export [R2]display ip as-path-filter 1 As path filter number: 2 deny _101$ permit .* [R2]display bgp routing-table regular-expression _101$ Total Number of Routes: 1 BGP Local router ID is 10.1.12.2 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.1/32 10.1.12.1 0 0 101i
IP COMMUNITY Filter
COMMUNITY Filter 与 COMMUNITY 属性配合使用,可以在不便使用 IP Prefix List 和 AS_Path Filter 时,降低路由管理难度。
COMMUNITY Filter 有两种类型:
1)基本 Community Filter:匹配公认 Community 属性,或团体号;
2)高级 Community Filter:通过正则表达式匹配团体号;
常用的基础配置命令
// ---------------------------------------------------------------------------- // 在路由策略中,设置路由的 Community 属性值 [Huawei-route-policy] apply community { community-number ... } [ additive ] // ---------------------------------------------------------------------------- // 将团体属性发布给对等体(组) # 缺省情况,BGP 不将团体属性发布给任何对等体(组)。 [Huawei-bgp-af-ipv4] peer { group-name | ipv4-address | ipv6-address } advertise-community // ---------------------------------------------------------------------------- // 创建 Community Filter 配置 # 基本 Community Filter 编号范围:1~99。在基本 Community Filter 中只能指定团体号或知名团体属性。 # 高级 Community Filter 编号范围:100~199。在高级 Community Filter 中可以指定正则表达式作为匹配条件。 [Huawei] ip community-filter { basic name | num } { permit | deny } [ community-number... ] [Huawei] ip community-filter { advanced name | num } { permit | deny } regular-expression # 匹配同时携带 Community 值 [100:1,200:1,300:1]的路由。(多个 Community 值之间是“与”的关系) ip community-filter 1 permit 100:1 200:1 300:1 # 匹配携带 Community 值[100:1]或[200:1,300:1]的路由。(多组 Community 值之间是“或”的关系) ip community-filter 1 permit 100:1 ip community-filter 1 permit 200:1 300:1 # 匹配携带以 10 开头的 Community 值的路由。 ip community-filter 100 permit ^10 // ---------------------------------------------------------------------------- // 应用 Community Filter 配置 # 在 Route-Policy 视图下,创建一个基于 Community Filter 的匹配规则。 [Huawei-route-policy] if-match community-filter { basic-comm-filter-num [ whole-match ] | adv-comm-filter-num } [Huawei-route-policy] if-match community-filter comm-filter-name [ whole-match ]