例:BGP階層の異なるレベルでのルーティングポリシーの適用
この例では、シンプルなネットワークトポロジーで設定されたBGPを紹介し、ルーティングポリシーがBGP設定の異なるレベルで適用された時にどのような効果があるかを説明します。
要件
この例を設定する前に、デバイス初期化以外の特別な設定を行う必要はありません。
概要
BGPでは、以下のようなポリシーを適用できます。
-
BGPグローバルの
importおよびexportステートメント-これらのステートメントを[edit protocols bgp]階層レベルに含める(ルーティングインスタンスの場合は、これらのステートメントを[edit routing-instances routing-instance-name protocols bgp]階層レベルに含める)。 -
グループの
importおよびexportステートメント-これらのステートメントを[edit protocols bgp group group-name]階層レベルに含める(ルーティングインスタンスの場合は、これらのステートメントを[edit routing-instances routing-instance-name protocols bgp group group-name]階層レベルに含める)。 -
ピアの
importおよびexportステートメント-これらのステートメントを[edit protocols bgp group group-name neighbor address]階層レベルに含める(ルーティングインスタンスの場合は、これらのステートメントを[edit routing-instances routing-instance-name protocols bgp group group-name neighbor address]階層レベルに含める)。 -
ファミリの
importおよびexportステートメント-これらのステートメントを[edit protocols bgp family nlri]階層レベルに含める(ルーティングインスタンスの場合は、これらのステートメントを[edit routing-instances routing-instance-name protocols bgp family nlri]階層レベルに含める)。
ピアレベルのimportまたはexportステートメントは、グループのimportまたはexportステートメントを上書きします。グループレベルimportまたはexportステートメントは、グローバルBGPのimportまたはexportステートメントを上書きします。
この例では、send-directという名のポリシーがグローバルレベルで適用され、send-192.168.0.1という名の別のポリシーがグループレベルで適用されており、send-192.168.20.1という名の3つ目のポリシーがネイバーレベルで適用されています。
user@host# show protocols
bgp {
local-address 172.16.1.1;
export send-direct;
group internal-peers {
type internal;
export send-192.168.0.1;
neighbor 172.16.2.2 {
export send-192.168.20.1;
}
neighbor 172.16.3.3;
}
group other-group {
type internal;
neighbor 172.16.4.4;
}
}
これは、重要なポイントであり、しばしば誤解され問題が生じる原因となっていますが、このような構成では、最も明示的なポリシーのみが適用されます。ネイバーレベルのポリシーは、グループレベルのポリシーよりも明示的であり、さらにグループレベルのポリシーは、グローバルポリシーよりも明示的です。
ネイバー172.16.2.2には、send-192.168.20.1ポリシーのみが適用されます。ネイバー172.16.3.3にはより具体的なものがないため、send-192.168.0.1ポリシー適用のみがされます。一方で、other-groupのグループにあるネイバー172.16.4.4には、グループまたはネイバーレベルのポリシーがないため、send-directポリシーを使用します。
ネイバー172.16.2.2で3つのポリシーすべての機能を実行させる必要がある場合は、他の3つの機能が含まれる新しいネイバーレベルのポリシーを記述して適用するか、既存の3つのポリシーすべてをチェーンとして、ネイバー172.16.2.2に適用することができます。
トポロジー
図 1は、サンプルネットワークを示しています。

