PacketLab
BGP · Attributes and Path Selection

BGP MED

Suggest a preferred entry into an AS with a lower metric, then verify whether the neighboring AS actually selects it.

Two entries into one AS

R1 and R3 in AS 65010 advertise the same /24 to R2 in AS 65020. Because both candidates come from the same neighboring AS, the ordinary MED comparison applies when earlier criteria tie.

Lab topologyIllustrative network
.1 / .2 · eBGP.5 / .6 · eBGPR1AS 65010R2AS 65020R3AS 65010
Solid lines: physical links. Link labels use the last octet of 192.0.2.x; every link is a separate /30. AS labels identify the protocol relationship. Loopback0 is 10.255.0.N/32 for router RN. Exact interfaces and subnets are listed below.
LinkFirst endpointSecond endpoint
R1–R2R1 GigabitEthernet1: 192.0.2.1/30R2 GigabitEthernet1: 192.0.2.2/30
R2–R3R2 GigabitEthernet2: 192.0.2.5/30R3 GigabitEthernet1: 192.0.2.6/30
Complete baseline configurations

R1

hostname R1
ip cef
interface Loopback0
 ip address 10.255.0.1 255.255.255.255
exit
interface Loopback10
 ip address 198.51.100.1 255.255.255.0
exit
interface GigabitEthernet1
 ip address 192.0.2.1 255.255.255.252
 no shutdown
exit
router bgp 65010
 bgp router-id 10.255.0.1
 no bgp default ipv4-unicast
 neighbor 192.0.2.2 remote-as 65020
 address-family ipv4 unicast
  no auto-summary
  neighbor 192.0.2.2 activate
  network 198.51.100.0 mask 255.255.255.0
 exit-address-family
end

R2

hostname R2
ip cef
interface Loopback0
 ip address 10.255.0.2 255.255.255.255
exit
interface GigabitEthernet1
 ip address 192.0.2.2 255.255.255.252
 no shutdown
exit
interface GigabitEthernet2
 ip address 192.0.2.5 255.255.255.252
 no shutdown
exit
router bgp 65020
 bgp router-id 10.255.0.2
 no bgp default ipv4-unicast
 neighbor 192.0.2.1 remote-as 65010
 neighbor 192.0.2.6 remote-as 65010
 address-family ipv4 unicast
  no auto-summary
  neighbor 192.0.2.1 activate
  neighbor 192.0.2.6 activate
 exit-address-family
end

R3

hostname R3
ip cef
interface Loopback0
 ip address 10.255.0.3 255.255.255.255
exit
interface Loopback10
 ip address 198.51.100.3 255.255.255.0
exit
interface GigabitEthernet1
 ip address 192.0.2.6 255.255.255.252
 no shutdown
exit
router bgp 65010
 bgp router-id 10.255.0.3
 no bgp default ipv4-unicast
 neighbor 192.0.2.5 remote-as 65020
 address-family ipv4 unicast
  no auto-summary
  neighbor 192.0.2.5 activate
  network 198.51.100.0 mask 255.255.255.0
 exit-address-family
end
Outputs are illustrative, not recorded router results. Each lesson is a separate lab. Allow updates to converge after changes; the selected baseline path is an example when all earlier criteria tie.
R2# show ip bgp 198.51.100.0/24
     Network          Next Hop        Metric LocPrf Weight Path
*>   198.51.100.0/24  192.0.2.1            0             0 65010 i
*                     192.0.2.6            0             0 65010 i

MED is optional non-transitive. Lower is preferred when the paths are comparable. The Metric column displays it in these tables.

Advertise different metrics

On R1, set the target prefix’s exported MED to 200:

ip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map ENTRY-METRIC permit 10
 match ip address prefix-list TARGET
 set metric 200
exit
route-map ENTRY-METRIC permit 20
exit
router bgp 65010
 address-family ipv4 unicast
  neighbor 192.0.2.2 route-map ENTRY-METRIC out
 exit-address-family

On R3, advertise MED 50:

ip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map ENTRY-METRIC permit 10
 match ip address prefix-list TARGET
 set metric 50
exit
route-map ENTRY-METRIC permit 20
exit
router bgp 65010
 address-family ipv4 unicast
  neighbor 192.0.2.5 route-map ENTRY-METRIC out
 exit-address-family
R1# clear ip bgp 192.0.2.2 soft out
R3# clear ip bgp 192.0.2.5 soft out

Observe the preference

R2# show ip bgp 198.51.100.0/24
     Network          Next Hop        Metric LocPrf Weight Path
*    198.51.100.0/24  192.0.2.1          200             0 65010 i
*>                    192.0.2.6           50             0 65010 i
R2# show ip route 198.51.100.0
Routing entry for 198.51.100.0/24
  Known via "bgp 65020", distance 20, metric 50
  * 192.0.2.6, via GigabitEthernet2

R2 chooses R3’s lower value. This influences traffic arriving from R2; the receiving AS can still apply earlier local policy that overrides the hint.

Comparison and propagation

Received MED can be carried internally within the neighboring AS, but it is not simply passed onward to another external AS. By default these examples compare MED for paths from the same neighboring AS, not arbitrary unrelated providers. Missing MED is normally treated as zero in this command family; configuration can change that behavior.

MED is neither an end-to-end sum nor the local IGP cost to a next hop. Always-compare-med and deterministic-MED change aspects of comparison and grouping; do not enable them merely to make a diagram’s preferred arrow win.

Restore the baseline

Detach ENTRY-METRIC on both originators and refresh their external advertisements.

R1

router bgp 65010
 address-family ipv4 unicast
  no neighbor 192.0.2.2 route-map ENTRY-METRIC out
 exit-address-family

R3

router bgp 65010
 address-family ipv4 unicast
  no neighbor 192.0.2.5 route-map ENTRY-METRIC out
 exit-address-family
R1# clear ip bgp 192.0.2.2 soft out
R3# clear ip bgp 192.0.2.5 soft out
R2# show ip bgp 198.51.100.0/24
     Network          Next Hop        Metric LocPrf Weight Path
*>   198.51.100.0/24  192.0.2.1            0             0 65010 i
*                     192.0.2.6            0             0 65010 i

Key Takeaways

  • Lower MED is preferred among comparable candidates after earlier checks tie.
  • The Metric column shows MED in these examples.
  • MED normally compares routes from the same neighboring AS.
  • A receiving AS can carry MED internally but does not blindly pass it to a third external AS.
  • MED is a preference hint, not an accumulated end-to-end IGP cost.

MED Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. Comparable paths have MED 200 and 50. Which wins with earlier checks tied?
2. Which comparison is normally eligible for MED?
3. What does set metric affect in this BGP policy?
4. Can higher remote LOCAL_PREF defeat your lower MED hint?
5. Is MED the sum of all interior costs along the end-to-end path?
6. What is the normal missing-MED treatment in this command family?
Protocol and command references

Best-path comparison rules · BGP path attributes · Router-symbol attribution.