目录

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

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

本文摘自笔者编辑出版的 ,通过示例演示了BGP AS_Path过滤器在BGP路由过滤方面的灵活应用。

https://i-blog.csdnimg.cn/direct/ecc8496334fe4999bf22f2305849df1b.png

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

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

https://i-blog.csdnimg.cn/direct/15fb970bdcda4b98b4490df254df36e6.png

图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路由。

  1. 配置和验证

(1)配置各路由器的接口IP地址。在此仅介绍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连接,RouterARouterD四台路由器的Router ID分别配置为1.1.1.14.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所示。

https://i-blog.csdnimg.cn/direct/8293c51a350c432a8e02ce7a5beb73d9.png

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

https://i-blog.csdnimg.cn/direct/3ee9d3f28d554beaaa1667ddceaed4c4.png

图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所示。

https://i-blog.csdnimg.cn/direct/b4f681cc593e40388123510677044d7c.png

图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。

https://i-blog.csdnimg.cn/direct/87731478657a45baa34aae8a07f5dca9.png

图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。

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