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.
device# configure terminal
device(config)# route-map medroute permit 1
Note
Route-map deny sequences are not advertised; deny configurations are ignored.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
device(config-bgp-ipv4u)# end
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
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