16 MED
MED (Multi-Exit Discriminator) is an optional non-transitive attribute used to influence the inbound path into an AS from a directly connected neighboring AS. It is step 6 in the best-path algorithm.
Characteristics
- Influences the inbound path into your AS, but only for directly connected neighboring AS.
- Lower value wins: unlike Local Preference and Weight, a lower MED is more preferred.
- Range: 0 to 4294967295.
- Inherited from the metric of the original routing source (which is why the Cisco command to set it is
set metric). - Shared with a neighboring AS and propagated within that AS, but removed when that AS forwards the prefix to another AS. MED crosses only one AS boundary.
Why MED only reaches directly connected AS
MED is an optional non-transitive attribute, so it is stripped when a route leaves the AS that received it. It is shared with the directly connected neighbor and propagated inside that neighbor’s AS, but it does not travel transitively to more distant AS. This is the key difference from AS-PATH prepend.
Comparison with AS-PATH prepend
Both influence inbound traffic and both are configured outbound, but their reach differs:
| Property | MED | AS-PATH Prepend |
|---|---|---|
| Influences inbound | Yes | Yes |
| Configured | outbound | outbound |
| Reach | Directly connected AS only | Directly and indirectly connected AS |
| Preferred value | Lower | Shorter path |
Use prepend to influence a distant AS; use MED for a directly connected neighbor (typically your ISP).
The default comparison rule
By default, MED is only compared between routes coming from the same neighboring AS. If two routes come from different AS, MED is not compared, unless bgp always-compare-med is enabled. This is consistent with MED being a hint an AS gives its neighbor about which of its own links to prefer.
Typical use case
The canonical use of MED is an AS with multiple links to the same neighboring AS (hence “Multi-Exit”). You send a lower MED over the preferred link and a higher MED over the other; because lower wins, the neighbor enters through the link you prefer. This lets you tell a neighbor which of your entry points to use.
Missing MED behavior
When a route arrives without a MED attribute, Cisco by default treats it as 0 (the most preferred, since lower wins). The option bgp bestpath med missing-as-worst changes this to treat a missing MED as the worst (infinite) instead.
How it is applied
A route-map matches the target prefixes and sets the metric (which is the MED), applied outbound toward the neighboring AS.
Self-check
Q1 — Which MED value is preferred, and what does MED influence?
A) Higher wins; influences outbound path
B) Lower wins; influences inbound path from a directly connected AS
C) Higher wins; influences inbound path
D) Lower wins; influences the whole Internet
Respuesta
B is correct. A lower MED is preferred, and it influences the inbound path into your AS from a directly connected neighboring AS.
- A) False — lower wins, and MED influences inbound, not outbound.
- C) False — lower, not higher, is preferred.
- D) False — MED only reaches directly connected AS, not the whole Internet.
Q2 — How far does MED propagate?
A) Across all AS along the path
B) It crosses only one AS boundary and is then removed
C) It never leaves the local router
D) It is transitive like Community
Respuesta
B is correct. MED is optional non-transitive: shared with the directly connected AS and propagated inside it, but stripped when forwarded to another AS.
- A) False — that describes AS-PATH prepend’s reach, not MED’s.
- C) False — that describes Weight; MED is sent to the neighbor.
- D) False — MED is non-transitive, unlike Community.
Q3 — By default, MED is compared between routes only when they:
A) Come from different AS
B) Come from the same neighboring AS
C) Have the same Local Preference
D) Have the same next-hop
Respuesta
B is correct. By default MED is compared only between routes from the same neighboring AS, unless
bgp always-compare-medis enabled.
- A) False — routes from different AS are not compared by default.
- C) False — Local Preference equality is not the trigger.
- D) False — next-hop equality is not the trigger.
Q4 — What is the canonical use case for MED?
A) Preventing inter-AS loops
B) An AS with multiple links to the same neighboring AS, choosing which entry the neighbor should use
C) Setting the exit path for the whole AS
D) Overriding best-path on one router
Respuesta
B is correct. MED (Multi-Exit Discriminator) tells a neighbor which of your multiple links to that neighbor to prefer for inbound traffic.
- A) False — loop prevention is AS-PATH’s role.
- C) False — choosing the AS-wide exit is Local Preference’s role.
- D) False — single-router override is Weight’s role.