LoginSignup
0
1

BGPのフィルタリング設定(AS_PATH ACL)

Posted at

AS_PATH ACLについて

BGPではAS_PATH属性に基づいて経路情報のフィルタリングが行えるAS_PATH ACLを使用することができます。AS_PATH ACLでは、正規表現を使用して、AS_PATH属性を指定することで、柔軟に経路情報のAS_PATH属性をフィルタリングして、意図しない経路情報を送信または受信しないようにすることができます。

物理構成図

image.jpeg
環境はCMLで以下のように構成しています。
CSR1000-V(ルータ)×7
Alpine Linux(デスクトップ)×3
※CMLはネットワーク機器のシミュレートをするサービスでCisco社が有償で提供しています。

前回の記事で作成したMEDとLocal-Preferenceを使った構成に新規でRT7を追加して、BGPの設定を追加しています。

スタブASであるRT1、RT6、RT7の先には、PCを設置します。
PC1(10.1.0.1/24)
PC2(10.2.0.1/24)
PC3(10.3.0.1/24)

今回の目標は、PC1とPC3はPC2とだけ通信できるようにし、PC1とPC3間で通信が行えないようにすることです。この場合、RT2、RT3にAS_PATH ACLでそれぞれの経路をフィルタリングして経路情報を交換しないようにします。

BGPの設定

CMLでは下記のような画面になっています。
※desktop-0をPC1、desktop-1をPC2、desktop-3をPC3として設定しています。
image.jpeg

前回の記事でも具体的な設定コマンドを記載していましたが、あらためて必要なコンフィグを記載します。※設定に関係ないコンフィグは省略して記載しています。
主系の経路としてRT2、RT4を通るように設計しています。詳しい内容は前回の内容を参照ください。

RT1
router bgp 100
 bgp log-neighbor-changes
 network 10.1.0.0 mask 255.255.255.0
 network 10.10.1.0 mask 255.255.255.0
 network 10.10.2.0 mask 255.255.255.0
 neighbor 10.10.1.2 remote-as 200
 neighbor 10.10.2.2 remote-as 200
RT2
router bgp 200
 bgp log-neighbor-changes
 network 10.30.1.0 mask 255.255.255.0
 neighbor 10.10.1.1 remote-as 100
 neighbor 10.10.1.1 route-map PC1-subnet-LP in
 neighbor 10.10.1.1 route-map PC2-subnet-MED out
 neighbor 10.20.0.2 remote-as 200
 neighbor 10.20.0.2 next-hop-self
 neighbor 10.30.1.2 remote-as 300
 neighbor 10.30.1.2 route-map PC2-subnet-LP in
 neighbor 10.60.1.1 remote-as 500
 neighbor 10.60.1.1 route-map PC2-subnet-MED out
!
(省略)
!
!
!
ip access-list standard 1
 10 permit 10.1.0.0 0.0.0.255
 20 permit 10.3.0.0 0.0.0.255
ip access-list standard 2
 10 permit 10.2.0.0 0.0.0.255
!
!
route-map PC1-subnet-LP permit 10
 match ip address 1
 set local-preference 200
!
route-map PC1-subnet-LP permit 20
!
route-map PC2-subnet-LP permit 10
 match ip address 2
 set local-preference 200
!
route-map PC2-subnet-LP permit 20
!
route-map PC1-subnet-MED permit 10
 match ip address 1
 set metric 10
!
route-map PC1-subnet-MED permit 20
!
route-map PC2-subnet-MED permit 10
 match ip address 2
 set metric 10
!
route-map PC2-subnet-MED permit 20
RT3
router bgp 200
 bgp log-neighbor-changes
 network 10.30.2.0 mask 255.255.255.0
 neighbor 10.10.2.1 remote-as 100
 neighbor 10.10.2.1 route-map PC2-subnet-MED out
 neighbor 10.20.0.1 remote-as 200
 neighbor 10.20.0.1 next-hop-self
 neighbor 10.30.2.2 remote-as 300
 neighbor 10.60.2.1 remote-as 500
 neighbor 10.60.2.1 route-map PC2-subnet-MED out
!
(省略)
!
!
!
ip access-list standard 1
 10 permit 10.1.0.0 0.0.0.255
 20 permit 10.3.0.0 0.0.0.255
ip access-list standard 2
 10 permit 10.2.0.0 0.0.0.255
!
!
route-map PC1-subnet-MED permit 10
 match ip address 1
 set metric 20
