Skip to content

MikroTik で BGP の属性(MED / LOCAL_PREF)を検証してみる

前回は Mikrotik 製品で BGP の Peering だけ、設定してみました。今回は属性(Attribute)のうち、非常にメジャーな MED(Multi-Exit Discriminator)と LP(Local Preference)を設定してみました。

所感

先に所感を記載します。的はずれな点もあるかも知れません。

  • 良いと思う点
    • 設定は非常に簡易だった。
    • 動作も特に問題無かった。MED や LP という、ありふれた属性しかテストしていないせいかも知れないが、Cisco との相互運用においても試した限りは問題無かった。
  • 悪いと思う点
    • 「WebUI → Routing → BGP → Peers → 該当 Peer を選択 → OK をクリック」すると、何も設定変更していないとしても必ず、BGP Peer が Down/Up してしまう。これは致命的で、使い物にならない。CLI であれば Peer の設定を変更しても、特に Down/Up は発生しなかった。よって、実際の運用で BGP Peer の設定をするのであれば WebUI を利用してはならない。

検証環境

構成は以下の通りです。

file

検証で利用したルータは以下の通りです。

番号 メーカー 型番 OS バージョン
1 Cisco WS-C3750-24TS 12.2(46)SE
2 Mikrotik CCR1009-8G-1S-1S+ 6.29.1

初期設定のコンフィグを見ると分かりますが、Cisco では Loopback 1 〜 10 を 10.0.1.0/24 〜 10.0.10.0/24 で設定し、network コマンドで BGP で広告させています。

初期設定

1-Cisco の初期設定

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
hostname 1-Cisco
!
ip routing
!
interface Loopback1
 ip address 10.0.1.1 255.255.255.0
!
interface Loopback2
 ip address 10.0.2.1 255.255.255.0
!
interface Loopback3
 ip address 10.0.3.1 255.255.255.0
!
interface Loopback4
 ip address 10.0.4.1 255.255.255.0
!
interface Loopback5
 ip address 10.0.5.1 255.255.255.0
!
interface Loopback6
 ip address 10.0.6.1 255.255.255.0
!
interface Loopback7
 ip address 10.0.7.1 255.255.255.0
!
interface Loopback8
 ip address 10.0.8.1 255.255.255.0
!
interface Loopback9
 ip address 10.0.9.1 255.255.255.0
!
interface Loopback10
 ip address 10.0.10.1 255.255.255.0
!
interface FastEthernet1/0/1
 no switchport
 ip address 192.168.1.1 255.255.255.0
!
interface FastEthernet1/0/2
 no switchport
 ip address 192.168.2.1 255.255.255.0
!
router bgp 65001
 no synchronization
 no auto-summary
 !
 network 10.0.1.0 mask 255.255.255.0
 network 10.0.2.0 mask 255.255.255.0
 network 10.0.3.0 mask 255.255.255.0
 network 10.0.4.0 mask 255.255.255.0
 network 10.0.5.0 mask 255.255.255.0
 network 10.0.6.0 mask 255.255.255.0
 network 10.0.7.0 mask 255.255.255.0
 network 10.0.8.0 mask 255.255.255.0
 network 10.0.9.0 mask 255.255.255.0
 network 10.0.10.0 mask 255.255.255.0
 !
 neighbor 192.168.1.2 remote-as 65002
 neighbor 192.168.2.2 remote-as 65002

2-CCR の初期設定

1
2
3
4
5
6
7
8
/ip address add address=192.168.1.2/24 interface=ether1
/ip address add address=192.168.2.2/24 interface=ether2
/ip address add address=192.168.3.2/24 interface=ether3
/system identity set name=2-CCR
/routing bgp instance set default as=65002
/routing bgp peer add remote-address=192.168.1.1 remote-as=65001 ttl=1
/routing bgp peer add remote-address=192.168.2.1 remote-as=65001 ttl=1
/routing bgp network add network=192.168.3.0/24

経路の確認

