How does MED work, and what are the gotchas?
Show the answer
Say this first
MED (MULTI_EXIT_DISC) is a value you send to a neighbor AS to suggest which of your links it should use to
reach you: lower is better. It is only a hint, it sits below LOCAL_PREF and AS path length, and by default
Cisco compares MED only between paths from the same neighbor AS. Gotchas: a missing MED counts as 0, the best
value, unless bgp bestpath med missing-as-worst is set; results can depend on arrival order without
bgp deterministic-med; comparing across different ASes needs bgp always-compare-med.
Go deeper
Typical use: two links to the same provider
route-map ISP1-PRIMARY-OUT permit 10
match ip address prefix-list OUR-PREFIXES
set metric 10
!
route-map ISP1-BACKUP-OUT permit 10
match ip address prefix-list OUR-PREFIXES
set metric 50The provider sees both paths from AS 64500 and, if it honours MED, sends traffic down the MED 10 link. Its own local preference still comes first, and some providers reset customer MEDs.
Non-transitive
The receiving AS passes your MED to its iBGP peers but must not pass it to another AS.
Order dependence
Without deterministic-med, IOS compares paths pairwise starting from the newest. MED is skipped whenever the two
paths come from different ASes, so with three or more paths the result can change with arrival order. With
bgp deterministic-med, paths are grouped by neighbor AS, the best of each group is chosen, then groups are
compared. Configure it the same on every router in the AS.
Useful variants
set metric-type internal sets the MED to the IGP metric to the next hop, telling the neighbor which entry
point is closest to the destination inside your network.
They will ask next
Is MED compared before or after eBGP versus iBGP?
Before. MED is step 6, peer type is step 7.
Why do providers often ignore customer MEDs?
MED lets the customer push traffic onto expensive parts of the provider's network. Many providers prefer their own local preference rules or offer communities instead.
Traps
- Expecting MED to choose between two different ISPs. They never compare it across ASes by default.
- Expecting your MED to beat the neighbor's local preference.