当前位置: 首页 > article >正文

AS_Path过滤器应用灵活配置示例

本文摘自笔者编辑出版的《华为HCIP-Datacom路由交换学习指南》,通过示例演示了BGP AS_Path过滤器在BGP路由过滤方面的灵活应用。

如图8-73所示,相邻路由器间建立EBGP对等体关系,并在RouterA、RouterB和RouterD上把对应的Loopback0接口所代表的网段路由引入到了BGP路由表中。现要通过AS_Path Filter实现以下目的。

  • RouterB不接收始发于AS 400的BGP路由;
  • RouterD不接收包含AS 100的BGP路由。

图8-73 AS_Path Filter应用配置示例的拓扑结构

  1. 基本配置思路分析

AS_Path Filter的应用有两种方式,一种是直接在BGP地址族视图下调用,一种是在路由策略中调用。另外,一台BGP路由器不接收来自某个AS的路由也有两种配置方式,一是在发送端的AS边界路由器上配置,一种是接收方端的AS边界路由器上配置。本示例将分别予以介绍。

针对RouterB不接收始发于AS 400的BGP路由的要求,可以在RouterA上配置向RouterB发布路由时通过AS_Path Filter进行过滤,也可以在RouterB上配置接收来自RouterA的路由时通过AS_Path Filter进行过滤,均拒绝AS_Path列表中第一个AS号(最右边的AS号)为400的BGP路由通过。此时,RouterB将学习不到RouterD引入的172.16.1.0/24网段BGP路由。

针对RouterD不接收包含AS 100的BGP路由的要求,可以在RouterC上配置向RouterD发布路由时通过AS_Path Filter进行过滤,也可以在RouterD上配置接收来自RouterC的路由时通过AS_Path Filter进行过滤,均拒绝AS_Path列表中包含AS 100的BGP路由通过。此时,RouterD将同时学习不到RouterA上的192.168.1.0/24网段BGP路由和RouterB上的192.168.2.0/24网段BGP路由。

基于AS_Path Filter的BGP路由过滤是在完成BGP路由基本功能配置基础上进行的,根据以上分析可得出本示例的基本配置思路如下:

(1)配置各路由器接口的IP地址。

(2)配置各路由器的BGP基本功能,并分别将RouterA、RouterB和RouterD上的Loopback0接口所在网段的路由通过network命令(也可以是import-route命令)引入到BGP路由表中。

(3)在RouterA上配置AS_Path Filter,拒绝向RouterB通告AS_Path属性中最右边AS号为400的BGP路由;或者在RouterB上配置AS_Path Filter,拒绝从RouterA接收AS_Path列表中最右边AS号为400的BGP路由。

(4)在RouterC上配置AS_Path Filter,拒绝向RouterD通告AS_Path属性中包含AS 100的BGP路由;或者在RouterD上配置AS_Path Filter,拒绝从RouterC接收AS_Path列表中包含AS 100的BGP路由。

2. 配置和验证

(1)配置各路由器的接口IP地址。在此仅介绍RouterA上的配置,其他路由器上的配置方法一样,略。

<RouterA> system-view

[RouterA] interface gigabitethernet 0/0/0

[RouterA-GigabitEthernet0/0/0] ip address 10.1.1.1 24

[RouterA-GigabitEthernet0/0/0]quit

[RouterA] interface gigabitethernet 0/0/1

[RouterA-GigabitEthernet0/0/1] ip address 10.1.2.1 24

[RouterA-GigabitEthernet0/0/1]quit

[RouterA] interface loopback0

[RouterA-Loopback0] ip address 192.168.1.1 24

[RouterA-Loopback0]quit

(2)配置各路由器的BGP基本功能。EBGP对等体间使用直连物理接口建立TCP连接,RouterA~RouterD四台路由器的Router ID分别配置为1.1.1.1~4.4.4.4,并在RouterA、RouterB、RouterD上Loopback0接口对应网段路由引入到BGP路由表中。

  • RouterA上的配置。