Cisco 側で BGP テーブルを確認します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
1-Cisco# show ip bgp
BGP table version is 13, local router ID is 10.0.10.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.1.0/24      0.0.0.0                  0         32768 i
*> 10.0.2.0/24      0.0.0.0                  0         32768 i
*> 10.0.3.0/24      0.0.0.0                  0         32768 i
*> 10.0.4.0/24      0.0.0.0                  0         32768 i
*> 10.0.5.0/24      0.0.0.0                  0         32768 i
*> 10.0.6.0/24      0.0.0.0                  0         32768 i
*> 10.0.7.0/24      0.0.0.0                  0         32768 i
*> 10.0.8.0/24      0.0.0.0                  0         32768 i
*> 10.0.9.0/24      0.0.0.0                  0         32768 i
*> 10.0.10.0/24     0.0.0.0                  0         32768 i
*> 192.168.3.0      192.168.1.2                            0 65002 i
*                   192.168.2.2                            0 65002 i

192.168.3.0/24 は AS 65002(Mikrotik 側)から AS 65001(Cisco 側)に広報された経路です。この経路の詳細を見てみます。Cisco 側から見た場合、NexpHop が 192.168.1.2 になっており、構成図上の「上側のルート」を通っているのが分かります。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
1-Cisco# show ip bgp 192.168.3.0/24
BGP routing table entry for 192.168.3.0/24, version 13
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Flag: 0x860
  Advertised to update-groups:
     1
  65002
    192.168.1.2 from 192.168.1.2 (192.168.1.2)
      Origin IGP, localpref 100, valid, external, best
  65002
    192.168.2.2 from 192.168.2.2 (192.168.1.2)
      Origin IGP, localpref 100, valid, external

MED 属性の付与

BGP のトラフィックコントロールでは代表的な MED 属性を付与してみます。設定の順序は以下の通りです。「Cisco では RouteMap」、「Mikrotik では Filter」と用語の違いがあるものの、概ねの設定手順は両者でほぼ共通です。

番号 Cisco の場合 Mikrotik の場合
1 付与したい属性を持った RouteMap を定義する 付与したい属性を持った Filter を定義する
2 定義した RouteMap を BGP Neighbor に適用する 定義した Filter を BGP Peer に適用する

今回は Mikrotik 側で対 Cisco 向けに以下の属性を設定します。

Peer アドレス IN OUT
192.168.1.1 MED 200 MED 200
192.168.2.1 MED 100 MED 100

図示すると以下の通りです。

file

Mikrotik での具体的な設定は以下の通りです。

1
2
3
4
/routing filter add chain=MED-100 protocol=bgp set-bgp-med=100
/routing filter add chain=MED-200 protocol=bgp set-bgp-med=200
/routing bgp peer set 0 in-filter=MED-200 out-filter=MED-200
/routing bgp peer set 1 in-filter=MED-100 out-filter=MED-100

1-Cisco 側での経路確認

AS 65002(Mikrotik)側から受信している経路である 192.168.3.0/24 ですが、Best Path の NextHop が 192.168.2.2(下側の経路)になっていることが分かります。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
1-Cisco# show ip bgp
BGP table version is 28, local router ID is 10.0.10.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.1.0/24      0.0.0.0                  0         32768 i
*> 10.0.2.0/24      0.0.0.0                  0         32768 i
*> 10.0.3.0/24      0.0.0.0                  0         32768 i
*> 10.0.4.0/24      0.0.0.0                  0         32768 i
*> 10.0.5.0/24      0.0.0.0                  0         32768 i
*> 10.0.6.0/24      0.0.0.0                  0         32768 i
*> 10.0.7.0/24      0.0.0.0                  0         32768 i
*> 10.0.8.0/24      0.0.0.0                  0         32768 i
*> 10.0.9.0/24      0.0.0.0                  0         32768 i
*> 10.0.10.0/24     0.0.0.0                  0         32768 i
*> 192.168.3.0      192.168.2.2            100             0 65002 i
*                   192.168.1.2            200             0 65002 i

