サービスの改善にご協力お願いします。

お客様のご意見をお聞かせください。

アンケートの所要時間はおよそ 2 分です。

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
list Table of Contents
このページで
keyboard_arrow_right

この機械翻訳はお役に立ちましたでしょうか?

starstarstarstarstar
Go to English page
免責事項:

このページは、サードパーティー製機械翻訳ソフトウェアを使用して翻訳されます。質の高い翻訳を提供するために合理的な対応はされていますが、ジュニパーネットワークスがその正確性を保証することはできかねます。この翻訳に含まれる情報の正確性について疑問が生じた場合は、英語版を参照してください. ダウンロード可能なPDF (英語版のみ).

例:BGPコミュニティ数に基づくルーティングポリシーの設定

date_range 19-Jan-25

この例では、BGPコミュニティの数に基づいてBGPルートを受け入れるポリシーを作成する方法を示します。

要件

この例を構成する前に、デバイスの初期化以上の特別な構成は必要ありません。

概要

この例では、外部BGP(EBGP)接続を持つ2つのルーティングデバイスを示しています。デバイスR2は、BGPセッションを使用して、デバイスR1に2つのスタティックルートを送信します。デバイスR1では、インポートポリシーにより、BGPで受信したルートに一致と見なされるコミュニティを最大5つ含めることができると指定されています。たとえば、ルートに3つのコミュニティが含まれている場合、一致と見なされて受け入れられます。ルートに6つ以上のコミュニティが含まれている場合、不一致と見なされ、拒否されます。

EBGPのデフォルトポリシーは、すべてのルートを受け入れるということを覚えておくことが重要です。一致しないルートが拒否されるようにするには、ポリシー定義の最後に then reject アクションを含める必要があります。

トポロジー

図 1は、サンプルのネットワークを示しています。

図 1: 受け入れるコミュニティの数に制限を設けたBGPポリシー受け入れるコミュニティの数に制限を設けたBGPポリシー

設定

CLIクイック構成

この例をすばやく設定するには、次のコマンドをコピーしてテキストファイルに貼り付け、改行を削除して、ネットワーク構成に合わせて必要な詳細を変更し、[edit]階層レベルのCLIにコマンドをコピー&ペーストしてください。

デバイスR1

content_copy zoom_out_map
set interfaces fe-1/1/0 unit 0 description to-R2
set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.1/30
set interfaces lo0 unit 0 family inet address 192.168.0.1/32
set protocols bgp group external-peers type external
set protocols bgp group external-peers peer-as 2
set protocols bgp group external-peers neighbor 10.0.0.2 import import-communities
set policy-options policy-statement import-communities term 1 from protocol bgp
set policy-options policy-statement import-communities term 1 from community-count 5 orlower
set policy-options policy-statement import-communities term 1 then accept
set policy-options policy-statement import-communities term 2 then reject
set routing-options router-id 192.168.0.1
set routing-options autonomous-system 1

デバイスR2

content_copy zoom_out_map
set interfaces fe-1/1/0 unit 0 description to-R1
set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.2/30
set interfaces lo0 unit 0 family inet address 192.168.0.2/32
set protocols bgp group external-peers type external
set protocols bgp group external-peers export statics
set protocols bgp group external-peers peer-as 1
set protocols bgp group external-peers neighbor 10.0.0.1
set policy-options policy-statement statics from protocol static
set policy-options policy-statement statics then community add 1
set policy-options policy-statement statics then accept
set policy-options community 1 members 2:1
set policy-options community 1 members 2:2
set policy-options community 1 members 2:3
set policy-options community 1 members 2:4
set policy-options community 1 members 2:5
set policy-options community 1 members 2:6
set policy-options community 1 members 2:7
set policy-options community 1 members 2:8
set policy-options community 1 members 2:9
set policy-options community 1 members 2:10
set routing-options static route 10.2.0.0/16 reject
set routing-options static route 10.2.0.0/16 install
set routing-options static route 10.3.0.0/16 reject
set routing-options static route 10.3.0.0/16 install
set routing-options router-id 192.168.0.3
set routing-options autonomous-system 2

手順

ステップバイステップでの手順

次の例では、設定階層内のさまざまなレベルに移動する必要があります。CLIのナビゲーションについては、Junos OS CLIユーザーガイド設定モードでCLIエディターを使用する を参照してください。

