Setting a BGP4 route MED to equal the next-hop route IGP metric

You can set the MED of the advertised BGP route to the IGP metric of the next hop route. This setting works only with the outbound route map used with a BGP neighbor. You can use this configuration with BGP shortcuts (IPoMPLS) and IPv4 or IPv6 address families in default or user VRFs.

About this task

The following task shows how to set the route MED to the same value as the IGP metric of the BGP4 next-hop route.

Procedure

  1. From privileged EXEC mode, enter global configuration mode.
    device# configure terminal
  2. Configure a route map to permit the destination network.
    device(config)# route-map medroute permit 1
    This example creates a route map named medroute that allows a matching pattern and enters configuration mode for the route-map sequence number 1.
    Note

    Note

    Route-map deny sequences are not advertised; deny configurations are ignored.
  3. Set the metric type for the routes to the same value as the IGP metric of the BGP4 next-hop route.
    device(config-routemap-medroute/permit/1)# set metric-type internal
  4. Return to privileged EXEC mode.
    device(config-routemap-medroute/permit/1)# end
  5. From privileged EXEC mode, enter global configuration mode.
    device# configure terminal
  6. Access BGP router configuration mode.
    device(config)# router bgp
  7. Specify the BGP autonomous system number (ASN) where the device resides.
    device(config-bgp-router)# local-as 666
  8. Specify the autonomous system (AS) in which a remote neighbor resides
    device(config-bgp-router)# neighbor 10.11.12.13 remote-as 100
  9. Enable BGP IPv4 address-family configuration mode.
    device(config-bgp-router)# address-family ipv4 unicast
  10. Apply the medroute route map to an outgoing route from 10.11.12.13.
    device(config-bgp-ipv4u)# neighbor 10.11.12.13 route-map out medroute
  11. Return to privileged EXEC mode.
    device(config-bgp-ipv4u)# end

Example

The following example shows the configuration in the previous steps.

device# configure terminal
device(config)# route-map medroute permit 1
device(config-routemap-medroute/permit/1)# set metric-type internal
device(config-routemap-medroute/permit/1)# end
device# configure terminal
device(config)# router bgp
device(config-bgp-router)# local-as 666
device(config-bgp-router)# neighbor 10.11.12.13 remote-as 100
device(config-bgp-router)# address-family ipv4 unicast
device(config-bgp-ipv4u)# neighbor 10.11.12.13 route-map out medroute

What to do next

To display the MED for the route, use the show ip bgp neighbors advertised-routes command.
device# show ip bgp neighbors 10.11.12.13 advertised-routes
       There are 1 routes advertised to neighbor 10.11.12.13
Status A:AGGREGATE B:BEST b:NOT-INSTALLED-BEST E:EBGP I:IBGP L:LOCAL x:BEST-
EXTERNAL
       Prefix             Next Hop                 MED        LocPrf     Weight Status
1      99.99.99.0/24      10.11.12.13              14                    0      BEx
         AS_PATH: 666 100

If any dynamic change in the IGP cost of next hop occurs after applying the outbound route map to the BGP neighbor, the change is not reflected in the MED field implicitly. Use clear ip bgp neighbor command with the soft-outbound option to reflect the change.

device# clear ip bgp neighbor 10.11.12.13 soft-outbound