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:

PropertyMEDAS-PATH Prepend
Influences inboundYesYes
Configuredoutboundoutbound
ReachDirectly connected AS onlyDirectly and indirectly connected AS
Preferred valueLowerShorter 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

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

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

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