例:ルーティングポリシープレフィックスリストの設定
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 に示すように、AS 65000 の各ルーターには顧客ルートがあります。デバイスR1は、172.16.1.0/24サブネット内で顧客ルートを割り当てます。デバイスR2は、デバイスR3は、それぞれ172.16.2.0/24および172.16.3.0/24サブネット内で顧客ルートを割り当てます。デバイスR1は、顧客ルートの完全なリストを維持するために、AS 65000の中央点に指定されています。以下に示すように、デバイス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
-
R2およびR3への内部BGP(IBGP)ピアリングを設定します。
[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
-
R4への外部BGP(EBGP)ピアリングを設定します。エクスポートポリシー設定は、後のステップで示します。
[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
-
R2 および R3 への OSPF ピアリングを設定します。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の代わりにprefix-list-filterを使用するとどうなるかを確認してください。
アクション
-
R3 上で、既存の静的ルートよりも長い静的ルートを追加します。
[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にアドバタイズしています。