【BGP】コミュニティの概要と設定

 BGPコミュニティはプレフィックスに付与される付加情報です。複数のプレフィックスに対して何らか同一の処理をする場合に、プレフィックスをグループ化するのに、コミュニティを使用します。

コミュニティは、2バイト:2バイトの表記で、前半の2バイトはAS番号、後半は自由に採番するのが一般的です。

 以下の構成を考えます。

 R1上の各プレフィックスそれぞれにコミュニティ値を付与して、R2に広告します。R2は、コミュニティ値に応じて、AS番号をプリペンドして、AS3へ広告するとします。

プレフィックス     コミュニティ値  
(R1で付与)
R2で実施する処理
1.1.1.1/321:1AS 1をプリペンド
11.11.11.11/321:11AS 1 と AS 11をプリペンド
111.111.111.111/321:111AS 1 と AS 11とAS 111をプリペンド
スポンサーリンク

BGPの基本設定

 まず、BGPの基本設定(AS番号、ネイバー、広告プレフィックス)をします。

R1(config)# interface Loopback0 
R1(config-if)#  ip address 1.1.1.1 255.255.255.255 
R1(config)# interface Loopback11 
R1(config-if)#  ip address 11.11.11.11 255.255.255.255 
R1(config)# interface Loopback111 
R1(config-if)#  ip address 111.111.111.111 255.255.255.255 

R1(config)#router bgp 1
R1(config-router)# network 1.1.1.1 mask 255.255.255.255
R1(config-router)# network 11.11.11.11 mask 255.255.255.255
R1(config-router)# network 111.111.111.111 mask 255.255.255.255
R1(config-router)# neighbor 192.168.12.2 remote-as 2
R2(config)#router bgp 2
R2(config-router)# neighbor 192.168.12.1 remote-as 1
R2(config-router)# neighbor 192.168.23.3 remote-as 3
R3(config)#router bgp 3
R3(config-router)# neighbor 192.168.23.2 remote-as 2

 設定が完了すると、ネイバーがアップします。

スポンサーリンク

R1の設定

 R1では、各プレフィックスにコミュニティを付与して、R2へ広告します。まず、各プレフィックスをプレフィックスリストで定義します。

R1(config)# ip prefix-list LOOPBACK_1 seq 5 permit 1.1.1.1/32
R1(config)# ip prefix-list LOOPBACK_11 seq 5 permit 11.11.11.11/32
R1(config)# ip prefix-list LOOPBACK_111 seq 5 permit 111.111.111.111/32

 次にroute-mapコマンドで、上で設定したプレフィックスリストに対して、コミュニティをset communityコマンドで付与します。

コミュニティを2バイト:2バイト表記にするには、ip bgp-community new-format が必要です。

R1(config)# ip bgp-community new-format
R1(config)# route-map SET-COMMUNITY permit 1
R1(config-route-map)#  match ip address prefix-list LOOPBACK_1
R1(config-route-map)#  set community 1:1
R1(config-route-map)#!
R1(config-route-map)# route-map SET-COMMUNITY permit 11
R1(config-route-map)#  match ip address prefix-list LOOPBACK_11
R1(config-route-map)#  set community 1:11
R1(config-route-map)#!
R1(config-route-map)# route-map SET-COMMUNITY permit 111
R1(config-route-map)#  match ip address prefix-list LOOPBACK_111
R1(config-route-map)#  set community 1:111
R1(config-route-map)#!         
R1(config-route-map)# route-map SET-COMMUNITY permit 1000

ルートマップでは、最後に暗黙のdenyがあるため、最後にシーケンス番号1000として何も処理しないルートマップを設定しています。 これにより、プレフィックスリストに一致しないプレフィックスは、何も処理されず、他のネイバーに広告することができます。

 では、上のルートマップをネイバーR2の出力側に適用します。

コミュニティ値を広告するには、ネイバー設定でsend-communityコマンドの追加も必要です。

R1(config)#router bgp 1
R1(config-router)# neighbor 192.168.12.2 send-community
R1(config-router)# neighbor 192.168.12.2 route-map SET-COMMUNITY out
スポンサーリンク

R2の設定

 R2では、受信したプレフィックスのコミュニティ値に応じて、プレフィックスへの処理を設定します。 コミュニティを2バイト:2バイト表記にするには、ip bgp-community new-format が必要です。

コミュニティ値を定義するため、ip community-listコマンドを使用します。

R2(config)#ip bgp-community new-format
R2(config)#ip community-list 1 permit 1:1
R2(config)#ip community-list 11 permit 1:11
R2(config)#ip community-list 111 permit 1:111

 次にroute-mapコマンドで、上で設定したコミュニティリストに対して、実行する処理(今回は、ASプリペンド)を設定します。

