先看R2上的命令:
route-policy AS-PATH permit node 10 if-match as-path-filter BGP route-policy AS-PATH deny node 20 ip as-path-filter BGP permit ^[^2]00 400 100.
答案在这里:
apply as-path 400 100 200 300 overwrite
就是DY个400,第二个100,第三个200,第四个300
正则表达式的规则在这里:
也可以看这个:
https://support.huawei.com/enterprise/zh/knowledge/EKB0000394119?idAbsPath=7919710
A:
正则表达式是按照一定的模板来匹配字符串的公式。然后对BGP路由的AS_PATH属性做出响应的判断(接收或者拒绝)。实际上可以认为它是一个AS_PATH的ACL。
正则表达式常用符号:
符号 说明
^ 匹配一个字符串的开始。如“^200”表示只匹配AS_PATH的DY个值为200。
$ 匹配一个字符串的结束。如“200$”表示只匹配AS_PATH的final一个值为200。
. 匹配任何单个字符,包括空格。但是有些厂商实现的不一样,比如阿尔卡特的这个字符也可以匹配一个AS号。
+ 匹配前面的一个字符或者一个序列,1次或者多次出现。
_ 匹配一个符号。如逗号,括号,空格符号等。
* 匹配前面的一个字符或者一个序列,可以0次或者多次出现。
? 匹配前面的一个字符,可以0次或者多次出现。
( ) 匹配的变化的AS或者一个独立的匹配,通常和“|”一起使用。
| 逻辑或
[ ] 匹配的一个范围内的AS,通常和“-”一起使用
- 连接符
? ip as-path-acl 2 deny 70$ (拒绝从AS70始发的路由)
? ip as-path-acl 2 permit .* (允许其他AS的路由)
做了一下,解决了,拓扑结构:
配置:
Router1:
R1: sys sys R1 int loo0 ip add 10.0.0.1 24 int e0/0/0 ip add 12.0.0.1 24 bgp 300 peer 12.0.0.2 as-number 230 peer 12.0.0.2 route-policy AS-PATH export network 10.0.0.0 24 quit route-policy AS-PATH permit node 10 if-match ip-prefix BGP apply as-path 400 100 200 300 overwrite quit ip ip-prefix BGP permit 10.0.0.0 24 quit 查看发送: sys dis bgp routing-table peer 12.0.0.2 advertised-routes
Router2:
R2: sys sys R2 int e0/0/0 ip add 12.0.0.2 24 int e0/0/1 ip add 23.0.0.2 24 bgp 230 peer 12.0.0.1 as-number 300 peer 23.0.0.3 as-number 230 quit 查看接收: sys dis bgp routing-table peer 12.0.0.1 received-routes 配置策略: sys route-policy AS-PATH permit node 10 if-match as-path-filter BGP route-policy AS-PATH deny node 20 quit ip as-path-filter BGP permit ^[^2]00 400 100. quit sys bgp 230 peer 12.0.0.1 route-policy AS-PATH import quit