例:ルーティングポリシープレフィックスリストの設定
Junos OSでは、プレフィックスリストを通して、ルートのセットを定義する1つの方法が提供されています。Junos OSでは、同じタスクを達成するルートフィルターなどの他の方法も提供されます。プレフィックスリストとは、適用されるポリシーの一致条件として使用されるルートセットを表すIPプレフィックスのリストです。この種のリストは、自律システム(AS)内で顧客ルートのリストを表現するのに有用な場合があります。プレフィックスリストには名前が付けられ、[edit policy-options] 構成階層内で構成されます。
要件
この例を設定する前に、デバイス初期化以外の特別な設定を行う必要はありません。
Junos OSリリース22.1R1を使用して、更新および再検証しました。
概要
プレフィックスリストは、ルートフィルターのリストと類似しています。ルートフィルタとプレフィックスリストの機能的な違いは、プレフィックスリストでは範囲を指定できないことです。プレフィックスリストを使って範囲をシミュレートするには、リストに追加のプレフィックスを含めるか、短いものと長いものの2つのプレフィックスリストを使い、一方を受け入れ、もう一方を拒否に設定します。また、prefix-list-filter 一致条件を使用してプレフィックスリストをフィルタリングすることもできます。選択肢には、exact、longer、orlonger があります。
ルートフィルターのリストよりもプレフィックスリストの方がメリットがあるのは、プレフィックスが複数の異なる場所から参照される場合です。例えば、プレフィックスリストは、BGPインポートポリシー、エクスポートポリシー、RPFポリシー、ファイアウォールフィルター、ループバックフィルター、マルチキャストスコープ設定時などに参照できます。
プレフィックスリストが変更された場合でも、プレフィックスが構成されているたくさんの異なる場所を思い出す必要なく、プレフィックスリストを更新すれば、プレフィックスを何度も変更せずに1回の変更で済みます。これにより、ロケーションのアドレスの入力ミスや、1つ以上のロケーションの更新を忘れるといった構成ミスを減らすことができます。
プレフィックスリストは、多数のデバイスを管理する場合にも役立ちます。特定のIPアドレスではなく、プレフィックスリストを参照することで、さまざまなフィルターやポリシーをできるだけ汎用的に記述できます。フィルターやポリシーの複雑なロジックは一度だけ記述すればよく、デバイスごと、サイトごとのカスタマイズを最小限にとどめることができます。
図 1に示すように、AS65000内の各ルーターはカスタマールートを有しています。デバイスR1は、172.16.1.0/24サブネット内で顧客ルートを割り当てます。デバイスR2は 172.16.2.0/24、デバイスR3は172.16.3.0/24のサブネット内で顧客ルートを割り当てます。デバイスR1はAS65000の中央点に指定されており、カスタマールートの完全なリストを保持しています。以下に示すように、デバイスR1には customers というプレフィックスリストがあります。
user@R1# show policy-options
prefix-list customers {
172.16.1.16/28;
172.16.1.32/28;
172.16.1.48/28;
172.16.1.64/28;
172.16.2.16/28;
172.16.2.32/28;
172.16.2.48/28;
172.16.2.64/28;
172.16.3.16/28;
172.16.3.32/28;
172.16.3.48/28;
172.16.3.64/28;
}
見ての通り、プレフィックスリストには(ルートフィルターに表示されるような)各ルートの一致タイプは含まれません。これは、ポリシーでプレフィックスリストを使用する場合の重要なポイントです。ルートは、リスト内のプレフィックスの1つと正確に一致する場合のみ一致します。言い換えれば、リスト内の各ルートは、プレフィックスリストで構成された通りにルーティングテーブルに表示されなければなりません。
以下のように、ポリシー内の一致条件としてプレフィックスリストを参照します。
user@R1# show policy-options
policy-statement customer-routes {
term get-routes {
from {
prefix-list customers;
}
then accept;
}
term others {
then reject;
}
}
この例では、customers プレフィックスリスト内のすべてのルートが、デバイスR1のルーティングテーブルに表示されます。デバイスR2とデバイスR3は、顧客宛のデバイスR1静的ルートにエクスポートします。
前述したように、prefix-list-filter 一致条件は exact、longer、または orlonger 一致タイプで使用できます。これにより、プレフィックスリストの完全一致制限を回避する方法が提供されます。以下はその一例です。
user@R1# show policy-options
policy-statement customer-routes {
term get-routes {
from {
prefix-list-filter customers orlonger;
}
then accept;
}
term others {
then reject;
}
}
この例は、prefix-list 一致条件と prefix-list-filter 一致条件の両方の効果を示しています。
トポロジー
図 1は、サンプルのネットワークを示しています。

