Local preference controls where your traffic leaves your AS. MED (Multi-Exit Discriminator) tries to control where traffic enters your AS — by suggesting to your neighbor which of your multiple connections they should prefer. The key word is "suggesting" — MED is optional non-transitive, evaluated at step 6 of best path selection, and your neighbor is free to ignore it entirely.
How MED Works
- Direction: Set on outbound advertisements to an eBGP peer. The receiving AS uses it to choose between multiple entry points into your network.
- Value: Lower is better (opposite of local-pref). Default is 0 when explicitly set, or missing (treated as 0 or infinity depending on config).
- Comparison scope: By default, MED is only compared between paths received from the same neighboring AS. Paths from different ASes ignore each other's MED.
- Transitivity: Non-transitive — MED is only meaningful to the directly connected AS. It's not passed further.
Configuration
Set MED on outbound to suggest which entry point ISP-A should prefer:
! R1-HQ: prefer this entry point (lower MED = better)
route-map TO-ISP-A permit 10
set metric 100
!
router bgp 65001
neighbor 172.16.0.2 route-map TO-ISP-A outIf you have a second border router (R2-HQ) also peering with ISP-A, set a higher MED there:
! R2-HQ: less preferred entry point
route-map TO-ISP-A permit 10
set metric 200
!
router bgp 65001
neighbor 172.16.0.4 route-map TO-ISP-A outISP-A now sees the same prefix from two entry points: R1-HQ with MED 100 and R2-HQ with MED 200. At step 6 of best path selection, ISP-A prefers R1-HQ (lower MED).
Setting MED from IGP Metric
A common pattern is to set MED to the IGP metric, so external traffic naturally flows to the closest entry point:
route-map SET-MED-FROM-IGP permit 10
set metric-type internal
!
router bgp 65001
neighbor 172.16.0.2 route-map SET-MED-FROM-IGP outOr use the redistribute or network command behavior: when a BGP route is originated from an IGP route, the IGP metric is automatically carried as the MED (unless overridden).
MED Comparison Rules
This is where MED gets tricky:
Default: Same-AS Comparison Only
By default, MED is only compared between paths learned from the same neighboring AS. If R1-HQ learns 100.64.0.0/18 from both ISP-A (AS 65010, MED 100) and ISP-B (AS 65020, MED 50), MED is NOT compared because the paths come from different ASes.
! Enable comparison across all ASes
R1-HQ(config-router)# bgp always-compare-medWith bgp always-compare-med, MED is compared regardless of the originating AS. This is commonly needed in networks that peer at multiple IXPs or have complex multi-AS peering arrangements.
Missing MED Treatment
What if one path has a MED and another doesn't? By default, a missing MED is treated as 0 (best possible). This can cause unexpected behavior:
! Treat missing MED as the worst (highest value)
R1-HQ(config-router)# bgp bestpath med missing-as-worstWith missing-as-worst, paths without MED are treated as MED 4294967295 (max uint32), making them the least preferred. This is generally a safer default in production.
Why MED Is "Just a Suggestion"
MED is evaluated at step 6 — after weight (1), local-pref (2), locally originated (3), AS-path length (4), and origin (5). If your neighbor has set local-pref on their inbound route-map, or if the AS-path lengths differ, MED never gets a chance to influence the decision.
In practice, many ISPs configure inbound local-pref on customer sessions, effectively overriding any MED the customer sets. MED is most effective when:
- Both paths have the same local-pref on the receiving side
- Both paths have the same AS-path length
- The receiving AS actually pays attention to MED (some strip it on ingress)
Verification
! What ISP-A sees for our prefix
ISP-A-PE1# show ip bgp 10.1.0.0/16
BGP routing table entry for 10.1.0.0/16, version 34
Paths: (2 available, best #1, table default)
65001
172.16.0.1 from 172.16.0.1 (1.1.1.1)
Origin IGP, metric 100, valid, external, best
65001
172.16.0.5 from 172.16.0.5 (2.2.2.2)
Origin IGP, metric 200, valid, externalISP-A prefers the path via 172.16.0.1 (R1-HQ) because MED 100 < 200.
! Verify MED on our outbound advertisements
R1-HQ# show ip bgp neighbors 172.16.0.2 advertised-routes
Network Next Hop Metric LocPrf Weight Path
*> 10.1.0.0/16 172.16.0.1 100 32768 iMED vs Other Inbound Traffic Engineering Tools
| Tool | Scope | Strength |
|---|---|---|
| MED | Single neighboring AS | Weak — only a suggestion, evaluated at step 6 |
| AS-Path Prepending | All ASes | Moderate — affects step 4 globally, but crude |
| Communities | Depends on upstream policy | Strong — if upstream supports action communities (e.g., set local-pref) |
| More-specific prefixes | Global | Strongest — longest match always wins in forwarding |
For reliable inbound traffic engineering, communities (if supported by your upstream) or more-specific prefix advertisements are more effective than MED. See BGP AS-Path Prepending for the next option.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| MED set but neighbor ignoring it | Neighbor's local-pref or AS-path length difference decides before step 6 | MED can't override higher-priority steps. Use communities or AS-path prepending instead. |
| MED not being compared between paths from different ASes | Default behavior — MED only compared within same AS | Enable bgp always-compare-med if cross-AS comparison is needed. |
| Path without MED winning over path with lower MED | Missing MED treated as 0 (best) by default | Configure bgp bestpath med missing-as-worst. |
Key Takeaways
- MED suggests to a neighboring AS which entry point to prefer — lower MED is better. But it's only evaluated at step 6 and can be overridden by local-pref, weight, or AS-path length.
- By default, MED is only compared between paths from the same AS. Use
bgp always-compare-medfor cross-AS comparison. - MED is non-transitive — it only reaches your direct neighbor, not their upstreams.
- For stronger inbound traffic control, use communities (if your upstream supports them) or selective prefix advertising over MED.
- Configure
bgp bestpath med missing-as-worstto avoid paths with no MED unexpectedly winning.