!
route-map PC1-subnet-MED permit 20
!
route-map PC2-subnet-MED permit 10
 match ip address 2
 set metric 20
!
route-map PC2-subnet-MED permit 20
RT4
router bgp 300
 bgp log-neighbor-changes
 network 10.30.1.0 mask 255.255.255.0
 network 10.50.1.0 mask 255.255.255.0
 neighbor 10.30.1.1 remote-as 200
 neighbor 10.30.1.1 route-map PC1-subnet-LP in
 neighbor 10.40.0.2 remote-as 300
 neighbor 10.40.0.2 next-hop-self
 neighbor 10.50.1.2 remote-as 400
 neighbor 10.50.1.2 route-map PC2-subnet-LP in
 neighbor 10.50.1.2 route-map PC1-subnet-MED out
!
(省略)
!
!
!
ip access-list standard 1
 10 permit 10.1.0.0 0.0.0.255
 20 permit 10.3.0.0 0.0.0.255
ip access-list standard 2
 10 permit 10.2.0.0 0.0.0.255
!
!
route-map PC1-subnet-LP permit 10
 match ip address 1
 set local-preference 200
!
route-map PC1-subnet-LP permit 20
!
route-map PC2-subnet-LP permit 10
 match ip address 2
 set local-preference 200
!
route-map PC2-subnet-LP permit 20
!
route-map PC1-subnet-MED permit 10
 match ip address 1
 set metric 10
!
route-map PC1-subnet-MED permit 20
!
route-map PC2-subnet-MED permit 10
 match ip address 2
 set metric 10
!
route-map PC2-subnet-MED permit 20
RT5
router bgp 300
 bgp log-neighbor-changes
 network 10.50.2.0 mask 255.255.255.0
 neighbor 10.30.2.1 remote-as 200
 neighbor 10.40.0.1 remote-as 300
 neighbor 10.40.0.1 next-hop-self
 neighbor 10.50.2.2 remote-as 400
 neighbor 10.50.2.2 route-map PC1-subnet-MED out
!
(省略)
!
!
!
ip access-list standard 1
 10 permit 10.1.0.0 0.0.0.255
 20 permit 10.3.0.0 0.0.0.255
ip access-list standard 2
 10 permit 10.2.0.0 0.0.0.255
!
!
route-map PC1-subnet-MED permit 10
 match ip address 1
 set metric 20
!
route-map PC1-subnet-MED permit 20
!
route-map PC2-subnet-MED permit 10
 match ip address 2
 set metric 20
!
route-map PC2-subnet-MED permit 20
RT6
router bgp 400
 bgp log-neighbor-changes
 network 10.2.0.0 mask 255.255.255.0
 neighbor 10.50.1.1 remote-as 300
 neighbor 10.50.2.1 remote-as 300
RT7
router bgp 500
 bgp log-neighbor-changes
 network 10.3.0.0 mask 255.255.255.0
 network 10.60.1.0 mask 255.255.255.0
 network 10.60.2.0 mask 255.255.255.0
 neighbor 10.60.1.2 remote-as 200
 neighbor 10.60.2.2 remote-as 200

AS_PATH ACLの設定

現状の設定ですと、RT7とRT1はお互いに経路情報を交換してしまい、疎通が取れてしまいます。