より詳細に 192.168.3.0/24 を確認した結果は以下の通りです。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
1-Cisco# show ip bgp 192.168.3.0/24
BGP routing table entry for 192.168.3.0/24, version 28
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Flag: 0x10840
  Advertised to update-groups:
     1
  65002
    192.168.2.2 from 192.168.2.2 (192.168.1.2)
      Origin IGP, metric 100, localpref 100, valid, external, best
  65002
    192.168.1.2 from 192.168.1.2 (192.168.1.2)
      Origin IGP, metric 200, localpref 100, valid, external

2-CCR 側での経路確認

AS 65001(Cisco)側から受信している経路のうち、10.0.1.0/24 をピックアップして見てみます。192.168.1.1(上側)と 192.168.2.1(下側)から 10.0.1.0/24 を受信していますが、意図した通りに MED 値が付与されており、結果として 192.168.2.1(下側)の経路が「Active(A 表示)」になっていることが分かります。

1
2
3
4
5
6
7
8
[admin@2-CCR] > /ip route print detail
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
 0 ADb  dst-address=10.0.1.0/24 gateway=192.168.2.1 gateway-status=192.168.2.1 reachable via  ether2 distance=20
        scope=40 target-scope=10 bgp-as-path="65001" bgp-med=100 bgp-origin=igp received-from=peer2

 1  Db  dst-address=10.0.1.0/24 gateway=192.168.1.1 gateway-status=192.168.1.1 reachable via  ether1 distance=20
        scope=40 target-scope=10 bgp-as-path="65001" bgp-med=200 bgp-origin=igp received-from=peer1

LP 属性の付与

次は MED 同様、BGP ではメジャーな Local Preference(LOCAL_PREF、または LP)を試してみます。MED と違い、LP は IN 側にしか付与出来ません。よって、属性は以下のようにします。

Peer アドレス IN OUT
192.168.1.1 LP 200 MED 200
192.168.2.1 LP 100 MED 100

図示すると以下の通りです。

file

Mikrotik での具体的な設定は以下の通りです。

1
2
3
4
/routing filter add chain=LP-150 protocol=bgp set-bgp-local-pref=150
/routing filter add chain=LP-250 protocol=bgp set-bgp-local-pref=250
/routing bgp peer set 0 in-filter=LP-150 out-filter=MED-200
/routing bgp peer set 1 in-filter=LP-250 out-filter=MED-100

1-Cisco 側での経路確認

Mikrotik 側からの広報経路は属性を変更していない為、特に何も変わっていません。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
1-Cisco# show ip bgp 192.168.3.0/24
BGP routing table entry for 192.168.3.0/24, version 14
Paths: (2 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  65002
    192.168.2.2 from 192.168.2.2 (192.168.1.2)
      Origin IGP, metric 100, localpref 100, valid, external, best
  65002
    192.168.1.2 from 192.168.1.2 (192.168.1.2)
      Origin IGP, metric 200, localpref 100, valid, external

2-CCR 側での経路確認

AS 65001(Cisco)側からの受信経路に対して MED では無く、LP を付与しましたので、受信経路を確認すると LP が付与されていることが分かります。

1
2
3
4
5
6
7
8
[admin@2-CCR] > /ip route print detail
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
 0 ADb  dst-address=10.0.1.0/24 gateway=192.168.2.1 gateway-status=192.168.2.1 reachable via  ether2 distance=20
        scope=40 target-scope=10 bgp-as-path="65001" bgp-local-pref=250 bgp-med=0 bgp-origin=igp received-from=peer2

 1  Db  dst-address=10.0.1.0/24 gateway=192.168.1.1 gateway-status=192.168.1.1 reachable via  ether1 distance=20
        scope=40 target-scope=10 bgp-as-path="65001" bgp-local-pref=150 bgp-med=0 bgp-origin=igp received-from=peer1