CLIクイック構成は、図 1にあるすべてのデバイスの構成を示しています。
セクション#configuration__policy-bgp-apply-levels-stは、デバイスR1の手順を説明しています。
設定
CLIクイック構成
この例をすばやく設定するには、次のコマンドをコピーしてテキストファイルに貼り付け、改行を削除して、ネットワーク構成に合わせて必要な詳細を変更し、[edit]階層レベルのCLIにコマンドをコピー&ペーストしてください。
デバイスR1
set interfaces fe-1/2/0 unit 0 description to-R2 set interfaces fe-1/2/0 unit 0 family inet address 10.10.10.1/30 set interfaces lo0 unit 0 family inet address 172.16.1.1/32 set protocols bgp local-address 172.16.1.1 set protocols bgp export send-direct set protocols bgp group internal-peers type internal set protocols bgp group internal-peers export send-static-192.168.0 set protocols bgp group internal-peers neighbor 172.16.2.2 export send-static-192.168.20 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols bgp group other-group type internal set protocols bgp group other-group neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set policy-options policy-statement send-static-192.168.0 term 1 from protocol static set policy-options policy-statement send-static-192.168.0 term 1 from route-filter 192.168.0.0/24 orlonger set policy-options policy-statement send-static-192.168.0 term 1 then accept set policy-options policy-statement send-static-192.168.20 term 1 from protocol static set policy-options policy-statement send-static-192.168.20 term 1 from route-filter 192.168.20.0/24 orlonger set policy-options policy-statement send-static-192.168.20 term 1 then accept set routing-options static route 192.168.0.1/32 discard set routing-options static route 192.168.20.1/32 discard set routing-options router-id 172.16.1.1 set routing-options autonomous-system 17
デバイスR2
set interfaces fe-1/2/0 unit 0 description to-R1 set interfaces fe-1/2/0 unit 0 family inet address 10.10.10.2/30 set interfaces fe-1/2/1 unit 0 description to-R3 set interfaces fe-1/2/1 unit 0 family inet address 10.10.10.5/30 set interfaces lo0 unit 0 family inet address 172.16.2.2/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set routing-options router-id 172.16.2.2 set routing-options autonomous-system 17
デバイスR3
set interfaces fe-1/2/1 unit 0 description to-R2 set interfaces fe-1/2/1 unit 0 family inet address 10.10.10.6/30 set interfaces fe-1/2/2 unit 0 description to-R4 set interfaces fe-1/2/2 unit 0 family inet address 10.10.10.9/30 set interfaces lo0 unit 0 family inet address 172.16.3.3/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.3.3 set protocols bgp group internal-peers neighbor 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 set routing-options router-id 172.16.3.3 set routing-options autonomous-system 17
デバイスR4
set interfaces fe-1/2/2 unit 0 description to-R3 set interfaces fe-1/2/2 unit 0 family inet address 10.10.10.10/30 set interfaces lo0 unit 0 family inet address 172.16.4.4/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.4.4 set protocols bgp group internal-peers neighbor 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 set routing-options router-id 172.16.4.4 set routing-options autonomous-system 17
手順
ステップバイステップでの手順
次の例では、構成設定階層の複数のレベルに移動する必要があります。CLIのナビゲーションについては、『CLIユーザーガイド』の「コンフィギュレーションモードでのCLIエディタの使用」を参照してください。
IS-ISデフォルトのルートポリシーを設定します。
デバイスインターフェイスを設定します。
[edit interfaces] user@R1# set fe-1/2/0 unit 0 description to-R2 user@R1# set fe-1/2/0 unit 0 family inet address 10.10.10.1/30 user@R1# set lo0 unit 0 family inet address 172.16.1.1/32
インターフェイス上で、OSPFまたは別の内部ゲートウェイプロトコル(IGP)を有効にします。
[edit protocols OSPF area 0.0.0.0] user@R1# set interface lo0.0 passive user@R1# set interface fe-1/2/0.0
スタティックルートを設定します。
[edit routing-options] user@R1# set static route 192.168.0.1/32 discard user@R1# set static route 192.168.20.1/32 discard
ルーティングポリシーを有効にします。
[edit protocols policy-options] user@R1# set policy-statement send-direct term 1 from protocol direct user@R1# set policy-statement send-direct term 1 then accept user@R1# set policy-statement send-static-192.168.0 term 1 from protocol static user@R1# set policy-statement send-static-192.168.0 term 1 from route-filter 192.168.0.0/24 orlonger user@R1# set policy-statement send-static-192.168.0 term 1 then accept user@R1# set policy-statement send-static-192.168.20 term 1 from protocol static user@R1# set policy-statement send-static-192.168.20 term 1 from route-filter 192.168.20.0/24 orlonger user@R1# set policy-statement send-static-192.168.20 term 1 then accept
BGPを設定し、エクスポートポリシーを適用します。
[edit protocols bgp] user@R1# set local-address 172.16.1.1 user@R1# set protocols bgp export send-direct user@R1# set group internal-peers type internal user@R1# set group internal-peers export send-static-192.168.0 user@R1# set group internal-peers neighbor 172.16.2.2 export send-static-192.168.20 user@R1# set group internal-peers neighbor 172.16.3.3 user@R1# set group other-group type internal user@R1# set group other-group neighbor 172.16.4.4
ルーターIDとAS(自律システム)番号を設定します。
[edit routing-options] user@R1# set router-id 172.16.1.1 user@R1# set autonomous-system 17
デバイスの設定が完了したら、設定をコミットします。
[edit] user@R1# commit
結果
設定モードから、show interfaces、show protocols、show policy-options、およびshow routing-optionsコマンドを発行して設定を確認します。出力結果に意図した設定内容が表示されない場合は、この例の手順を繰り返して設定を修正します。
user@R1# show interfaces
fe-1/2/0 {
unit 0 {
description to-R2;
family inet {
address 10.10.10.1/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 172.16.1.1/32;
}
}
}
user@R1# show protocols
bgp {
local-address 172.16.1.1;
export send-direct;
group internal-peers {
type internal;
export send-static-192.168.0;
neighbor 172.16.2.2 {
export send-static-192.168.20;
}
neighbor 172.16.3.3;
}
group other-group {
type internal;
neighbor 172.16.4.4;
}
}
ospf {
area 0.0.0.0 {
interface lo0.0 {
passive;
}
interface fe-1/2/0.0;
}
}
user@R1# show policy-options
policy-statement send-direct {
term 1 {
from protocol direct;
then accept;
}
}
policy-statement send-static-192.168.0 {
term 1 {
from {
protocol static;
route-filter 192.168.0.0/24 orlonger;
}
then accept;
}
}
policy-statement send-static-192.168.20 {
term 1 {
from {
protocol static;
route-filter 192.168.20.0/24 orlonger;
}
then accept;
}
}
user@R1# show routing-options
static {
route 192.168.0.1/32 discard;
route 192.168.20.1/32 discard;
}
router-id 172.16.1.1;
autonomous-system 17;
検証
設定が正常に機能していることを確認します。
BGPルート学習の検証
目的
ルーティングテーブルを確認して、BGPエクスポートポリシーが期待通りに機能していることを確認します。
アクション
user@R1> show route protocol direct
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.1/32 *[Direct/0] 1d 22:19:47
> via lo0.0
10.10.10.0/30 *[Direct/0] 1d 22:19:47
> via fe-1/2/0.0
user@R1> show route protocol static
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.1/32 *[Static/5] 02:20:03
Discard
192.168.20.1/32 *[Static/5] 02:20:03
Discarduser@R2> show route protocol bgp
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.20.1/32 *[BGP/170] 02:02:40, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.1 via fe-1/2/0.0user@R3> show route protocol bgp
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.1/32 *[BGP/170] 02:02:51, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.5 via fe-1/2/1.0user@R4> show route protocol bgp
inet.0: 9 destinations, 11 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.1/32 [BGP/170] 1d 20:38:54, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.9 via fe-1/2/2.0
10.10.10.0/30 [BGP/170] 1d 20:38:54, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.9 via fe-1/2/2.0説明
デバイスR1は、show route protocol directコマンドに2つのダイレクトルートを表示します:172.16.1.1/32および10.10.10.0/30。show route protocol staticコマンドは、2つのスタティックルートを表示します:192.168.0.1/32および192.168.20.1/32。
デバイスR2では、show route protocol bgpコマンドによって、デバイスR2がBGPで学習した唯一のルートが192.168.20.1/32ルートであることが示されています。
デバイスR3では、show route protocol bgpコマンドによって、デバイスR3がBGPで学習した唯一のルートが192.168.0.1/32ルートであることが示されています。
デバイスR4では、show route protocol bgpコマンドによって、デバイスR4がBGPで学習したルートは172.16.1.1/32および10.10.10.0/30ルートのみであることが示されています。
BGPルート受信の検証
目的
デバイスR1から受信したBGPルートをチェックし、BGPのエクスポートポリシーが期待通りに機能していることを確認します。
アクション
user@R2> show route receive-protocol bgp 172.16.1.1 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 192.168.20.1/32 172.16.1.1 100 I
user@R3> show route receive-protocol bgp 172.16.1.1 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 192.168.0.1/32 172.16.1.1 100 I
user@R4> show route receive-protocol bgp 172.16.1.1 inet.0: 9 destinations, 11 routes (9 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path 172.16.1.1/32 172.16.1.1 100 I 10.10.10.0/30 172.16.1.1 100 I
説明
デバイスR2では、route receive-protocol bgp 172.16.1.1コマンドによって、デバイスR2はデバイスR1から1つのBGPルート192.168.20.1/32のみを受け取っていることが示されています。
デバイスR3では、route receive-protocol bgp 172.16.1.1コマンドによって、デバイスR3がデバイスR1から1つのBGPルート192.168.0.1/32のみを受け取っていることが示されています。
デバイスR4では、route receive-protocol bgp 172.16.1.1コマンドによって、デバイスR4がデバイスR1から2つのBGPルート172.16.1.1/32および10.10.10.0/30を受け取っていることが示されています。
要約すると、BGPの異なるCLI階層に複数のポリシーが適用される場合、最も具体的なアプリケーションのみが評価され、より具体性に欠ける他のアプリケーションは除外されます。このポイントは理にかなっているように見えますが、ルーターの設定時には忘れられがちです。ネイバーレベルのポリシーがグローバルポリシーまたはグループレベルのポリシーと組み合わされていると勘違いして、ポリシーの動作が予想と異なるのに気づくのです。