CLIクイック構成は、図 1でのすべてのデバイスの設定を示しています。
セクション#configuration449__policy-prefix-list-stは、デバイス R1 の手順を説明します。
設定
CLIクイック構成
この例をすばやく設定するには、次のコマンドをコピーしてテキストファイルに貼り付け、改行を削除して、ネットワーク構成に合わせて必要な詳細を変更し、[edit]階層レベルのCLIにコマンドをコピー&ペーストしてください。
デバイスR1
set interfaces ge-0/0/0 unit 0 description to_R2 set interfaces ge-0/0/0 unit 0 family inet address 10.0.0.1/30 set interfaces ge-0/0/1 unit 0 description to_R3 set interfaces ge-0/0/1 unit 0 family inet address 10.0.0.5/30 set interfaces ge-0/0/2 unit 0 description to_R4 set interfaces ge-0/0/2 unit 0 family inet address 10.1.0.5/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set policy-options prefix-list customers 172.16.1.16/28 set policy-options prefix-list customers 172.16.1.32/28 set policy-options prefix-list customers 172.16.1.48/28 set policy-options prefix-list customers 172.16.1.64/28 set policy-options prefix-list customers 172.16.2.16/28 set policy-options prefix-list customers 172.16.2.32/28 set policy-options prefix-list customers 172.16.2.48/28 set policy-options prefix-list customers 172.16.2.64/28 set policy-options prefix-list customers 172.16.3.16/28 set policy-options prefix-list customers 172.16.3.32/28 set policy-options prefix-list customers 172.16.3.48/28 set policy-options prefix-list customers 172.16.3.64/28 set policy-options policy-statement customer-routes term get-routes from prefix-list customers set policy-options policy-statement customer-routes term get-routes then accept set policy-options policy-statement customer-routes term others then reject set routing-options router-id 192.168.0.1 set routing-options autonomous-system 65000 set routing-options static route 172.16.1.16/28 discard set routing-options static route 172.16.1.32/28 discard set routing-options static route 172.16.1.48/28 discard set routing-options static route 172.16.1.64/28 discard set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.1 set protocols bgp group int neighbor 192.168.0.2 set protocols bgp group int neighbor 192.168.0.3 set protocols bgp group to_65001 type external set protocols bgp group to_65001 export customer-routes set protocols bgp group to_65001 neighbor 10.1.0.6 peer-as 65001 set protocols ospf area 0.0.0.0 interface ge-0/0/0.0 set protocols ospf area 0.0.0.0 interface ge-0/0/1.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive
デバイスR2
set interfaces ge-0/0/0 unit 0 description to_R1 set interfaces ge-0/0/0 unit 0 family inet address 10.0.0.2/30 set interfaces ge-0/0/1 unit 0 description to_R3 set interfaces ge-0/0/1 unit 0 family inet address 10.1.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set routing-options router-id 192.168.0.2 set routing-options autonomous-system 65000 set routing-options static route 172.16.2.16/28 discard set routing-options static route 172.16.2.32/28 discard set routing-options static route 172.16.2.48/28 discard set routing-options static route 172.16.2.64/28 discard set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.2 set protocols bgp group int neighbor 192.168.0.1 export send-static set protocols bgp group int neighbor 192.168.0.3 set protocols ospf area 0.0.0.0 interface ge-0/0/0.0 set protocols ospf area 0.0.0.0 interface ge-0/0/1.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive
デバイスR3
set interfaces ge-0/0/0 unit 0 description to_R1 set interfaces ge-0/0/0 unit 0 family inet address 10.0.0.6/30 set interfaces ge-0/0/1 unit 0 description to_R2 set interfaces ge-0/0/1 unit 0 family inet address 10.1.0.2/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set routing-options router-id 192.168.0.3 set routing-options autonomous-system 65000 set routing-options static route 172.16.3.16/28 discard set routing-options static route 172.16.3.32/28 discard set routing-options static route 172.16.3.48/28 discard set routing-options static route 172.16.3.64/28 discard set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.3 set protocols bgp group int neighbor 192.168.0.1 export send-static set protocols bgp group int neighbor 192.168.0.2 set protocols ospf area 0.0.0.0 interface ge-0/0/0.0 set protocols ospf area 0.0.0.0 interface ge-0/0/1.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive
デバイス R4
set interfaces ge-0/0/0 unit 0 description to_R1 set interfaces ge-0/0/0 unit 0 family inet address 10.1.0.6/30 set interfaces lo0 unit 0 family inet address 192.168.0.4/32 set routing-options autonomous-system 65001 set protocols bgp group ext type external set protocols bgp group ext peer-as 65000 set protocols bgp group ext neighbor 10.1.0.5
手順
ステップバイステップでの手順
R1を設定する手順を順を追って説明します。他のルーターもこれに類似した手順になります。次の例では、設定階層内のさまざまなレベルに移動する必要があります。CLIのナビゲーションについては、Junos OS CLIユーザーガイドの「設定モードでのCLIエディターの使用」を参照してください。
R1を設定するには:
-
インターフェイスを設定します。
[edit] user@R1# set interfaces ge-0/0/0 unit 0 description to_R2 user@R1# set interfaces ge-0/0/0 unit 0 family inet address 10.0.0.1/30 user@R1# set interfaces ge-0/0/1 unit 0 description to_R3 user@R1# set interfaces ge-0/0/1 unit 0 family inet address 10.0.0.5/30 user@R1# set interfaces ge-0/0/2 unit 0 description to_R4 user@R1# set interfaces ge-0/0/2 unit 0 family inet address 10.1.0.5/30 user@R1# set interfaces lo0 unit 0 family inet address 192.168.0.1/32
-
IBGP(内部BGP)ピアリングをR2とR3に設定します。
[edit] user@R1# set protocols bgp group int type internal user@R1# set protocols bgp group int local-address 192.168.0.1 user@R1# set protocols bgp group int neighbor 192.168.0.2 user@R1# set protocols bgp group int neighbor 192.168.0.3
-
外部BGP(EBGP)ピアリングをR4に設定します。エクスポートポリシー設定は、後のステップで示します。
[edit] user@R1# set protocols bgp group to_65001 type external user@R1# set protocols bgp group to_65001 export customer-routes user@R1# set protocols bgp group to_65001 neighbor 10.1.0.6 peer-as 65001
-
OSPFピアリングをR2とR3に設定します。OSPFプロトコルは、IBGPピアリングを確立できる各デバイスごとにループバックアドレスの学習を提供します。
[edit] user@R1# set protocols ospf area 0.0.0.0 interface ge-0/0/0.0 user@R1# set protocols ospf area 0.0.0.0 interface ge-0/0/1.0 user@R1# set protocols ospf area 0.0.0.0 interface lo0.0 passive
-
プレフィックスリストを構成します。
[edit] user@R1# set policy-options prefix-list customers 172.16.1.16/28 user@R1# set policy-options prefix-list customers 172.16.1.32/28 user@R1# set policy-options prefix-list customers 172.16.1.48/28 user@R1# set policy-options prefix-list customers 172.16.1.64/28 user@R1# set policy-options prefix-list customers 172.16.2.16/28 user@R1# set policy-options prefix-list customers 172.16.2.32/28 user@R1# set policy-options prefix-list customers 172.16.2.48/28 user@R1# set policy-options prefix-list customers 172.16.2.64/28 user@R1# set policy-options prefix-list customers 172.16.3.16/28 user@R1# set policy-options prefix-list customers 172.16.3.32/28 user@R1# set policy-options prefix-list customers 172.16.3.48/28 user@R1# set policy-options prefix-list customers 172.16.3.64/28
-
プレフィックスリストを一致条件として参照するルーティングポリシーを構成します。
[edit] user@R1# set policy-options policy-statement customer-routes term get-routes from prefix-list customers user@R1# set policy-options policy-statement customer-routes term get-routes then accept user@R1# set policy-options policy-statement customer-routes term others then reject
-
172.16.1.0/24ネットワークの静的ルートを設定します。カスタマールートをエミュレートするために、静的ルートを使用します。
[edit] user@R1# set routing-options static route 172.16.1.16/28 discard user@R1# set routing-options static route 172.16.1.32/28 discard user@R1# set routing-options static route 172.16.1.48/28 discard user@R1# set routing-options static route 172.16.1.64/28 discard
-
自律システム(AS)番号とルーターIDを設定します。
[edit] user@R1# set routing-options router-id 192.168.0.1 user@R1# set routing-options autonomous-system 65000
結果
設定モードから、show interfaces 、show protocols、show policy-options、およびshow routing-options のコマンドを入力して設定を確認します。出力結果に意図した設定内容が表示されない場合は、この例の手順を繰り返して設定を修正します。
user@R1# show interfaces
ge-0/0/0 {
unit 0 {
description to_R2;
family inet {
address 10.0.0.1/30;
}
}
}
ge-0/0/1 {
unit 0 {
description to_R3;
family inet {
address 10.0.0.5/30;
}
}
}
ge-0/0/2 {
unit 0 {
description to_R4;
family inet {
address 10.1.0.5/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 192.168.0.1/32;
}
}
}user@R1# show protocols
bgp {
group int {
type internal;
local-address 192.168.0.1;
neighbor 192.168.0.2;
neighbor 192.168.0.3;
}
group to_65001 {
type external;
export customer-routes;
neighbor 10.1.0.6 {
peer-as 65001;
}
}
}
ospf {
area 0.0.0.0 {
interface ge-0/0/0.0;
interface ge-0/0/1.0;
interface lo0.0 {
passive;
}
}
}user@R1# show policy-options
prefix-list customers {
172.16.1.16/28;
172.16.1.32/28;
172.16.1.48/28;
172.16.1.64/28;
172.16.2.16/28;
172.16.2.32/28;
172.16.2.48/28;
172.16.2.64/28;
172.16.3.16/28;
172.16.3.32/28;
172.16.3.48/28;
172.16.3.64/28;
}
policy-statement customer-routes {
term get-routes {
from {
prefix-list customers;
}
then accept;
}
term others {
then reject;
}
}
user@R1# show routing-options
static {
route 172.16.1.16/28 discard;
route 172.16.1.32/28 discard;
route 172.16.1.48/28 discard;
route 172.16.1.64/28 discard;
}
router-id 192.168.0.1;
autonomous-system 65000;
デバイスの設定が完了したら、設定モードから commit を入力します。
検証
設定が正常に機能していることを確認します。
R1のルートを検証
目的
R1で、ルーティングテーブル内のルートを確認します。
アクション
user@R1> show route terse 172.16/16 inet.0: 30 destinations, 30 routes (30 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both A V Destination P Prf Metric 1 Metric 2 Next hop AS path * ? 172.16.1.16/28 S 5 Discard * ? 172.16.1.32/28 S 5 Discard * ? 172.16.1.48/28 S 5 Discard * ? 172.16.1.64/28 S 5 Discard * ? 172.16.2.16/28 B 170 100 I unverified >10.0.0.2 * ? 172.16.2.32/28 B 170 100 I unverified >10.0.0.2 * ? 172.16.2.48/28 B 170 100 I unverified >10.0.0.2 * ? 172.16.2.64/28 B 170 100 I unverified >10.0.0.2 * ? 172.16.3.16/28 B 170 100 I unverified >10.0.0.6 * ? 172.16.3.32/28 B 170 100 I unverified >10.0.0.6 * ? 172.16.3.48/28 B 170 100 I unverified >10.0.0.6 * ? 172.16.3.64/28 B 170 100 I unverified >10.0.0.6
意味
デバイスR1は、自身の静的ルート(S)とデバイス R2、R3からのBGPルート(B)を学習済みです。
R4へのルートアドバタイズを検証
目的
R1で、カスタマールートがR4にアドバタイズされていることを確認します。
アクション
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 30 destinations, 30 routes (30 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I
意味
予想通り、カスタマープレフィックスリストからのルートのみがR4にアドバタイズされます。
prefix-list-filterステートメントを使った検証
目的
prefix-list-filter を prefix-list の代わりに使用するとどうなるかを確認します。
アクション
-
R3で、既存の静的ルートの1つよりも長い静的ルートを追加します。
[edit routing-options static] user@R3# set route 172.16.3.65/32 discard user@R3# commit
-
R1で、プレフィックスリストを無効にし、
orlongerマッチタイプでプレフィックスリストフィルタを設定します。[edit policy-options policy-statement customer-routes term get-routes] user@R1# deactivate from prefix-list customers user@R1# set from prefix-list-filter customers orlonger user@R1# commit
-
R1で、R4にアドバタイズされているルートを確認します。
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 31 destinations, 31 routes (31 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I * 172.16.3.65/32 Self I
意味
予想通り、172.16.3.65/32がプレフィックスリストにないにもかかわらず、R1は172.16.3.65/32ルートをR4にアドバタイズしています。