忍者ブログ

しこてぃっしゅβ

日々の忘備録代わりと、チラシのウラで。

   

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

BGP next-hop-selfのはなし

今回はBGPについてです。


BGP next-hop-selfの話です。




BGPは非常に複雑なルーティングプロトコルです。


エンタープライズのネットワークではそれほど難しい設計はありませんが、キャリア系のネットワークでは非常に複雑な経路制御を行います。


痛男はこれまでにキャリア系の設計・テスト・構築プロジェクト数案件に参加したことがありますが、どれもこれもPATH属性をガチガチにチューニングしてありました。


特にAS-PATH属性の正規表現なんかは何度やってもなかなか覚えられません。


とは言え、覚えられないだと仕事がないこの業界、いつまでも逃げている訳にはいきません。と、いうわけでAS-PATH属性については機会をみて検証しながらこのブログにアップしていきたいと思います。


今回はBGPのnext-hop-selfの話です。


もう少し体系立ててブログにアップすれば良いのですが、いかんせんその時その時で困ったことや勉強になったことなどの忘備録的なブログなので部分部分のアップになっちゃいますね。すみません。


 


bgpには多き分けてi-bgpとe-bgpの二種類があります。


ざっくり言うと、i-bgpは同一ASを持つ同一ドメインに所属しているノード同士で接続するBGPで、e-bgpは異なるASを持つ異なるドメインに所属しているノード同士で接続するBGPです。


基本的にBGPはAS単位での経路情報の交換を目的として開発されたルーティングプロトコルなので、OSPFやEIGRPなどとは少し実装が違います。



例えば、以下のような単純な構成があったとします。





R-1ではloopback 0に192.168.0.1/24のアドレスを設定しています。本来、このような使い方はしないと思いますが、今回は疑似的な環境としてこうしています。


R-1、R-2、R-3、R-4はそれぞれASが異なりますので、e-bgpで接続されています。


また、R-4とR-5は同一ASに所属しているため、i-bgpで接続されています。


========
R1#show ip bgp summary
BGP router identifier 192.168.0.1, local AS number 55627
BGP table version is 2, main routing table version 2
1 network entries using 117 bytes of memory
1 path entries using 52 bytes of memory
2/1 BGP path/bestpath attribute entries using 248 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 417 total bytes of memory
BGP activity 1/0 prefixes, 1/0 paths, scan interval 60 secs


Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.2        4  4766     307     307        2    0    0 05:03:16        0
R1#


========
R2#show ip bgp summary
BGP router identifier 10.0.0.5, local AS number 4766
BGP table version is 2, main routing table version 2
1 network entries using 117 bytes of memory
1 path entries using 52 bytes of memory
2/1 BGP path/bestpath attribute entries using 248 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 441 total bytes of memory
BGP activity 1/0 prefixes, 1/0 paths, scan interval 60 secs


Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.1        4 55627     308     308        2    0    0 05:04:13        1
10.0.0.6        4  2497     308     308        2    0    0 05:04:13        0
R2#


========
R3#show ip bgp summary
BGP router identifier 10.0.0.9, local AS number 2497
BGP table version is 2, main routing table version 2
1 network entries using 117 bytes of memory
1 path entries using 52 bytes of memory
2/1 BGP path/bestpath attribute entries using 248 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 441 total bytes of memory
BGP activity 1/0 prefixes, 1/0 paths, scan interval 60 secs


Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.5        4  4766     308     308        2    0    0 05:04:37        1
10.0.0.10       4  2461     350     363        2    0    0 00:20:11        0
R3#


========
R4#show ip bgp summary
BGP router identifier 10.0.0.13, local AS number 2461
BGP table version is 2, main routing table version 2
1 network entries using 117 bytes of memory
1 path entries using 52 bytes of memory
2/1 BGP path/bestpath attribute entries using 248 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 441 total bytes of memory
BGP activity 13/12 prefixes, 13/12 paths, scan interval 60 secs


Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.9        4  2497     363     351        2    0    0 00:21:06        1
10.0.0.14       4  2461     253     261        2    0    0 00:21:04        0
R4#