RT7
RT7#sh ip bgp 10.1.0.0
BGP routing table entry for 10.1.0.0/24, version 5
Paths: (2 available, best #2, table default)
 Advertised to update-groups:
    1
 Refresh Epoch 3
 200 100
   10.60.2.2 from 10.60.2.2 (10.30.2.1)
     Origin IGP, localpref 100, valid, external
     rx pathid: 0, tx pathid: 0
     Updated on Dec 1 2023 13:48:08 UTC
 Refresh Epoch 4
 200 100
   10.60.1.2 from 10.60.1.2 (10.30.1.1)
     Origin IGP, localpref 100, valid, external, best
     rx pathid: 0, tx pathid: 0x0
     Updated on Dec 1 2023 15:30:58 UTC
RT7#ping 10.1.0.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.0.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms

PC1と PC3間で通信を行うのであればこのままでも問題ありませんが、両者を通信させたくない場合は、RT2、RT3で経路情報をフィルタリングをして、経路情報を広報する前に破棄させなければなりません。
設定は下記のようになります。

RT2
RT2(config)#ip as-path access-list 1 permit _300$
RT2(config)#ip as-path access-list 1 permit _400$
RT2(config)#ip as-path access-list 1 permit ^$
RT2(config)#router bgp 200
RT2(config-router)#nei 10.10.1.1 filter-list 1 out
RT2(config-router)#nei 10.60.1.1 filter-list 1 out
RT3
RT3(config)#ip as-path access-list 1 permit _300$
RT3(config)#ip as-path access-list 1 permit _400$
RT3(config)#ip as-path access-list 1 permit ^$
RT3(config)#router bgp 200
RT3(config-router)#nei 10.10.2.1 filter-list 1 out
RT3(config-router)#nei 10.60.2.1 filter-list 1 out

AS_PATH ACLは正規表現を扱うことができますので、AS_PATHアトリビュートを柔軟にフィルタリングできます。今回使用した特殊文字は下記のような意味を持ちます。

特殊文字 説明
_ 数字以外の任意の文字
^ 文字列の先頭と一致
$ 文字列の末尾と一致

上記の設定の_300\$は文字が300で終わるという意味になりますので、AS300が発生源の経路がマッチします。BGPでは経路情報をeBGPネイバーへ広報するときにAS番号を先頭に付けて広報するので、末尾のAS番号が経路の発信源になります。
また、^\$は空白の意味になり、自身のASが発生源の経路にマッチします。自身のASが発信源の経路情報は、eBGPネイバーから広報されてきたわけではないのでAS番号は空白となります。下記のBGPテーブル上の10.30.1.0/24、10.30.2.0/24の経路のようにAS番号が空白の経路については^$にマッチします。

RT2
RT2#sh ip bgp
BGP table version is 14, local router ID is 10.30.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      10.10.1.1                0    200      0 100 i
 *>   10.2.0.0/24      10.30.1.2                     200      0 300 400 i
 * i  10.3.0.0/24      10.20.0.2                0    100      0 500 i
 *>                    10.60.1.1                0             0 500 i
 r i  10.10.1.0/24     10.20.0.2                0    100      0 100 i
 r>                    10.10.1.1                0             0 100 i
 * i  10.10.2.0/24     10.20.0.2                0    100      0 100 i
 *>                    10.10.1.1                0             0 100 i
 *    10.30.1.0/24     10.30.1.2                0             0 300 i
 *>                    0.0.0.0                  0         32768 i
 *>i  10.30.2.0/24     10.20.0.2                0    100      0 i
 * i  10.50.1.0/24     10.20.0.2                0    100      0 300 i
 *>                    10.30.1.2                0             0 300 i
 *>   10.50.2.0/24     10.30.1.2                              0 300 i
 * i                   10.20.0.2                0    100      0 300 i
 r i  10.60.1.0/24     10.20.0.2                0    100      0 500 i
 r>                    10.60.1.1                0             0 500 i
 * i  10.60.2.0/24     10.20.0.2                0    100      0 500 i
 *>                    10.60.1.1                0             0 500 i

結果の確認

上記の設定後、RT7のshow ip bgpを確認すると、フィルタリングされた経路情報を受信できていないことが確認できます。AS_PATH ACLも通常のACL同様に、最終行に暗黙のdenyがかかりますので、permitした経路以外は全て破棄しています。

RT7
RT7#sh ip bgp
BGP table version is 19, local router ID is 10.60.2.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *    10.2.0.0/24      10.60.2.2               20             0 200 300 400 i
 *>                    10.60.1.2               10             0 200 300 400 i
 *>   10.3.0.0/24      0.0.0.0                  0         32768 i
 *    10.30.1.0/24     10.60.2.2                              0 200 i
 *>                    10.60.1.2                0             0 200 i
 *    10.30.2.0/24     10.60.2.2                0             0 200 i
 *>                    10.60.1.2                              0 200 i
 *    10.50.1.0/24     10.60.2.2                              0 200 300 i
 *>                    10.60.1.2                              0 200 300 i
 *    10.50.2.0/24     10.60.2.2                              0 200 300 i
 *>                    10.60.1.2                              0 200 300 i
 *>   10.60.1.0/24     0.0.0.0                  0         32768 i
 *>   10.60.2.0/24     0.0.0.0                  0         32768 i

これでRT7とRT1はお互いの経路情報を失い、通信できなくなりました。フィルタリングで許可されているRT2までの経路はこれまで通り受信できているため、PC1とPC2、PC3とPC2は通信することができます。

RT7
RT7#ping 10.1.0.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.0.1, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
RT7#ping 10.2.0.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.0.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/3 ms
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1