BGP的正则表达式一般用在as-path中,常用的如下:

.(点):表示匹配任意一个字符,包括空格。

*:表示匹配零个或多个模式的出现。即前一个字符出现0次或多次。

+:表示匹配一个或多个模式的出现。即前一个字符出现1次或多次。

?:表示匹配零个或一个模式的出现。即前一个字符出现0次或一次。

^:表示匹配字符串的开始。

$:表示匹配字符串的结束。

_(下划线):匹配逗号、左大括号、右大括号、左小括号、右小括号、字符串的开始、字符串的结束或空格.

[]:匹配中括号中的任意字符之一。如[AB],则表示匹配A或B

|:匹配其中之一。如A|B,则表示匹配A或B。

-:表示的是范围。如[1-3],则表示匹配的是1、2、3中的单个字符。

有的时候,我们需要根据需求去过滤某些从其他AS学习来的BGP前缀,不传递到自己的peer。例如如下如:AS4上不需要学习AS1和AS12学习来的1.1.1.1/24、2.2.2.2/24和10.1.1.0/24

我们可以在R3上看出,邻居建立完成。

R3#sho ip b summ
BGP router identifier 3.3.3.3, local AS number 3
BGP table version is 6, main routing table version 6
5 network entries using 585 bytes of memory
5 path entries using 260 bytes of memory
5/4 BGP path/bestpath attribute entries using 620 bytes of memory
3 BGP AS-PATH entries using 72 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1537 total bytes of memory
BGP activity 5/0 prefixes, 5/0 paths, scan interval 60 secs

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
13.1.1.1 4 1 19 22 6 0 0 00:14:13 2
23.1.1.2 4 12 18 22 6 0 0 00:14:10 1
34.1.1.4 4 4 18 18 6 0 0 00:14:16 1

且在R3上可以看到从AS1和AS12学习来的BGP前缀。

R3#sho ip bgp
BGP table version is 6, local router ID is 3.3.3.3
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 13.1.1.1 0 0 1 i  <<<<<<<
*> 2.2.2.0/24 23.1.1.2 0 0 12 i <<<<<<<<<
*> 3.3.3.0/24 0.0.0.0 0 32768 i
*> 4.4.4.0/24 34.1.1.4 0 0 4 i
*> 10.1.1.0/24 13.1.1.1 0 0 1 i <<<<<<<<<<

此时在R4上也可以看到对应的BGP前缀:

R4#sho ip bgp
BGP table version is 6, local router ID is 4.4.4.4
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 34.1.1.3 0 3 1 i
*> 2.2.2.0/24 34.1.1.3 0 3 12 i
*> 3.3.3.0/24 34.1.1.3 0 0 3 i
*> 4.4.4.0/24 0.0.0.0 0 32768 i
*> 10.1.1.0/24 34.1.1.3 0 3 1 i

此时可以使用多种方式过滤,下列是使用route-map匹配local产生的BGP前缀的方式:

R3#sho run | s route-map
neighbor 34.1.1.4 route-map cisco out
route-map cisco permit 10
match route-type local
R3#sho run | s r b
router bgp 3
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
network 3.3.3.0 mask 255.255.255.0
neighbor 13.1.1.1 remote-as 1
neighbor 23.1.1.2 remote-as 12
neighbor 34.1.1.4 remote-as 4
neighbor 34.1.1.4 route-map cisco out
no auto-summary

显示效果如下:

R4#cle ip b * soft

R4#sho ip bgp
BGP table version is 9, local router ID is 4.4.4.4
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
*> 3.3.3.0/24 34.1.1.3 0 0 3 i
*> 4.4.4.0/24 0.0.0.0 0 32768 i

其他的两种方式:

在R3上配置:

1、直接使用filter-list调用as-path access-list

R3(config)#ip as-path access-list 1 permit ^$
R3(config)#router bgp 3
R3(config-router)#nei 34.1.1.4 filter-list 1 out

PS:也可以使用route-map匹配as-path access-list:

R3(config)#route-map Test per 10
R3(config-route-map)#match as-path 1

R3(config-route-map)#exit
R3(config)#router bgp 3
R3(config-router)#nei 34.1.1.4 route-map Test out

2、使用deny不需要的AS的前缀,然后permit所有。

R3(config)#ip as-path access-list 1 deny _1_
R3(config)#ip as-path access-list 1 deny _12_
R3(config)#ip as-path access-list 1 permit .*
R3(config)#router bgp 3
R3(config-router)#nei 34.1.1.4 filter-list 1 out

Other:测试正则表达式匹配的前缀:

命令

R3#sho ip bg regexp ?
LINE A regular-expression to match BGP AS paths. Use "ctrl-v ?" to enter "?"

R3#sho ip bgp ?
A.B.C.D IP prefix <network>/<length>, e.g., 35.0.0.0/8
A.B.C.D Network in the BGP routing table to display
all All address families
cidr-only Display only routes with non-natural netmasks
community Display routes matching the communities
community-list Display routes matching the community-list
dampening Display detailed information about dampening
extcommunity-list Display routes matching the extcommunity-list
filter-list Display routes conforming to the filter-list
inconsistent-as Display only routes with inconsistent origin ASs
injected-paths Display all injected paths
ipv4 Address family
ipv6 Address family
labels Display Labels for IPv4 NLRI specific information
neighbors Detailed information on TCP and BGP neighbor connections
nsap Address family
oer-paths Display all oer controlled paths
paths Path information
peer-group Display information on peer-groups
pending-prefixes Display prefixes pending deletion
prefix-list Display routes matching the prefix-list
quote-regexp Display routes matching the AS path "regular expression"
regexp Display routes matching the AS path regular expression
replication Display replication status of update-group(s)
rib-failure Display bgp routes that failed to install in the routing
table (RIB)
route-map Display routes matching the route-map
summary Summary of BGP neighbor status
template Display peer-policy/peer-session templates
update-group Display information on update-groups
vpnv4 Address family
| Output modifiers