========
R5#show ip bgp summary
BGP router identifier 10.0.0.14, local AS number 2461
BGP table version is 4, main routing table version 4
1 network entries using 117 bytes of memory
1 path entries using 52 bytes of memory
2/1 BGP path/bestpath attribute entries using 248 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 441 total bytes of memory
BGP activity 4/3 prefixes, 7/6 paths, scan interval 60 secs


Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.0.13       4  2461     260     252        4    0    0 00:21:20        1
R5#


=========


この状態でR-1のLocalセグメントである、192.168.0.0/24をR-1からR-5に広報するとします。


各ノードで以下のようなシンプルな設定をしています。



========
R1#show run | begin bgp
router bgp 55627
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 neighbor 10.0.0.2 remote-as 4766
 no auto-summary
!


========
R2#show run | begin bgp
router bgp 4766
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 neighbor 10.0.0.1 remote-as 55627
 neighbor 10.0.0.6 remote-as 2497
 no auto-summary
!


========
R3#show run | begin bgp
router bgp 2497
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 neighbor 10.0.0.5 remote-as 4766
 neighbor 10.0.0.10 remote-as 2461
 no auto-summary
!


========
R4#show run | begin bgp
router bgp 2461
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 neighbor 10.0.0.9 remote-as 2497
 neighbor 10.0.0.14 remote-as 2461
 no auto-summary
!


========
R5#show run | begin bgp
router bgp 2461
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.0.0.13 remote-as 2461
 no auto-summary
!


========



この状態で、R-3、R-4でルーティングテーブルをみます。



========
R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 2 subnets
C       10.0.0.8 is directly connected, FastEthernet1/0
C       10.0.0.4 is directly connected, FastEthernet0/0
B    192.168.0.0/24 [20/0] via 10.0.0.5, 00:03:56
R3#
R3#show ip bgp
BGP table version is 6, local router ID is 10.0.0.9
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.0.0      10.0.0.5                               0 4766 55627 i
R3#


========
R4#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 2 subnets
C       10.0.0.8 is directly connected, FastEthernet0/0
C       10.0.0.12 is directly connected, FastEthernet1/0
B    192.168.0.0/24 [20/0] via 10.0.0.9, 00:03:54
R4#
R4#
R4#show ip bgp
BGP table version is 2, local router ID is 10.0.0.13
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.0.0      10.0.0.9                               0 2497 4766 55627 i
R4#


========

R-4まではR-1のLocalセグメントがe-bgpにのって広報されています。


次にR-4とR-5をみます。


========
R4#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 2 subnets
C       10.0.0.8 is directly connected, FastEthernet0/0
C       10.0.0.12 is directly connected, FastEthernet1/0
B    192.168.0.0/24 [20/0] via 10.0.0.9, 00:03:54
R4#
R4#
R4#show ip bgp
BGP table version is 2, local router ID is 10.0.0.13
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.0.0      10.0.0.9                               0 2497 4766 55627 i
R4#


========
R5#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.12 is directly connected, FastEthernet0/0
R5#
R5#show ip bgp
BGP table version is 5, local router ID is 10.0.0.14
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
* i192.168.0.0      10.0.0.9                 0    100      0 2497 4766 55627 i
R5#


========

R-4では192.168.0.0/24がルーティングテーブル上に反映されているにも関わらず、R-5ではルーティングテーブル上に反映されていません。


R-5のshow ip bgpをみるとNextHopが10.0.0.9となっています。


R-5には10.0.0.8/30のセグメントがありませんので、当然、NextHopである10.0.0.9への経路情報も持っていません。


したがって、R-5のルーティングテーブル上にはせっかくR-4から受信した192.168.0.0/24への経路情報がルーティングテーブルに反映されないのです。