Device R1を設定するには:

  1. インターフェイスを設定します。

    content_copy zoom_out_map
    [edit interfaces]
    user@R1# set fe-1/1/0 unit 0 description to-R2
    user@R1# set fe-1/1/0 unit 0 family inet address 10.0.0.1/30
    user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
    
  2. BGP を設定します。

    デバイスR2とのBGPピアリングセッションにインポートポリシーを適用します。

    content_copy zoom_out_map
    [edit protocols bgp group external-peers]
    user@R1# set type external
    user@R1# set peer-as 2
    user@R1# set neighbor 10.0.0.2 import import-communities
    
  3. 直接ルートを送信するルーティングポリシーを設定します。

    content_copy zoom_out_map
    [edit policy-options policy-statement import-communities]
    user@R1# set term 1 from protocol bgp
    user@R1# set term 1 from community-count 5 orlower
    user@R1# set term 1 then accept
    user@R1# set term 2 then reject
    
  4. 自律システム(AS)番号とルーターIDを設定します。

    content_copy zoom_out_map
    [edit routing-options ]
    user@R1# set router-id 192.168.0.1
    user@R1# set autonomous-system 1
    

ステップバイステップでの手順

次の例では、設定階層内のさまざまなレベルに移動する必要があります。CLIのナビゲーションについては、Junos OS CLIユーザーガイド設定モードでCLIエディターを使用する を参照してください。

デバイスR2 を設定するには:

  1. インターフェイスを設定します。

    content_copy zoom_out_map
    [edit interfaces]
    user@R2# set fe-1/1/0 unit 0 description to-R1
    user@R2# set fe-1/1/0 unit 0 family inet address 10.0.0.2/30
    user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
    
  2. ルーターIDと自律システム(AS)番号を設定する。

    content_copy zoom_out_map
    [edit routing-options]
    user@R2# set router-id 192.168.0.3
    user@R2# set autonomous-system 2
    
  3. BGP を設定します。

    content_copy zoom_out_map
    [edit  protocols bgp group external-peers]
    user@R2# set type external
    user@R2# set peer-as 1
    user@R2# set neighbor 10.0.0.1
    
  4. 複数のコミュニティを設定するか、複数のメンバーを持つ単一のコミュニティを設定します。

    content_copy zoom_out_map
    [edit policy-options community 1]
    user@R2# set members 2:1
    user@R2# set members 2:2
    user@R2# set members 2:3
    user@R2# set members 2:4
    user@R2# set members 2:5
    user@R2# set members 2:6
    user@R2# set members 2:7
    user@R2# set members 2:8
    user@R2# set members 2:9
    user@R2# set members 2:10
    
  5. 静的ルートを構成します。

    content_copy zoom_out_map
    [edit routing-options static]
    user@R2# set route 10.2.0.0/16 reject
    user@R2# set route 10.2.0.0/16 install
    user@R2# set route 10.3.0.0/16 reject
    user@R2# set route 10.3.0.0/16 install
    
  6. スタティックルートをBGPにアドバタイズし、BGPコミュニティをルートに追加するルーティングポリシーを設定します。

    content_copy zoom_out_map
    [edit policy-options policy-statement statics]
    user@R2# set from protocol static
    user@R2# set then community add 1
    user@R2# set then accept
    
  7. エクスポートポリシーを適用します。

    content_copy zoom_out_map
    [edit protocols bgp group external-peers]
    user@R2# set export statics
    

結果

設定モードから、show interfacesshow protocolsshow policy-options、およびshow routing-options のコマンドを入力して設定を確認します。出力結果に意図した設定内容が表示されない場合は、この例の手順を繰り返して設定を修正します。

デバイスR1

content_copy zoom_out_map
user@R1# show interfaces
fe-1/1/0 {
    unit 0{
        description to-R2;
        family inet {
            address 10.0.0.1/30;
        }
    }
}
lo0 {
    unit 0 {
        family inet {
            address 192.168.0.1/32;
        }
    }
}
}
content_copy zoom_out_map
user@R1# show protocols
bgp {
    group external-peers {
        type external;
        peer-as 2;
        neighbor 10.0.0.2 {
            import import-communities;
        }
    }
}
content_copy zoom_out_map
user@R1# show policy-options
policy-statement import-communities {
    term 1 {
        from {
            protocol bgp;
            community-count 5 orlower;
        }
        then accept;
    }
    term 2 {
        then reject;
    }
}
content_copy zoom_out_map
user@R1# show routing-options
router-id 192.168.0.1;
autonomous-system 1;

