例:ASパス先頭付加のルーティングポリシーの設定
この例では、BGPによってアドバタイズされる特定のルートのASパスを先頭に追加するようにルーティングポリシーを設定する方法を示しています。
要件
開始する前に、ルーターのインターフェイスとプロトコルが正しく設定されていることを確認してください。 このドキュメントで使用するインターフェイスとBGPプロトコルの設定を提供します。
この例は、Junosリリース2 2で更新され、再検証されました。1 R1。
概要
この例では、 と呼ばれるルーティング・ポリシーと と呼ばれる 用語 を作成します。prependpolicy1prependterm1 マスク長が指定したマスク以上の場合、ルーティング ポリシーは、172.16.0.0/12、192.168.0.0/16、および 10.0.0.0/8 プレフィックスに一致するルートに、AS 番号 65001 を 3 回付加します。その結果、ルートのマスク長が指定したネットワーク マスクと同じかそれより 長い場合、一致が発生します。このポリシーは、AS 65001のR1がAS番号65000のR2にアドバタイズしたBGPルートに、エクスポートポリシーとして適用されます。prependpolicy1指定されたプレフィックス範囲に一致しないルートには、ASパスが先頭に追加されません。
トポロジー
トポロジーでは、R1 と R2 の間に EBGP ピアリングが設定されています。10.1.23.0/24サブネットアドレスへの直接インターフェイスピアリングが使用されます。R1はAS番号65001に属しており、R2にアドバタイズされる際に、特定の一致するルートセットの先頭にAS番号を付加するように設定されています。
ASパスにAS番号を追加することで、転送対象としてルートが選択される可能性が低くなります。これは、AS 65001の所有者が、AS 65000のオペレータから受信するイングレストラフィックの量を減らすために行う場合があります。
この例では、エクスポートポリシーを介して先頭に追加するASパスを示しています。また、インポート・ポリシーを使用して、属性操作のルートでマッチングすることもできます。一般的には、ルートの先頭にのみローカルAS番号を付加するのがベストプラクティスです。リモートネットワークに属するAS番号を先頭に追加すると、予期しない結果が生じる可能性があります。
BGP パス選択の詳細については、を参照してください 。Understanding BGP Path Selection
設定
手順
CLIクイック構成
このセクションでは、R1 デバイスの設定を中心に説明します。この例で使用されているすべてのデバイスの完全な設定については、付録を参照してください。
この例をすばやく設定するには、次のコマンドをコピーしてテキストファイルに貼り付け、改行を削除して、ネットワーク構成に合わせて必要な詳細を変更し、[edit]階層レベルのCLIにコマンドをコピー&ペーストしてください。
この例では、R1の未使用のインターフェイスに3つのテストプレフィックスを割り当てます。4 番目のテスト プレフィックスが R1 のループバック アドレスに割り当てられます。これにより、BGP にアドバタイズできる 4 つの直接ルートが提供されます。当社のポリシーでは、 ステートメントと ステートメントを組み合わせて使用し、どのプレフィックスにASパスの先頭付加を付けるかを制御します。protocol direct
route-filter
set system host-name R1 set interfaces xe-0/0/0:1 unit 0 family inet address 10.1.23.1/24 set interfaces xe-0/0/0:0 unit 0 family inet address 10.255.1.1/30 set interfaces xe-0/0/0:0 unit 0 family inet address 172.16.0.1/24 set interfaces xe-0/0/0:0 unit 0 family inet address 10.200.1.1/24 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set policy-options policy-statement prependpolicy1 term prependterm1 from protocol direct set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 172.16.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 192.168.0.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 10.255.1.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 then as-path-prepend "65001 65001 65001" set policy-options policy-statement prependpolicy1 term prependterm1 then accept set policy-options policy-statement prependpolicy1 term else from protocol direct set policy-options policy-statement prependpolicy1 term else from route-filter 10.200.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term else then accept set routing-options autonomous-system 65001 set routing-options router-id 192.168.0.1 set protocols bgp group ebgp type external set protocols bgp group ebgp export prependpolicy1 set protocols bgp group ebgp peer-as 65000 set protocols bgp group ebgp neighbor 10.1.23.2
ステップバイステップでの手順
次の手順では、構成階層内のさまざまなレベルに移動する必要があります。手順については、 Junos OS CLIユーザーガイドのを参照してください。設定モードでのCLIエディターの使用https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
特定のルートの先頭にAS番号を付加するルーティングポリシーを作成するには:
-
ピアリングおよびループバックインターフェイスを設定します。
user@R1# [edit] set interfaces xe-0/0/0:1 unit 0 family inet address 10.1.23.1/24 set interfaces lo0 unit 0 family inet address 192.168.0.1/32
-
AS 番号、RID、および外部 BGP ピア グループを設定します。次のステップでポリシーを定義します 。prependpolicy1 ポリシーは、R1がアドバタイズするルートに影響を与えるエクスポートポリシーとして適用されます。
user@R1# [edit] set routing-options autonomous-system 65001 set routing-options router-id 192.168.0.1 set protocols bgp group ebgp type external set protocols bgp group ebgp export prependpolicy1 set protocols bgp group ebgp peer-as 65000 set protocols bgp group ebgp neighbor 10.1.23.2
-
ポリシーを設定します 。prependpolicy1 ルート フィルター ステートメントへの switch を使用すると 、マスク長が指定したマスク以上の場合にマッチングが可能になります。
or-longer
プレフィックスとマスクの長さが同じ場合にのみ一致するなどの他の オプション。exact
この用語は 、用語に一致 しないルートが、用語に一致することによって ASパスを先頭に付加せずにアドバタイズされる方法を示しています。elseprependterm1elseuser@R1# [edit] set policy-options policy-statement prependpolicy1 term prependterm1 from protocol direct set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 172.16.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 192.168.0.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 10.255.1.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 then as-path-prepend "65001 65001 65001" set policy-options policy-statement prependpolicy1 term prependterm1 then accept set policy-options policy-statement prependpolicy1 term else from protocol direct set policy-options policy-statement prependpolicy1 term else from route-filter 10.200.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term else then accept
注:複数のAS番号を入力する場合は、それぞれの番号をスペースで区切る必要があります。AS番号の文字列は二重引用符で囲みます。
-
テスト ルートを定義します。このサンプルトポロジーでは、動作上稼働している未使用のインターフェースにプレフィックスを割り当てます。これにより、BGPがエクスポートポリシーの動作をテストするためにアドバタイズする直接ルートが提供されます。
user@R1# [edit] set interfaces xe-0/0/0:0 unit 0 family inet address 10.255.1.1/30 set interfaces xe-0/0/0:0 unit 0 family inet address 172.16.0.1/24 set interfaces xe-0/0/0:0 unit 0 family inet address 10.200.1.1/24
結果
コンフィギュレーション・モードから 、 、 、および のコマンドを入力して、コンフィギュレーションを確認します。show policy-optionsshow protocols bgpshow routing-optionsshow interfaces 出力結果に意図した設定内容が表示されない場合は、この例の設定手順を繰り返して設定を修正します。
user@R1#[edit] user@R1# show policy-options policy-statement prependpolicy1 { term prependterm1 { from { protocol direct; route-filter 172.16.0.0/16 orlonger; route-filter 192.168.0.0/24 orlonger; route-filter 10.255.1.0/24 orlonger; } then { as-path-prepend "65001 65001 65001"; accept; } } term else { from { protocol direct; route-filter 10.200.0.0/16 orlonger; } then accept; } } [edit] user@R1# show protocols bgp group ebgp { type external; export direct; peer-as 65000; neighbor 10.1.23.2; } [edit] user@R1# show routing-options autonomous-system 65001; router-id 192.168.0.1 user@R1# show interfaces xe-0/0/0:0 unit 0 { family inet { address 10.255.1.1/30; address 172.16.0.1/24; address 10.200.1.1/24; } } [edit] user@R1# show interfaces xe-0/0/0:1 unit 0 { family inet { address 10.1.23.1/24; } } [edit] user@R1# show interfaces lo0 unit 0 { family inet { address 192.168.0.1/32; } }
R1デバイスの設定が完了したら、設定モードから を入力します。commit
検証
設定が正常に機能していることを確認するには、次のタスクを実行します。
AS先頭付加ポリシーの検証
目的
ポリシーがデバイスで設定され、AS番号が先頭に付加されるように適切なルートが指定されていることを確認します。
アクション
動作モードからshow policy prependpolicy1 コマンドを入力します。
user@R1> show policy prependpolicy1 Policy prependpolicy1: [CHANGED/RESOLVED/] Term prependterm1: from proto Direct route filter: 172.16.0.0/16 orlonger 192.168.0.0/24 orlonger 10.255.1.0/24 orlonger then aspathprepend 65001 65001 65001 accept Term else: from proto Direct route filter: 10.200.0.0/16 orlonger then accept
ポリシーには、正しい一致条件とアクションが表示されます。
ルーティング ポリシー アプリケーションと BGP ピアリングの検証
目的
ルーティングポリシーが、EBGP ピアグループにエクスポートポリシーとして適用されていることを確認します。この手順では、R2 への BGP セッションが正しく確立されていることも確認します。
アクション
動作モードからshow bgp neighbor 10.1.23.2コマンドを入力します。
user@R1> show bgp neighbor 10.1.23.2 Peer: 10.1.23.2+49642 AS 65000 Local: 10.1.23.1+179 AS 65001 Group: ebgp Routing-Instance: master Forwarding routing-instance: master Type: External State: Established Flags: <Sync> Last State: OpenConfirm Last Event: RecvKeepAlive Last Error: None Export: [ prependpolicy1 ] Options: <PeerAS Refresh> Options: <GracefulShutdownRcv> Holdtime: 90 Preference: 170 Graceful Shutdown Receiver local-preference: 0 Number of flaps: 1 Last flap event: RecvNotify Error: 'Cease' Sent: 0 Recv: 1 Peer ID: 192.168.0.2 Local ID: 192.168.0.1 Active Holdtime: 90 . . . Input messages: Total 2498 Updates 1 Refreshes 0 Octets 47510 Output messages: Total 2500 Updates 3 Refreshes 0 Octets 47620 Output Queue[1]: 0 (inet.0, inet-unicast)
コマンド出力は、BGPセッションが確立されていること、およびR1がエクスポートとしてポリシーを適用 したことを確認します。prependpolicy1
ASパス先頭付加の検証
目的
エクスポートポリシーが、一致するルートの先頭にAS番号を付加するように設計どおりに機能することを確認します。
アクション
動作モードから、R2に コマンドを入力します 。show route protocol bgp または、R1の を使用して、R2にアドバタイズするルートの詳細を表示します。show route advertising-protocol bgp 10.1.23.2
user@R2> show route protocol bgp
inet.0: 14 destinations, 14 routes (14 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
10.200.1.0/24 *[BGP/170] 00:04:46, localpref 100
AS path: 65001 I, validation-state: unverified
> to 10.1.23.1 via xe-0/0/0:0.0
10.255.1.0/30 *[BGP/170] 00:04:46, localpref 100
AS path: 65001 65001 65001 65001 I, validation-state: unverified
> to 10.1.23.1 via xe-0/0/0:0.0
172.16.0.0/24 *[BGP/170] 00:04:46, localpref 100
AS path: 65001 65001 65001 65001 I, validation-state: unverified
> to 10.1.23.1 via xe-0/0/0:0.0
192.168.0.1/32 *[BGP/170] 00:04:46, localpref 100
AS path: 65001 65001 65001 65001 I, validation-state: unverified
> to 10.1.23.1 via xe-0/0/0:0.0
ルートには、予想されるASパスが付加されて表示されます。10.200.1.0/24ルートには、AS番号65001のインスタンスが1つだけあることに注意してください。このルートは、 ポリシーの 内のルート フィルター ステートメントと一致しないため、先頭に付加されません。prependterm1prependpolicy1
R2 にアドバタイズする BGP ルートに関する R1 のビューは、完全を期すために提供されています。
user@R1> show route advertising-protocol bgp 10.1.23.2
inet.0: 16 destinations, 16 routes (16 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 10.200.1.0/24 Self I
* 10.255.1.0/30 Self 65001 65001 65001 [65001] I
* 172.16.0.0/24 Self 65001 65001 65001 [65001] I
* 192.168.0.1/32 Self 65001 65001 65001 [65001] I
付録フル構成
R1の完全な設定。
set system host-name R1 set interfaces xe-0/0/0:0 unit 0 family inet address 10.255.1.1/30 set interfaces xe-0/0/0:0 unit 0 family inet address 172.16.0.1/24 set interfaces xe-0/0/0:0 unit 0 family inet address 10.200.1.1/24 set interfaces xe-0/0/0:1 unit 0 family inet address 10.1.23.1/24 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set policy-options policy-statement prependpolicy1 term prependterm1 from protocol direct set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 172.16.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 192.168.0.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 from route-filter 10.255.1.0/24 orlonger set policy-options policy-statement prependpolicy1 term prependterm1 then as-path-prepend "65001 65001 65001" set policy-options policy-statement prependpolicy1 term prependterm1 then accept set policy-options policy-statement prependpolicy1 term else from protocol direct set policy-options policy-statement prependpolicy1 term else from route-filter 10.200.0.0/16 orlonger set policy-options policy-statement prependpolicy1 term else then accept set routing-options router-id 192.168.0.1 set routing-options autonomous-system 65001 set protocols bgp group ebgp type external set protocols bgp group ebgp export prependpolicy1 set protocols bgp group ebgp peer-as 65000 set protocols bgp group ebgp neighbor 10.1.23.2
R2の完全な設定。
set system host-name R2 set interfaces xe-0/0/0:0 unit 0 family inet address 10.1.23.2/24 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set routing-options router-id 192.168.0.2 set routing-options autonomous-system 65000 set protocols bgp group ebgp type external set protocols bgp group ebgp peer-as 65001 set protocols bgp group ebgp neighbor 10.1.23.1