R2(config)#route-map AS-PREPEND-COMMUNITY permit 1
R2(config-route-map)# match community 1
R2(config-route-map)# set as-path prepend 1
R2(config-route-map)#!
R2(config-route-map)#route-map AS-PREPEND-COMMUNITY permit 11
R2(config-route-map)# match community 11
R2(config-route-map)# set as-path prepend 1 11
R2(config-route-map)#!
R2(config-route-map)#route-map AS-PREPEND-COMMUNITY permit 111
R2(config-route-map)# match community 111
R2(config-route-map)# set as-path prepend 1 11 111
R2(config-route-map)#!
R2(config-route-map)#route-map AS-PREPEND-COMMUNITY permit 1000
R2(config-route-map)#!

 上のルートマップをネイバーR3の出力側に適用します。

R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.23.3 route-map AS-PREPEND-COMMUNITY out

 R2でBGPプロセスを再起動し、ポリシーを反映させます。

R2#clear ip bgp *
R2#
%BGP-5-ADJCHANGE: neighbor 192.168.12.1 Down User reset
%BGP_SESSION-5-ADJCHANGE: neighbor 192.168.12.1 IPv4 Unicast topology
 base removed from session  User reset
%BGP-5-ADJCHANGE: neighbor 192.168.23.3 Down User reset
%BGP_SESSION-5-ADJCHANGE: neighbor 192.168.23.3 IPv4 Unicast topology
 base removed from session  User reset

%BGP-5-ADJCHANGE: neighbor 192.168.12.1 Up 
%BGP-5-ADJCHANGE: neighbor 192.168.23.3 Up 
R2#
スポンサーリンク

確認

 R2で受信したプレフィックスのコミュニティ値を確認します。

R2#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 2
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     11        
  Refresh Epoch 1
  1
    192.168.12.1 from 192.168.12.1 (111.111.111.111)
      Origin IGP, metric 0, localpref 100, valid, external, best
      Community: 1:1


R2#show ip bgp 11.11.11.11
BGP routing table entry for 11.11.11.11/32, version 3
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     11        
  Refresh Epoch 1
  1
    192.168.12.1 from 192.168.12.1 (111.111.111.111)
      Origin IGP, metric 0, localpref 100, valid, external, best
      Community: 1:11

R2#show ip bgp 111.111.111.111 
BGP routing table entry for 111.111.111.111/32, version 4
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     11        
  Refresh Epoch 1
  1
    192.168.12.1 from 192.168.12.1 (111.111.111.111)
      Origin IGP, metric 0, localpref 100, valid, external, best
      Community: 1:111

 プレフィックスに対応したコミュニティ値が付属しています。R2は、コミュニティ値に応じて、ASプリペンドを実行し、R3へ広告します。

 R3のBGPテーブルを確認します。

R3#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 30
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  2 1 1
    192.168.23.2 from 192.168.23.2 (2.2.2.2)
      Origin IGP, localpref 100, valid, external, best

R3#show ip bgp 11.11.11.11
BGP routing table entry for 11.11.11.11/32, version 31
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  2 1 11 1
    192.168.23.2 from 192.168.23.2 (2.2.2.2)
      Origin IGP, localpref 100, valid, external, best

R3#show ip bgp 111.111.111.111
BGP routing table entry for 111.111.111.111/32, version 32
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  2 1 11 111 1
    192.168.23.2 from 192.168.23.2 (2.2.2.2)
      Origin IGP, localpref 100, valid, external, best

プレフィックスに意図どおりASプリテンドされていることが確認できました。

 では、R1で、コミュニティを付与しないプレフィックス(222.222.222.222/32)を広告します。

R1(config)#interface loopback 222
R1(config-if)#ip address 222.222.222.222 255.255.255.255

R1(config)#router bgp 1
R1(config-router)#network 222.222.222.222 mask 255.255.255.255

 では、R2のBGPテーブルで222.222.222.222を確認すると、コミュニティが付与されていないことがわかります。

R2#show ip bgp 222.222.222.222
BGP routing table entry for 222.222.222.222/32, version 5
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     11        
  Refresh Epoch 1
  1
    192.168.12.1 from 192.168.12.1 (111.111.111.111)
      Origin IGP, metric 0, localpref 100, valid, external, best

 コミュニティを付与していないプレフィックスは、ルートマップのシーケンス1000番が適用され、何も処理せずに、R3へ広告されます。
R3のBGPテーブルを確認すると、ASプリペンドされていないことが確認できます。

R3#show ip bgp 222.222.222.222
BGP routing table entry for 222.222.222.222/32, version 33
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  2 1
    192.168.23.2 from 192.168.23.2 (2.2.2.2)
      Origin IGP, localpref 100, valid, external, best

その他 BGP関連記事は   >>  ルーティングプロトコル(BGP)まとめ << より参照できます。

コメント