はじめに
こんにちは。ネットワークエンジニアの「だいまる」です。
今回もBGPシリーズとして、経路制御に利用されるCommunity(コミュニティ)についてまとめていきたいと思います。
Communityとは?
概要
BGP Communityとは、「経路に対する色付けやタグ付けを意味し、特定の経路のみ広報する場合や受信する場合、Attributeを付与・変更したい場合の条件として使われることが多い」です。
一般的にCommunity値は「XXXX:YYYY」の形式で付与されることが多く、「XXXX」はAS番号、「YYYY」を特定の経路を示す番号にします。
(イメージ図)
また、このCommunity値にはWell-Knownと呼ばれる4つの値もあります。
| No | Community名 | 値 | 詳細 |
|---|---|---|---|
| 1 | Internet | 0 | デフォルトのCommunity(色付けなし) |
| 2 | no-export | 0xFFFFFF01 | eBGPネイバーに対し経路広報しない |
| 3 | no-advertise | 0xFFFFFF02 | iBGP/eBGPネイバーに対し経路広報しない |
| 4 | local-as | 0xFFFFFF03 | 異なるサブASに広報しない |
(No2〜4のイメージ図)
設定方法(Cisco IOS)
基本設定
Cisco IOSでは、送信側も受信側も「send-community」は必須となります。
(config)# router bgp <AS番号>
(config-router)# neighbor <IPアドレス> send-community
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
動作確認(Cisco IOS)
早速実機による動作確認を行っていきます。
検証環境
今回の検証環境も他の記事同様の構成を利用します。
基本設定
基本設定は、外接しているルータに全台投入してみました。(iBGP向けへの投入はなし、事前・事後確認なし)
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とした経路が存在しています。
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に設定します。
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でどうなっているか確認してみましょう。
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」がついてることがわかります。
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に付与してみます。
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」をつけてみたいと思います。
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での事後状態を確認してみましょう。
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」がついてることがわかります。
しっかり動作していますね。
最後に
今回は、BGPを一歩踏み込んだCommunityについてまとめてみました。
今後も少しずつ理解を深められる記事を投稿していきたいと思うので、ご参照ください。