デバイスR2

content_copy zoom_out_map
user@R2# show interfaces
fe-1/1/0 {
    unit 0 {
        description to-R1;
        family inet {
            address 10.0.0.2/30;
        }
    }
}
lo0 {
    unit 0 {
        family inet {
            address 192.168.0.2/32;
        }
    }
}
content_copy zoom_out_map
user@R2# show protocols
bgp {
    group external-peers {
        type external;
        export statics;
        peer-as 1;
        neighbor 10.0.0.1;
    }
}
content_copy zoom_out_map
user@R2# show policy-options
policy-statement statics {
    from protocol static;
    then {
        community add 1;
        accept;
    }
}
community 1 members [ 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 ];
content_copy zoom_out_map
user@R2# show routing-options
static {
    route 10.2.0.0/16 {
        reject;
        install;
    }
    route 10.3.0.0/16 {
        reject;
        install;
    }
}
router-id 192.168.0.3;
autonomous-system 2;

デバイスの設定が完了したら、設定モードからcommitを入力します。

検証

設定が正常に機能していることを確認します。

BGP ルートの検証

目的

デバイスR1のルーティングテーブルに、予期されるBGPルートが含まれていることを確認します。

アクション

  1. デバイスR1で、 show route protocols bgp コマンドを実行します。

    content_copy zoom_out_map
    user@R1> show route protocols bgp
    
    inet.0: 5 destinations, 5 routes (3 active, 0 holddown, 2 hidden)
    
  2. デバイスR1で、インポートポリシーの community-count 設定を変更します。

    content_copy zoom_out_map
    [edit policy-options policy-statement import-communities term 1]
    user@R1# set from community-count 5 orhigher
    user@R1# commit
    
  3. デバイスR1で、 show route protocols bgp コマンドを実行します。

    content_copy zoom_out_map
    user@R1> show route protocols bgp
    
    inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
    + = Active Route, - = Last Active, * = Both
    
    10.2.0.0/16        *[BGP/170] 18:29:53, localpref 100
                          AS path: 2 I, validation-state: unverified
                        > to 10.0.0.2 via fe-1/1/0.0
    10.3.0.0/16        *[BGP/170] 18:29:53, localpref 100
                          AS path: 2 I, validation-state: unverified
                        > to 10.0.0.2 via fe-1/1/0.0
  4. デバイスR1で、 show route protocols bgp extensive コマンドを実行して、アドバタイズされたコミュニティを表示します。

    content_copy zoom_out_map
    user@R1> show route protocols bgp extensive
    inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
    10.2.0.0/16 (1 entry, 1 announced)
    TSI:
    KRT in-kernel 10.2.0.0/16 -> {10.0.0.2}
            *BGP    Preference: 170/-101
                    Next hop type: Router, Next hop index: 671
                    Address: 0x9458270
                    Next-hop reference count: 4
                    Source: 10.0.0.2
                    Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                    Session Id: 0x100001
                    State: <Active Ext>
                    Local AS:     1 Peer AS:     2
                    Age: 18:56:10 
                    Validation State: unverified 
                    Task: BGP_2.10.0.0.2+179
                    Announcement bits (1): 0-KRT 
                    AS path: 2 I
                    Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                    Accepted
                    Localpref: 100
                    Router ID: 192.168.0.3
    
    10.3.0.0/16 (1 entry, 1 announced)
    TSI:
    KRT in-kernel 10.3.0.0/16 -> {10.0.0.2}
            *BGP    Preference: 170/-101
                    Next hop type: Router, Next hop index: 671
                    Address: 0x9458270
                    Next-hop reference count: 4
                    Source: 10.0.0.2
                    Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                    Session Id: 0x100001
                    State: <Active Ext>
                    Local AS:     1 Peer AS:     2
                    Age: 18:56:10 
                    Validation State: unverified 
                    Task: BGP_2.10.0.0.2+179
                    Announcement bits (1): 0-KRT 
                    AS path: 2 I
                    Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                    Accepted
                    Localpref: 100
                    Router ID: 192.168.0.3
    
    

意味

出力からは、デバイスR1のルーティングテーブルにおいて、デバイスR2から送信されたBGPルートが非表示になっていることがわかります。デバイスR1のインポートポリシーの community-count 設定が変更された場合、BGPルートは非表示ではなくなります。

footer-navigation