【BGP入門】BGP Communityの基本

  • URLをコピーしました!
目次

はじめに

こんにちは。ネットワークエンジニアの「だいまる」です。

今回もBGPシリーズとして、経路制御に利用されるCommunity(コミュニティ)についてまとめていきたいと思います。

Communityとは?

概要

BGP Communityとは、「経路に対する色付けやタグ付けを意味し、特定の経路のみ広報する場合や受信する場合、Attributeを付与・変更したい場合の条件として使われることが多い」です。

一般的にCommunity値は「XXXX:YYYY」の形式で付与されることが多く、「XXXX」はAS番号「YYYY」を特定の経路を示す番号にします。

(イメージ図)

また、このCommunity値にはWell-Knownと呼ばれる4つの値もあります。

NoCommunity名詳細
1Internet0デフォルトのCommunity(色付けなし)
2no-export0xFFFFFF01eBGPネイバーに対し経路広報しない
3no-advertise0xFFFFFF02iBGP/eBGPネイバーに対し経路広報しない
4local-as0xFFFFFF03異なるサブASに広報しない

(No2〜4のイメージ図)

Segment Routing for Service Provider and Enterprise Networks
Segment Routing for Service Provider and Enterprise Networks
Ciscoが発刊したサービスプロバイダ向けの
セグメントルーティングに関する参考書

設定方法(Cisco IOS)

基本設定

Cisco IOSでは、送信側も受信側も「send-community」は必須となります。

必須となる基本設定
(config)# router bgp <AS番号>
(config-router)# neighbor <IPアドレス> send-community

XXXX:YYYYのフォーマットを利用するためには、以下の設定も必要になります。

XXXX:YYYYフォーマットで必要な設定
(config)# ip bgp-community new-format

機器やOSによって必要な設定は異なります!

Well-Known Community/Community設定

以下の設定で標準となっている「Well-Known Community」や「Community」を設定できます。

設定方法
(config)#route-map <ルートマップ名> permit 10
(config-route-map)#set community <設定するコミュニティ>
(config)#router bgp <AS番号>
(config-router)#neighbor <ネイバーアドレス> route-map <ルートマップ名> out

### <設定するコミュニティ>のオプション ###
  <1-4294967295>  community number
  aa:nn           community number in aa:nn format
  gshut           Graceful Shutdown (well-known community)
  internet        Internet (well-known community)
  local-AS        Do not send outside local AS (well-known community)
  no-advertise    Do not advertise to any peer (well-known community)
  no-export       Do not export to next AS (well-known community)
  none            No community attribute
3分間ネットワーク基礎講座
〜大好評「3分間ネットワーク基礎講座」が、内容を刷新して新登場〜

動作確認(Cisco IOS)

早速実機による動作確認を行っていきます。

検証環境

今回の検証環境も他の記事同様の構成を利用します。

AS100
AS100
AS200
AS200
ルータ1
ルータ1
ルータ2
ルータ2
ルータ3
ルータ3
ルータ4
ルータ4
ルータ5
ルータ5
ルータ6
ルータ6
ルータ7
ルータ7
192.168.1.0/30
192.168…
192.168.2.0/30
192.168…
10.1.0.0/30
10.1.0….
10.2.0.0/30
10.2.0….
10.2.1.0/30
10.2.1….
10.2.2.0/30
10.2.2….
10.1.1.0/30
10.1.1….
10.1.2.0/30
10.1.2….
10.1.3.0/30
10.1.3….
Lo0:10.10.X.1/32
Lo0:10….
Lo0:10.20.X.1/32
Lo0:10….
AS300
AS300
ルータ8
ルータ8
192.168.3.0/30
192.168…
192.168.4.0/30
192.168…
AS400
AS400
192.168.5.0/30
192.168…
192.168.6.0/30
192.168…
Lo0:10.30.X.1/32
Lo0:10.30.X.1/32
Lo0:10.40.X.1/32
Lo0:10….
ルータ9
ルータ9
Text is not SVG – cannot display

基本設定

基本設定は、外接しているルータに全台投入してみました。(iBGP向けへの投入はなし、事前・事後確認なし)

ルータ2で投入したConfig
Router2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router2(config)#ip bgp-community new-format
Router2(config)#router bgp 100
Router2(config-router)#neighbor 192.168.2.2 send-community
Router2(config-router)#neighbor 192.168.3.2 send-community
Router2(config-router)#end

Well-Known Community

ルータ2からルータ8に「NO-EXPORT」を設定してみましょう。

事前確認では、192.168.3.1をNext-Hopとした経路が存在しています。

事前確認(ルータ6)
Router6#show ip bgp
BGP table version is 21, local router ID is 10.20.6.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,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   0.0.0.0          192.168.4.2                            0 300 100 ?
 *>i  10.10.1.1/32     10.20.5.1                0    100      0 400 400 100 i
 *>   10.10.2.1/32     192.168.4.2                            0 300 100 i
 *    10.10.3.1/32     192.168.4.2                            0 300 100 i
 * i                   10.20.5.1                0    100      0 100 i
 *>                    192.168.2.1                            0 100 i
 *    10.10.4.1/32     192.168.4.2                            0 300 100 i
 *>                    192.168.2.1                            0 100 i
 * i                   10.20.5.1                0    100      0 100 i
 *>   10.20.0.0/16     192.168.4.2                            0 300 100 i
 r>i  10.20.5.1/32     10.20.5.1                0    100      0 i
 *>   10.20.6.1/32     0.0.0.0                  0         32768 i
 r>i  10.20.7.1/32     10.20.7.1                0    100      0 i
 *>   10.30.8.1/32     192.168.4.2              0             0 300 i
 *>i  10.40.9.1/32     10.20.5.1                0    100      0 400 400 i
 *>i  10.40.19.1/32    10.20.5.1                0    100      0 400 400 i