では、なぜこのようなことが起きるのでしょうか。


BGPではe-bgpで学習した外部経路(他ASからの経路)をi-bgpへ転送する時にデフォルトでNext-Hopを変更しないからです。


これを回避する方法として、最も簡単な方法は10.0.0.9へのstatic routeを設定する方法です。



========
R5#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.12 is directly connected, FastEthernet0/0
R5#
R5#
R5#show ip bgp
BGP table version is 7, local router ID is 10.0.0.14
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
* i192.168.0.0      10.0.0.9                 0    100      0 2497 4766 55627 i
R5#


========
R5(config)#
R5(config)#ip route 10.0.0.0 255.0.0.0 fa
R5(config)#ip route 10.0.0.0 255.0.0.0 fastEthernet 0/0
R5(config)#end
R5#


========
R5#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C       10.0.0.12/30 is directly connected, FastEthernet0/0
S       10.0.0.0/8 is directly connected, FastEthernet0/0
B    192.168.0.0/24 [200/0] via 10.0.0.9, 00:00:18
R5#
R5#show ip bgp
BGP table version is 8, local router ID is 10.0.0.14
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
*>i192.168.0.0      10.0.0.9                 0    100      0 2497 4766 55627 i
R5#


========

このように、192.168.0.0/24のNext-Hop向けのstatic routeを設定すれば192.168.0.0/24への経路がベストパスに変わり(show ip bgpの>部分)、ルーティングテーブルに反映されます。



ただ、この方法ではe-bgpから学習し、i-bgpへ広告する経路情報全てでstatic routeを設定しなくてはなりません。


冒頭でも書いたように、BGPは主にキャリア系ネットワークで非常によく使用されるため経路数も数万単位で広告されます。


数万の経路情報一つ一つのstatic routeを記載していてはとても運用に耐えられるネットワークとはいえません。


そこで、static routeの代わりにnext-hop-selfが登場します。


next-hop-selfとは、i-bgpへ経路情報を広告する際にNext-Hopを書き換えて広告する機能です。


今回の例でいうと、R-4からR-5へ経路を広告する際にNext-Hopを書き換えて広告することになります。



next-hop-selfは各Neighborごとに設定します。


========
R4#show run | begin bgp
router bgp 2461
 no synchronization
 bgp log-neighbor-changes
 network 192.168.0.0
 neighbor 10.0.0.9 remote-as 2497
 neighbor 10.0.0.14 remote-as 2461
 no auto-summary
!


========
R4(config)#
R4(config)#router bgp 2461
R4(config-router)#neighbor 10.0.0.14 next-hop-self
R4(config-router)#end
R4#


========
R5#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route


Gateway of last resort is not set


     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.12 is directly connected, FastEthernet0/0
B    192.168.0.0/24 [200/0] via 10.0.0.13, 00:00:32
R5#
R5#show ip bgp
BGP table version is 10, local router ID is 10.0.0.14
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete


   Network          Next Hop            Metric LocPrf Weight Path
*>i192.168.0.0      10.0.0.13                0    100      0 2497 4766 55627 i
R5#


========
192.168.0.0/24へのnext-hopが10.0.0.9から10.0.0.13に変更されベストパスとなりました。


これによって、192.168.0.0/24がルーティングテーブルに反映されます。


 


 


 

PR

COMMENT

NAME
TITLE
MAIL(非公開)
URL
EMOJI
Vodafone絵文字 i-mode絵文字 Ezweb絵文字
COMMENT
PASS(コメント編集に必須です)
SECRET
管理人のみ閲覧できます

カレンダー

05 2024/06 07
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

忍者カウンター

Copyright ©  -- しこてぃっしゅβ --  All Rights Reserved
Design by CriCri / Photo by Geralt / powered by NINJA TOOLS / 忍者ブログ / [PR]