BGP MED属性控制路由选择示例

组网需求

  1. 所有路由器都配置BGP,Router A在AS 65008中,Router B和Router C在AS 65009中
  2. Router A与Router B之间运行EBGP,Router A和Router C之间运行IBGP
  3. 要求从AS 65008和AS 65009的流量优先通过Router C

组网拓扑

配置思路

  1. 配置各个路由器基本功能以及各个接口IP地址
  2. 配置Router B与Router C之间IBGP
  3. Router A与Router B、Router C之间配置EBGP
  4. 配置MED属性控制路由

配置命令

  1. 配置路由基本功能以及接口IP地址

    • Router A配置

      1
      2
      3
      4
      5
      6
      7
      8
      sys
      sys Router A
      int g0/0/0
      ip add 200.1.1.1 30
      int g0/0/1
      ip add 200.1.2.1 30
      int LoopBack 0
      ip add 1.1.1.1 32
  • Router B配置

    1
    2
    3
    4
    5
    6
    7
    8
    sys
    sys Router B
    int g0/0/0
    ip add 200.1.1.2 30
    int g0/0/2
    ip add 9.1.1.1 30
    int LoopBack 0
    ip add 2.2.2.2 32
  • Router C配置

    1
    2
    3
    4
    5
    6
    7
    8
    sys
    sys Router C
    int g0/0/1
    ip add 200.1.2.2 30
    int g0/0/2
    ip add 9.1.1.2 30
    int LoopBack 0
    ip add 3.3.3.3 32
  1. 配置IBGP

    • Router B配置

      1
      2
      3
      4
      sys
      bgp 65009
      router-id 2.2.2.2
      peer 9.1.1.2 as-number 65009
  • Router C配置

    1
    2
    3
    4
    sys
    bgp 65009
    router-id 3.3.3.3
    peer 9.1.1.1 as-number 65009
  1. 配置EBGP

    • Router A配置

      1
      2
      3
      4
      5
      sys
      bgp 65008
      router-id 1.1.1.1
      peer 200.1.1.2 as-number 65009
      peer 200.1.2.2 as-number 65009
  • Router B配置

    1
    2
    3
    sys
    bgp 65009
    peer 200.1.1.1 as-number 65008
  • Router C配置

    1
    2
    3
    sys
    bgp 65009
    peer 200.1.2.1 as-number 65008
  1. IBGP里的路由宣告给EBGP

    • Router B配置

      1
      2
      3
      4
      sys
      bgp 65009
      ipv4-family unicast
      network 9.1.1.0 30
  • Router C配置

    1
    2
    3
    4
    sys
    bgp 65009
    ipv4-family unicast
    network 9.1.1.0 30
  1. 配置MED属性(以Router B为例)

    • 设置路由策略

      1
      2
      3
      sys
      route-policy RouterB_MED permit node 10
      apply cost 100
  • 在BGP上应用路由策略

    1
    2
    3
    4
    sys
    bgp 65009
    ipv4-family unicast
    peer 200.1.1.1 route-policy RouterB_MED export

结果查看

  1. 没有配置MED属性前路由表

    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
    display bgp routing-table 9.1.1.0 30

    <Router A>dis bgp routing-table 9.1.1.0 30

    BGP local router ID : 1.1.1.1
    Local AS number : 65008
    Paths: 2 available, 1 best, 1 select
    BGP routing table entry information of 9.1.1.0/30:
    From: 200.1.1.2 (2.2.2.2)
    Route Duration: 00h02m32s
    Direct Out-interface: GigabitEthernet0/0/0
    Original nexthop: 200.1.1.2
    Qos information : 0x0
    AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, ac
    tive, pre 255
    Advertised to such 2 peers:
    200.1.1.2
    200.1.2.2
    BGP routing table entry information of 9.1.1.0/30:
    From: 200.1.2.2 (3.3.3.3)
    Route Duration: 00h00m27s
    Direct Out-interface: GigabitEthernet0/0/1
    Original nexthop: 200.1.2.2
    Qos information : 0x0
    AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, pre 255, not pre
    ferred for router ID
    Not advertised to any peer yet
  1. 配置MED属性后路由表

    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
    dispaly bgp routing-table 9.1.1.0 30

    <Router A>dis bgp routing-table 9.1.1.0 30

    BGP local router ID : 1.1.1.1
    Local AS number : 65008
    Paths: 2 available, 1 best, 1 select
    BGP routing table entry information of 9.1.1.0/30:
    From: 200.1.2.2 (3.3.3.3)
    Route Duration: 00h06m12s
    Direct Out-interface: GigabitEthernet0/0/1
    Original nexthop: 200.1.2.2
    Qos information : 0x0
    AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, ac
    tive, pre 255
    Advertised to such 2 peers:
    200.1.1.2
    200.1.2.2
    BGP routing table entry information of 9.1.1.0/30:
    From: 200.1.1.2 (2.2.2.2)
    Route Duration: 00h03m08s
    Direct Out-interface: GigabitEthernet0/0/0
    Original nexthop: 200.1.1.2
    Qos information : 0x0
    AS-path 65009, origin igp, MED 100, pref-val 0, valid, external, pre 255, not p
    referred for MED
    Not advertised to any peer yet
吴超 wechat
subscribe to my blog by scanning my public wechat account