[RouterA] bgp 100

[RouterA-bgp] router-id 1.1.1.1

[RouterA-bgp] peer 10.1.1.2 as-number 200

[RouterA-bgp] peer 10.1.2.2 as-number 300

[RouterA-bgp] network 192.168.1.0 24

  • RouterB上的配置。

[RouterB] bgp 200

[RouterB-bgp] router-id 2.2.2.2

[RouterB-bgp] peer 10.1.1.1 as-number 100

[RouterB-bgp] network 192.168.2.0 24

  • RouterC上的配置。

[RouterC] bgp 300

[RouterC-bgp] router-id 3.3.3.3

[RouterC-bgp] peer 10.1.2.1 as-number 100

[RouterC-bgp] peer 10.1.3.2 as-number 400

  • RouterD上的配置。

[RouterD] bgp 400

[RouterD-bgp] router-id 4.4.4.4

[RouterD-bgp] peer 10.1.3.1 as-number 300

[RouterD-bgp] network 172.16.1.0 24

以上配置好后,在RouterB上执行display bgp routing-table命令,可看到他已学习到了RouterA和RouterD上所引入的两个网段的BGP路由,如图8-74所示。在RouterD上执行display bgp routing-table命令,可看到他已学习到了RouterA和RouterB上所引入的两个网段的BGP路由,如图8-75所示。

图8-74  RouterB上学习到的RouterA和RouterD所引入的两个网段BGP路由

图8-75  RouterD上学习到的RouterA和RouterB所引入的两个网段BGP路由

(3)在RouterA上配置AS_Path Filter,拒绝向RouterB通告AS_Path列表中最右边AS号为400的BGP路由;或者在RouterB上配置AS_Path Filter,拒绝从RouterA接收AS_Path列表中最右边个AS号为400的BGP路由。下面是这两种配置方案的具体配置方法。

方案一:在RouterA上配置AS_Path Filter

[RouterA] ip as-path-filter 1 deny _400$   #---拒绝AS_Path表列中以AS 400结束的BGP路由

[RouterA] ip as-path-filter 1 permit .*  #---允许其他所有BGP路由通过。必须要配置,以允许其他路由通过,因为AS_Path过滤器的缺省匹配模式为deny

  • 采用直接调用AS_Path Filter的配置方式:

[RouterA] bgp 100

[RouterA-bgp] peer 10.1.1.2 as-path-filter 1 export  #---向对等体RouterB通告路由时调用1号AS_Path过滤器

以上配置好后,再在RouterB上执行display bgp routing-table命令,可看到原来学习到的位于AS 400的172.16.1.0/24网段BGP路由没有了(对比图8-74),如图8-76所示。

图8-76 在RouterA上配置并应用好AS_Path Filter后,RouterB上的BGP路由表

  • 采用路由策略调用AS_Path Filter的配置方式:

[RouterA] route-policy as-path permit node 10

[RouterA-route-policy] if-match as-path-filter 1

[RouterA-route-policy] quit

[RouterA] bgp 100

[RouterA-bgp] peer 10.1.1.2 route-policy as-path export

以上配置好后,再在RouterB上执行display bgp routing-table命令,得到的效果与图8-76一样,同样没有了以前学习到的172.16.1.0/24网段BGP路由。

方案二:在RouterB上配置AS_Path Filter

[RouterB] ip as-path-filter 1 deny _400$ 

[RouterB] ip as-path-filter 1 permit .*

  • 采用直接调用AS_Path Filter的配置方式:

[RouterB] bgp 200

[RouterB-bgp] peer 10.1.1.1 as-path-filter 1 import  #---从对等体RouterA学习路由时调用1号AS_Path Filter

以上配置好后,再在RouterB上执行display bgp routing-table命令,得到的效果一样,参见图8-76。

  • 采用路由策略调用AS_Path Filter的配置方式:

