BGP

【図解/BGP】ip prefix-listとroute-mapを使ったルートフィルタリング

BGP では route-map を使って BGP ルートを柔軟に制御できます。

今回はその中でも prefix-list での制御を紹介します。

prefix-list と access-list でどのような違いがあるか、という点にも触れておきます。

route-map + access-list によるルートフィルタリング

BGP で扱うルートは、サブネットマスク長が異なれば異なるルートとして扱われます。なので、10.1.4.0/24 と 10.1.4.0/23 は異なる宛先ルートとして扱われます。

そして BGP で route-map + access-list でルートフィルタを行うときは、サブネットマスク (プレフィックス) は意識されません。

例えば以下の構成において、RT4 上で route-map + access-list による inbound のルートフィルタを掛けるとします。

実験のために 3 つのアクセスリスト、3つのルートマップを用意します。

RT4(config)# access-list 1 permit 10.1.4.0 0.0.1.255
RT4(config)# access-list 2 permit 10.1.4.0 0.0.1.0
RT4(config)# access-list 3 permit 10.1.4.0 0.0.2.255

RT4(config)# route-map ACL1
RT4(config-route-map)# match ip address 1

RT4(config)# route-map ACL2
RT4(config-route-map)# match ip address 2

RT4(config)# route-map ACL3
RT4(config-route-map)# match ip address 3

[ACL1 による route-map 制御]

RT4(config-router)# neighbor 10.1.34.3 route-map ACL1 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp

     Network          Next Hop     Metric   LocPrf   Weight   Path
 *>  10.1.4.128/25    10.1.34.30                          0   65003 65001 i
 *>  10.1.4.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.4.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.4.0/22      10.1.34.3                           0   65003 65001 i
 *>  10.1.5.0/24      10.1.34.3                           0   65003 65001 i

サブネットマスク(プレフィックス) は関係なく、10.1.4. および 10.1.5. のルートだけが残りました。

ACL2 を使うと ACL1 の結果から 10.1.4.128/25 が外れます。

RT4(config-router)# no neighbor 10.1.34.3 route-map ACL1 in
RT4(config-router)# neighbor 10.1.34.3 route-map ACL2 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp
     Network          Next Hop     Metric   LocPrf   Weight   Path
 *>  10.1.4.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.4.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.4.0/22      10.1.34.3                           0   65003 65001 i
 *>  10.1.5.0/24      10.1.34.3                           0   65003 65001 i

ACL1 では第4オクテットはワイルドカードで自由でしたが、ACL2 では第4オクテットが 0 で固定されるからです。

ACL3 を使うと 10.1.4. と 10.1.6. が残ります。

RT4(config-router)# no neighbor 10.1.34.3 route-map ACL2 in
RT4(config-router)# neighbor 10.1.34.3 route-map ACL3 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp

     Network          Next Hop      Metric   LocPrf   Weight   Path
 *>  10.1.4.128/25    10.1.34.30                           0   65003 65001 i
 *>  10.1.4.0/24      10.1.34.3                            0   65003 65001 i
 *>  10.1.4.0/23      10.1.34.3                            0   65003 65002 i
 *>  10.1.4.0/22      10.1.34.3                            0   65003 65001 i
 *>  10.1.6.0/24      10.1.34.3                            0   65003 65001 i
 *>  10.1.6.0/23      10.1.34.3                            0   65003 65002 i

route-map + prefix-list によるルートフィルタリング

これが prefix-list を使うとルートマッチングにサブネットマスク (プレフィックス) の情報も使うことができます。

実験用に 3 つの prefix-list と 3 つの route-map を用意します。

RT4(config)# ip prefix-list PFX1 permit 10.1.4.0/24
RT4(config)# ip prefix-list PFX2 permit 10.1.4.0/22 ge 23 le 24
RT4(config)# ip prefix-list PFX3 permit 10.1.4.0/22 le 24
RT4(config)# route-map PFXMAP1
RT4(config-route-map)# match ip address prefix-list PFX1

RT4(config)# route-map PFXMAP2
RT4(config-route-map)# match ip address prefix-list PFX2

RT4(config)# route-map PFXMAP3
RT4(config-route-map)# match ip address prefix-list PFX3

le は less equal (以下)、ge は greater equal (以上) という意味です。le と ge が両方無いときは / の後のサブネットマスク長がそのまま使われます。

なので PFX1 を適用すると、10.1.4.0/24 だけが残ります。

RT4(config-router)# neighbor 10.1.34.3 route-map PFXMAP1 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp

     Network          Next Hop     Metric   LocPrf   Weight   Path
 *>  10.1.4.0/24      10.1.34.3                           0   65003 65001 i

PFX2 を適用すると、ネットワーク部が 10.1.4.0/22 であり、サブネットマスク長が /23 以上、/24 以下のものが残ります。

つまり、ネットワーク部が 10.1.4.0 ~ 10.1.7.255 のいずれかにヒットし、サブネットマスクが /23 もしくは /24 のものが残ります。

RT4(config-router)# no neighbor 10.1.34.3 route-map PFXMAP1 in
RT4(config-router)# neighbor 10.1.34.3 route-map PFXMAP2 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp

     Network          Next Hop     Metric   LocPrf   Weight   Path
 *>  10.1.4.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.4.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.5.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.6.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.6.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.7.0/24      10.1.34.3                           0   65003 65001 i

PFX3 を適用すると PFX2 の結果に /22 も加わります。

RT4(config-router)# no neighbor 10.1.34.3 route-map PFXMAP2 in
RT4(config-router)# neighbor 10.1.34.3 route-map PFXMAP3 in
RT4(config-router)# do clear ip bgp * soft
RT4(config-router)# do sh ip bgp

     Network          Next Hop     Metric   LocPrf   Weight   Path
 *>  10.1.4.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.4.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.4.0/22      10.1.34.3                           0   65003 65001 i
 *>  10.1.5.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.6.0/24      10.1.34.3                           0   65003 65001 i
 *>  10.1.6.0/23      10.1.34.3                           0   65003 65002 i
 *>  10.1.7.0/24      10.1.34.3                           0   65003 65001 i

コメント

タイトルとURLをコピーしました