宛先経路が複数ある場合、以下のアルゴリズムに従ってベストパスが一つ選択され、ルーティングテーブルに登録されます。
優先度 | アトリビュート |
1 | WEIGHT |
2 | LOCAL_PREF |
3 | 自生成ルート |
4 | AS_PATH |
5 | ORIGIN |
6 | MED |
7 | IGP>EGP>incomplete |
8以降も存在しますが一旦ここまで知っておけばBGPの経路制御で困ることはほぼほぼないかと思います。
WEIGHTアトリビュートはcisco独自のアトリビュートです。
今回はLOCAL_PREFアトリビュートを扱います。
LOCAL_PREFは同一AS内でのみ影響を与えるアトリビュートで発信トラフィックを制御します。
値が大きい経路を優先します。
LOCAL_PREFアトリビュートを変更するには2種類の方法があります。
①ネイバーのLOCAL_PREFを変更する
②変更したいプレフィックスをroute-mapで指定してLOCAL_PREFを変更する
現状、1.1.1.0/24はSW2をベストパスとしています。
BGP table version is 3, local router ID is 20.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not foundNetwork Next Hop Metric LocPrf Weight Path
*>i 1.1.1.0/24 10.1.1.2 0 100 0 200 i
* i 20.1.1.2 0 100 0 200 i
①の方法で変更してみます。
Enter configuration commands, one per line. End with CNTL/Z.
Switch2(config)#router bgp 100
Switch2(config-router)#bgp default local-preference 200
Switch2(config-router)#end
Switch2#clear ip bgp * so
Switch3#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch3(config)#router bgp 100
Switch3(config-router)#bgp default local-preference 500
Switch3(config-router)#end
Switch3#clear ip bgp * so
SW1から見るとLOCAL_PREF値比較によりSW3をベストパスとして選択していることが分かります。
BGP table version is 4, local router ID is 20.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not foundNetwork Next Hop Metric LocPrf Weight Path
* i 1.1.1.0/24 10.1.1.2 0 200 0 200 i
*>i 20.1.1.2 0 500 0 200 i
次に②の方法を試してみます。
今回はプレフィックスマッチではなくAS-PATHアクセスリストを用いて特定のASにマッチしたものに対してLOCAL_PREFを付与させてみます。
Switch2(config)#ip as-path access-list 1 permit ^200_
Switch2(config)#route-map LP permit 10
Switch2(config-route-map)#match as-path 1
Switch2(config-route-map)#set local-preference 300
Switch2(config-route-map)#router bgp 100
Switch2(config-router)#nei 30.1.1.1 route-map LP in
Switch2(config-router)#end
Switch2#clear ip bgp * so
Switch3#conf t
Switch3(config)#ip as-path access-list 1 permit ^200_
Switch3(config)#route-map LP permit 10
Switch3(config-route-map)#match as-path 1
Switch3(config-route-map)#set local-preference 600
Switch3(config-route-map)#router bgp 100
Switch3(config-router)#nei 40.1.1.1 route-map LP in
Switch3(config-router)#end
Switch3#clear ip bgp * so
SW1から見るとLOCAL_PREF値比較によりSW3をベストパスとして選択していることが分かります。
最後に優先度3の自生成ルートよりもLOCAL_PREFが優先されるか確認します。
SW1で1.1.1.0/24をnetworkコマンドによりルートを自生成させます。
Switch1(config)#router bgp 100
Switch1(config-router)#net 1.1.1.0 mask 255.255.255.0
Switch1(config-router)#end
Switch1#sh ip bgp
BGP table version is 8, local router ID is 20.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not foundNetwork Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 0.0.0.0 0 32768 i
* i 10.1.1.2 0 300 0 200 i
* i 20.1.1.2 0 600 0 200 i
これが罠です。
LPを無視して自生成ルートがベストパスに選択されています。
よく見ると自生成ルートにWEIGHTアトリビュートが付与されています。
自生成ルートはデフォルトで32768のWEIGHTが付与されます。
また、ピアから受け取る経路はWEIGHTが0となるため、より優先度の高いWEIGHT比較により自生成ルートが選択されてしまっています。
意図した経路選択をしたければWEIGHTを合わせてあげれば良いです。
Switch1(config-router)#nei 10.1.1.2 wei
Switch1(config-router)#nei 10.1.1.2 weight 32768
Switch1(config-router)#nei 20.1.1.2 weight 32768
Switch1#sh ip bgp
BGP table version is 10, local router ID is 20.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
r 1.1.1.0/24 0.0.0.0 0 32768 i
r i 10.1.1.2 0 300 32768 200 i
r>i 20.1.1.2 0 600 32768 200 i
コメントを書く