[RouterB] route-policy as-path permit node 10

[RouterB-route-policy] if-match as-path-filter 1

[RouterB-route-policy] quit

[RouterB] bgp 200

[RouterB-bgp] peer 10.1.1.1 route-policy as-path import

以上配置好后,再在RouterB上执行display bgp routing-table命令,得到的效果一样,参见图8-76。

(4)在RouterC上配置AS_Path Filter,拒绝向RouterD通告AS_Path列表中包含AS 100的BGP路由;或者在RouterD上配置AS_Path Filter,拒绝从RouterC接收AS_Path列表中包含AS 100的BGP路由。

方案一:在RouterC上配置AS_Path Filter

[RouterC] ip as-path-filter 2 deny _100_   #---拒绝AS_Path表列中包含AS 100的BGP路由

[RouterC] ip as-path-filter 2 permit .*  #---允许其他所有BGP路由通过

此处仅采用直接调用AS_Path Filter的配置方式。

[RouterC] bgp 300

[RouterC-bgp] peer 10.1.3.2 as-path-filter 2 export  #---向对等体RouterD通告路由时调用1号AS_Path Filter

以上配置好后,再在RouterD上执行display bgp routing-table命令,可看到原来学习到的位于AS 100的192.168.1.0/24和位于AS 200的192.168.2.0/24两网段的BGP路由同时没有了(对比图8-75),如图8-77所示。因为原来在RouterD上的这两个网段的BGP路由的AS_Path表中都包含了AS 100。

图8-77 在RouterC上配置并应用好AS_Path Filter后,RouterD上的BGP路由表

方案二:在RouterD上配置AS_Path Filter

[RouterD] ip as-path-filter 2 deny _100_  

[RouterD] ip as-path-filter 2 permit .*

  • 采用直接调用AS_Path Filter的配置方式:

[RouterD] bgp 200

[RouterD-bgp] peer 10.1.3.1 as-path-filter 2 import  #---从对等体RouterA学习路由时调用1号AS_Path Filter

以上配置好后,再在RouterD上执行display bgp routing-table命令,得到的效果一样,参见图8-77。

  • 采用路由策略调用AS_Path Filter的配置方式:

[RouterD] route-policy as-path permit node 10

[RouterD-route-policy] if-match as-path-filter 2

[RouterD-route-policy] quit

[RouterD] bgp 200

[RouterD-bgp] peer 10.1.3.1 route-policy as-path import

以上配置好后,再在RouterD上执行display bgp routing-table命令,得到的效果一样,参见图8-77。

通过以上配置即完全实现了本示例的目的。


http://www.kler.cn/a/581973.html

相关文章:

  • Nginx 缓存清理
  • Hugging Face的Transformers核心模块:Pipelines(参数说明,各种模型类型调用案例)
  • 第十一届蓝桥杯单片机国赛
  • 最后一个单词的长度(js实现,LeetCode58)
  • 简单工厂 、工厂方法模式和抽象工厂模式
  • Spring-事务
  • Qt测试程序经过的时间
  • UI自动化:Python + Selenium4.6以前的版本 环境搭建
  • 熬夜肝,如何免邀请码使用Manus(全套教程)
  • Vite为什么选用Rollup打包?
  • 开源数字人模型Heygem
  • Matlab中快速查找元素索引号
  • 涨薪技术|Kubernetes(k8s)之Service服务类型
  • Epoch 和 Batch Size的设计 + 模型的早停策略(基于上篇)
  • 物联网中如何增加其可扩展性 协议 网络 设备 还包括软件层面上的
  • 内存检测工具——Qt Creator
  • 2.装饰器模式
  • 基于深度学习的医学图像分割算法研究——结合MRI/CT图像的肿瘤区域自动分割与三维重建
  • STM32全系大阅兵(2)
  • rust语言match模式匹配涉及转移所有权Error Case