まずは、ルータ2にRoute-mapの設定を行い、その後に192.168.3.2向けのNeighborに設定します。

設定(ルータ2)
Router2(config)#route-map NO-EXPORT permit 10
Router2(config-route-map)#set community no-export
Router2(config)#router bgp 100
Router2(config-router)#neighbor 192.168.3.2 route-map NO-EXPORT out
Router2(config-router)#end

ルータ2での設定後、ルータ6でどうなっているか確認してみましょう。

事後確認(ルータ6)
Router6#show ip bgp
BGP table version is 25, local router ID is 10.20.6.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,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>i  0.0.0.0          10.20.5.1                0    100      0 400 400 100 ?
 *>i  10.10.1.1/32     10.20.5.1                0    100      0 400 400 100 i
 * i  10.10.3.1/32     10.20.5.1                0    100      0 100 i
 *>                    192.168.2.1                            0 100 i
 *>   10.10.4.1/32     192.168.2.1                            0 100 i
 * i                   10.20.5.1                0    100      0 100 i
 r>i  10.20.5.1/32     10.20.5.1                0    100      0 i
 *>   10.20.6.1/32     0.0.0.0                  0         32768 i
 r>i  10.20.7.1/32     10.20.7.1                0    100      0 i
 *>   10.30.8.1/32     192.168.4.2              0             0 300 i
 *>i  10.40.9.1/32     10.20.5.1                0    100      0 400 400 i
 *>i  10.40.19.1/32    10.20.5.1                0    100      0 400 400 i

ここからわかる通り、「AS300 100」となっている経路が消えたことがわかり、想定通りの動作をしていることがわかります。

ルータ8で確認してみるとしっかりCommunityに「no-export」がついてることがわかります。

状態確認(ルータ8)
Router8#show ip bgp 10.10.4.1
BGP routing table entry for 10.10.4.1/32, version 34
Paths: (2 available, best #1, table default, not advertised to EBGP peer)
  Not advertised to any peer
  Refresh Epoch 1
  100
    192.168.3.1 from 192.168.3.1 (10.10.2.1)
      Origin IGP, localpref 100, valid, external, best
      Community: no-export
      rx pathid: 0, tx pathid: 0x0
  Refresh Epoch 1
  200 100
    192.168.4.1 from 192.168.4.1 (10.20.6.1)
      Origin IGP, localpref 100, valid, external
      rx pathid: 0, tx pathid: 0

任意のCommunity値

ルータ2上で任意のCommunity値を付与し、ルータ6に付与してみます。

事前確認(ルータ6)
Router6#show ip bgp 10.10.4.1
BGP routing table entry for 10.10.4.1/32, version 12
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     1          2
  Refresh Epoch 1
  100
    192.168.2.1 from 192.168.2.1 (10.10.2.1)
      Origin IGP, localpref 100, valid, external, best
      rx pathid: 0, tx pathid: 0x0
  Refresh Epoch 1
  100
    10.20.5.1 (metric 2) from 10.20.5.1 (10.20.5.1)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0

ここでルータ2でCommunity「100:1000」をつけてみたいと思います。

設定(ルータ2)
Router2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router2(config)#route-map Community-Test permit 10
Router2(config-route-map)#set community 100:1000
Router2(config-route-map)#match ip address prefix-list Loopback
Router2(config)#router bgp 100
Router2(config-router)#no neighbor 192.168.2.2 prefix-list Loopback out
Router2(config-router)#neighbor 192.168.2.2 route-map Community-Test out
Router2(config-router)#end

この設定後のルータ6での事後状態を確認してみましょう。

事後確認(ルータ6)
Router6#show ip bgp 10.10.4.1
BGP routing table entry for 10.10.4.1/32, version 26
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     1          2
  Refresh Epoch 1
  100
    192.168.2.1 from 192.168.2.1 (10.10.2.1)
      Origin IGP, localpref 100, valid, external, best
      Community: 100:1000
      rx pathid: 0, tx pathid: 0x0
  Refresh Epoch 1
  100
    10.20.5.1 (metric 2) from 10.20.5.1 (10.20.5.1)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0

Community値に「100:1000」がついてることがわかります。

しっかり動作していますね。

マルチクラウドネットワークの教科書 耐障害性と冗長性を実現するデザインパターン
〜この1冊でマルチクラウドジャーニーを突き進め!〜

最後に

今回は、BGPを一歩踏み込んだCommunityについてまとめてみました。

今後も少しずつ理解を深められる記事を投稿していきたいと思うので、ご参照ください。

関連記事

  • URLをコピーしました!
目次