<cr>

BGP前缀过滤(正则表达式)的更多相关文章

  1. HCNP Routing&Switching之BGP路由过滤和AS-Path-Filter

    前文我们聊了下通过修改BGP路由属性来影响路由,从而达到控制BGP路由的目的:回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15495585.html:今天我们 ...

  2. BGP - 不同 AS 间运行的协议

    在之前介绍的网络场景中,ERGRP,OPSF,RIP 等都是运行在单独一个 AS(自治系统之间).这些协议统称为 IGP - 内部网关协议 ,目的主要是为自治系统内发现邻居和计算路由,从而找到合适的路 ...

  3. hbase 基本的JavaApi 数据操作及数据过滤(filter)

    本文主要是hbase的表操作.数据操作.数据查询过滤等,如果对JDBC或ADO有了解,容易理解HBASE API. hbase版本是2.0. 1.为了方便先贴helper的部分代码(文末git上有完整 ...

  4. hbase各种遍历查询shell语句 包含过滤组合条件

    import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Li ...

  5. 专家告诉你!如何避免黑客BGP劫持?

    BGP前缀劫持是针对Internet组织的持久威胁,原因是域间路由系统缺乏授权和身份验证机制. 仅在2017年,数千起路由事件导致代价高昂的中断和信息拦截,而问题的确切程度未知.尽管在过去20年中已经 ...

  6. 通过正则表达式实现简单xml文件解析

    这是我通过正则表达式实现的xml文件解析工具,有些XHTML文件中包含特殊符号,暂时还无法正常使用. 设计思路:常见的xml文件都是单根树结构,工具的目的是通过递归的方式将整个文档树装载进一个Node ...

  7. ES5 对数组方法的扩展 以及 正则表达式

    ES5 对数组的扩展 forEach map some every indexOf lastIndexOf forEach 与 map 语法: 数组.forEach(function ( v, i ) ...

  8. [置顶] 正则表达式应用:匹配IP地址

    都知道iP地址有四个数值,三个点号组成.三个数值的具体范围为0到255,为了使用正则表达式匹配就必须分析IP地址的组成 1先分析数值,2再组合数值和点号 1先分析数值 IP地址的数字范围从0到255, ...

  9. CCIE路由实验(3) -- BGP高级部分

    当一个AS包含多个IBGP对等体时,路由反射器非常有用.因为IBGP客户只需要和路由反射器建立邻居关系,从而降低了IBGP的连接数量.路由反射器和它的客户合称为一个簇.路由反射是克服IBGP水平分割的 ...

随机推荐

  1. 题解【洛谷P1046】[NOIP2005普及组] 陶陶摘苹果

    [NOIP2005] 陶陶摘苹果 首先,我们用一个数组s[11]存储每个苹果的高度. 然后,用a表示陶陶的身高. 接着,用a+30与s[i]比较,大于则计数器加一. 最后,输出计数器的值即可. #in ...

  2. Ztree使用教程

    这两天项目需要写一个树形帮助,学习了我们项目组的老师的Ztree的树的写法,实现了这个帮助,下面来总结一下Ztree的用法. (也是参考的一篇csdn上的博客了) zTree 是一个依靠 jQuery ...

  3. Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)

    从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...

  4. 【C语言】移动指针

    移动指针 #include<stdio.h> int main() { char *s="哈哈哈哈哈哈"; for(*s;s!="\0";s++) ...

  5. 哪款C语言编译器(IDE)适合初学者?

    这里我们把“编译器”和“IDE(集成开发环境)”当做一个概念,不再加以区分. C语言的集成开发环境有很多种,尤其是 Windows 下,多如牛毛,初学者往往不知道该如何选择,本节我们就针对 Windo ...

  6. 每日扫盲:eclipse快捷键 包括查找类、方法、变量汇总

    [Ct rl+T] 搜索当前接口的实现类 1. [ALT +/]    此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类.方法和属性的名字时,多体验一下[ ...

  7. Visual Studio 2017:SQLite/SQL Server Compact ToolBox使用

    1.首先是下载安装插件:SQLite/SQL Server Compact Toolbox,也可以从工具-->扩展和更新-->联机-->搜索:SQLite/SQL Server Co ...

  8. 解决Cannot download "https://github.com/sass/node-sass/releases/download/binding.nod的问题

    npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

  9. 7_6 带宽(UVa140)<回溯法:最优性剪枝>

    给定一个图(V,E),其中V为顶点的集合,E为边的集合,属于VxV.给定V中元素的一种排序,那么顶点v的带宽定义如下:在当前给定的排序中,与v距离最远的且与v有边相连的顶点与v的距离.给定排序的带宽定 ...

  10. 错误记录(一):VSCode

    VS Code莫名其妙突然变卡. 后来重新安装,下载以前版本,设置防止循环,都不太管用. 最后想添加VS Code目录到windows扫描白名单,但因为系统之前是英文不太好看懂,所以又调回了中文. 这 ...