(NW)BGP AS Path Prependやってみる

投稿者: | 2022年2月23日

皆さんこんにちは。今回はBGPの勉強ということでBGPを使った経路制御をやってみたいと思います。
BGP自体よくわかっていませんがとりあえずやってみよう精神でやってみます。最近クラウドとオンプレの接続で見かけることが多くなり業務上も知っておく必要が出てきたのでBGP周りの勉強を始めたところです。
とりあえず興味が向いたところからやっていこうと思います。

実験構成

使用機材 : Cisco catalyst 3750 x 5

実験内容

  1. RT5(50.0.0.1) -> RT1(10.0.0.1)の疎通ができるようにBGPの設定をする
  2. 「RT5 -> RT2 -> RT1」の経路で疎通確認をする
  3. AS Path Prependの設定を行って「RT5 -> RT4 -> RT3 -> RT1」の経路で疎通確認をする

AS50に対してAS10への経路制御を実施したいと思います。

設定

!!!
!!! RT1
!!!

!
ip routing
!
interface Loopback0
 ip address 10.0.0.1 255.255.255.0
!
interface GigabitEthernet2/0/23
 no switchport
 ip address 1.1.1.1 255.255.255.0
!
interface GigabitEthernet2/0/24
 no switchport
 ip address 2.2.2.1 255.255.255.0
!
router bgp 10
 bgp log-neighbor-changes
 network 10.0.0.0 mask 255.255.255.0
 neighbor 1.1.1.2 remote-as 20
 neighbor 2.2.2.3 remote-as 30
!
!!!
!!! RT2
!!!
!
ip routing
!
interface GigabitEthernet1/0/23
 no switchport
 ip address 1.1.1.2 255.255.255.0
!
interface GigabitEthernet1/0/24
 no switchport
 ip address 3.3.3.2 255.255.255.0
!
router bgp 20
 bgp log-neighbor-changes
 neighbor 1.1.1.1 remote-as 10
 neighbor 3.3.3.5 remote-as 50
 no auto-summary
!
!!!
!!!RT3
!!!
!
ip routing
!
interface GigabitEthernet1/0/23
 no switchport
 ip address 2.2.2.3 255.255.255.0
!
interface GigabitEthernet1/0/24
 no switchport
 ip address 4.4.4.3 255.255.255.0
!
router bgp 30
 no synchronization
 neighbor 2.2.2.1 remote-as 10
 neighbor 4.4.4.4 remote-as 40
 no auto-summary
!
!!!
!!!RT4
!!!
!
ip routing
!
interface GigabitEthernet1/0/23
 no switchport
 ip address 4.4.4.4 255.255.255.0
!
interface GigabitEthernet1/0/24
 no switchport
 ip address 5.5.5.4 255.255.255.0
!
router bgp 40
 no synchronization
 neighbor 4.4.4.3 remote-as 30
 neighbor 5.5.5.5 remote-as 50
 no auto-summary
!
!!!
!!!RT5
!!!
!
ip routing
!
interface GigabitEthernet1/0/23
 no switchport
 ip address 5.5.5.5 255.255.255.0
!
interface GigabitEthernet1/0/24
 no switchport
 ip address 3.3.3.5 255.255.255.0
!
router bgp 50
 no synchronization
 network 50.0.0.0 mask 255.255.255.0
 neighbor 3.3.3.2 remote-as 20
 neighbor 5.5.5.4 remote-as 40
 no auto-summary
!

疎通確認1

RT5のルーティングテーブルにBGPで広告された10.0.0.0/24の経路が載ってます。

RT5#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

     50.0.0.0/24 is subnetted, 1 subnets
C       50.0.0.0 is directly connected, Loopback0
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, GigabitEthernet1/0/24
     5.0.0.0/24 is subnetted, 1 subnets
C       5.5.5.0 is directly connected, GigabitEthernet1/0/23
     10.0.0.0/24 is subnetted, 1 subnets
B       10.0.0.0 [20/0] via 3.3.3.2, 00:01:03
RT5#

ベストパスにはパス数の少ないRT2を通るようになっています。

RT5#show ip bgp 10.0.0.1
BGP routing table entry for 10.0.0.0/24, version 5
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  40 30 10
    5.5.5.4 from 5.5.5.4 (5.5.5.4)
      Origin IGP, localpref 100, valid, external
  20 10
    3.3.3.2 from 3.3.3.2 (3.3.3.2)
      Origin IGP, localpref 100, valid, external, best
RT5#

10.0.0.1への疎通があることを確認OKです。

RT5#ping 10.0.0.1 source 50.0.0.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds:
Packet sent with a source address of 50.0.0.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/8 ms
RT5#

AS Path Prepend設定の追加

それでは、RT1からRT2向けにASパス数を意図的に追加した状態で広報を行うように設定を追加します。

!!!
!!!RT1
!!!
!
ip prefix-list PRE-AS seq 5 permit 10.0.0.0/24
!
route-map R-ASPRE permit 10
 match ip address prefix-list PRE-AS
 set as-path prepend 10 10
!
route-map R-ASPRE permit 20
!
!
router bgp 10
 neighbor 1.1.1.2 route-map R-ASPRE out
!

route-mapとprefix-listをつかってRT2向けの経路広報にASパス「10 10」を追加しています。これでRT5上でベストパスが変更されるはずです。それでは確認していきます。

疎通確認2

RT1の経路が更新されています。

RT5#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

     50.0.0.0/24 is subnetted, 1 subnets
C       50.0.0.0 is directly connected, Loopback0
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, GigabitEthernet1/0/24
     5.0.0.0/24 is subnetted, 1 subnets
C       5.5.5.0 is directly connected, GigabitEthernet1/0/23
     10.0.0.0/24 is subnetted, 1 subnets
B       10.0.0.0 [20/0] via 5.5.5.4, 00:03:51
RT5#
RT5#show ip bgp 10.0.0.1
BGP routing table entry for 10.0.0.0/24, version 6
Paths: (2 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  40 30 10
    5.5.5.4 from 5.5.5.4 (5.5.5.4)
      Origin IGP, localpref 100, valid, external, best
  20 10 10 10
    3.3.3.2 from 3.3.3.2 (3.3.3.2)
      Origin IGP, localpref 100, valid, external
RT5#

10.0.0.1あての経路がRT2からRT4を経由するようにベストパスが変わってますね。

RT5#show ip bgp
BGP table version is 6, local router ID is 50.0.0.1
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
*> 10.0.0.0/24      5.5.5.4                                0 40 30 10 i
*                   3.3.3.2                                0 20 10 10 10 i
*> 50.0.0.0/24      0.0.0.0                  0         32768 i
RT5#

それでは疎通確認をします。

RT5#ping 10.0.0.1 source 50.0.0.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds:
Packet sent with a source address of 50.0.0.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/5/9 ms
RT5#

疎通OKです。

今回はBGPの経路制御を実施してみました。普段ルーティングを設定する機会はないのですが、クラウドとオンプレの経路がどうなっているかを考慮する必要がある機会は増えてきました。このほかにもオンプレ/クラウドの接続周りでいろいろな技術が使われているので気が向いたらまた手を動かしながら調べてみようと思います。BGPに関してはAS Path Prepend以外にも経路制御の方法があるみたいなのでその辺もやってみようかと思います。

それではまた。

参考

BGP AS_PATH – Cisco Config

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です