BGP Attributes: MED

Introduction

In the previous post, I covered Local Preference – BGP’s tool for controlling outbound traffic from your AS. Now it’s time for the flip side: MED (Multi-Exit Discriminator), which influences inbound traffic into your AS.

While Local Preference tells your routers “use this exit,” MED tells your neighbors “use this entry.” It’s your way of saying to external autonomous systems: “Hey, if you want to reach my networks, I prefer you use this link over that one.”

The catch? MED is just a suggestion. Unlike Local Preference which you control within your own AS, MED depends on your neighbor honoring your preferences. Most well-behaved ASes do, but it’s not guaranteed.

Understanding MED

What is MED?

MED (Multi-Exit Discriminator) has these characteristics:

  • Also called: Metric, Cost (Cisco displays it as “Metric” in BGP tables)
  • Numeric value: Default is 0. Lower values are preferred (opposite of Local Preference!)
  • Direction: Controls inbound traffic (entries into your AS)
  • Scope: Sent to eBGP neighbors, but typically not passed beyond the neighboring AS
  • Propagation: Set outbound on routes advertised to eBGP neighbors

The Fundamental Asymmetry

This is a critical concept in BGP traffic engineering:

Outbound traffic (you control fully):
  ↓
  Use: Local Preference
  ↓
  Result: Your AS makes consistent exit decisions

Inbound traffic (you can only influence):
  ↓
  Use: MED
  ↓
  Result: Neighboring AS *may* honor your entry preferences

You have complete control over how traffic leaves your AS, but you can only suggest how it enters.

BGP Best Path Selection Revisited

MED appears much later in the best-path algorithm than Local Preference:

  1. Weight (highest wins) – Cisco-proprietary, local to the router only
  2. Local Preference (highest wins) – AS-wide coordination
  3. Locally originated routes (prefer routes originated by this router)
  4. AS-Path length (shortest wins)
  5. Origin type (IGP > EGP > Incomplete)
  6. MED (lowest wins) – comparing paths from the same neighboring AS
  7. eBGP over iBGP
  8. IGP metric to next-hop
  9. …additional tie-breakers

Since MED is at step 6, it can be overridden by Local Preference, AS-Path length, and Origin type. This is why MED is “just a suggestion” – the neighboring AS may have Local Preference policies that override your MED values.

Lower is Better

Unlike Local Preference, MED follows the lower is better rule:

  • MED 0 (default) = most preferred
  • MED 50 = less preferred
  • MED 100 = even less preferred
  • MED 200 = least preferred

Think of MED as a “cost” or “distance” metric – lower costs are better.

Lab Topology

Same topology from the Local Preference post:

  • AS 1000: R3, R4, R5, R6 (external AS from AS 2000’s perspective)
  • AS 2000: R7, R8, R9 (our AS – we want to influence how AS 1000 sends traffic to us)
Topology

AS 2000 has two entry points from AS 1000:

  • R7 receives traffic via 192.1.47.0/24 (link to R4)
  • R8 receives traffic via 192.1.48.0/24 (link to R4)

By default, AS 1000 (specifically R4) will make its own routing decision about which path to use when sending traffic to AS 2000’s networks. MED allows AS 2000 to express a preference.

Example: Set Preferred Entry Point Using MED

Requirement

AS 1000 should use the link between R4 and R8 as the preferred entry point when sending traffic into AS 2000.

From AS 2000’s perspective, we want AS 1000 to prefer sending traffic via R8 instead of R7.

Initial State (Before Configuration)

R4 (in AS 1000) has two paths to reach AS 2000’s networks:

R4#sh ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *    7.0.0.0          192.1.48.8                             0 2000 i
 *>                    192.1.47.7               0             0 2000 i
 *    8.0.0.0          192.1.47.7                             0 2000 i
 *>                    192.1.48.8               0             0 2000 i
 *    9.0.0.0          192.1.48.8                             0 2000 i
 *>                    192.1.47.7                             0 2000 i

Reading the output:

Network 7.0.0.0 (R7’s network):

  • Two paths: via 192.1.48.8 (R8) and via 192.1.47.7 (R7)
  • MED (Metric column): both show 0 (default)
  • Best path >: via 192.1.47.7 (R7’s direct link)

Network 8.0.0.0 (R8’s network):

  • Two paths: via 192.1.47.7 (R7) and via 192.1.48.8 (R8)
  • Best path >: via 192.1.48.8 (R8’s direct link)

Network 9.0.0.0 (R9’s network):

  • Two paths: via 192.1.48.8 (R8) and via 192.1.47.7 (R7)
  • Best path >: via 192.1.47.7 (R7)

R4 is splitting traffic. With equal MED values (both 0), R4 falls back to other tie-breakers in the best-path algorithm, likely the router-ID or some other factor. The path selection is inconsistent from AS 2000’s perspective.

Configuration

To influence AS 1000 to prefer the R8 entry point, we need to make R7’s advertisements less attractive by setting a higher (worse) MED value on R7’s outbound advertisements.

On R7, set MED on routes advertised to R4:

route-map SET-MED permit 10
 set metric 70

router bgp 2000
 neighbor 192.1.47.4 route-map SET-MED out

Breaking it down:

  • The route-map SET-MED sets the MED (metric) to 70
  • Applied outbound on the eBGP neighbor 192.1.47.4 (R4)
  • This affects all routes advertised from R7 to R4

Critical: MED is set on the outbound direction when advertising routes to eBGP neighbors. This is the opposite direction from Local Preference (which is set inbound).

Local Preference: Set INBOUND on eBGP (affects your AS)
MED: Set OUTBOUND to eBGP (affects neighbor AS)

Results After Configuration

R4’s BGP table now shows:

R4#sh ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   7.0.0.0          192.1.48.8                             0 2000 i
 *                     192.1.47.7              70             0 2000 i
 *    8.0.0.0          192.1.47.7              70             0 2000 i
 *>                    192.1.48.8               0             0 2000 i
 *>   9.0.0.0          192.1.48.8                             0 2000 i
 *                     192.1.47.7              70             0 2000 i

The changes:

Network 7.0.0.0:

  • Path via 192.1.47.7 (R7) now has MED=70
  • Path via 192.1.48.8 (R8) still has MED=0 (default)
  • Best path > switched to 192.1.48.8 (lower MED wins!)

Network 8.0.0.0:

  • Path via 192.1.47.7 (R7) now has MED=70
  • Path via 192.1.48.8 (R8) still has MED=0
  • Best path > remains 192.1.48.8 (reinforced by better MED)

Network 9.0.0.0:

  • Path via 192.1.47.7 (R7) now has MED=70
  • Path via 192.1.48.8 (R8) still has MED=0
  • Best path > switched to 192.1.48.8

R4’s routing table confirms all three networks now use the R8 entry:

R4#sh ip route bgp
B     7.0.0.0/8 [20/0] via 192.1.48.8, 00:03:04
B     8.0.0.0/8 [20/0] via 192.1.48.8, 01:58:51
B     9.0.0.0/8 [20/0] via 192.1.48.8, 00:03:04

Perfect! By setting MED=70 on R7’s advertisements (making them less attractive), we influenced AS 1000 to prefer sending traffic via R8 (MED=0) for all of AS 2000’s networks.

What Happens in AS 1000

R4 in AS 1000 now sees:

  • Routes from R7 with MED=70 (less preferred)
  • Routes from R8 with MED=0 (more preferred, default)

R4 chooses the path with lower MED (via R8), and installs those routes in the routing table. When R4 advertises these routes to other routers in AS 1000 (R3, R5, R6), the MED value may or may not be preserved depending on AS 1000’s internal policies.

Important: By default, Cisco IOS does not propagate MED across AS boundaries. MED received from AS 2000 influences AS 1000’s routing decisions, but typically won’t be passed on if AS 1000 re-advertises these routes to AS 100 or other neighbors.

The MED Comparison Gotcha

There’s a critical limitation to understand: MED is only compared between paths from the same neighboring AS.

If R4 receives:

  • Route A from AS 2000 with MED=50
  • Route B from AS 3000 with MED=100

BGP will not compare these MEDs. The MED comparison only applies when comparing multiple paths to the same destination from the same source AS.

This is why MED works in our lab scenario – both paths (via R7 and R8) originate from AS 2000, so R4 can legitimately compare their MED values.

MED vs Local Preference: The Complete Picture

Let’s tie this together with the Local Preference post. Here’s how outbound and inbound traffic control interact:

Outbound Traffic Control (Local Preference)

AS 2000’s perspective:

router bgp 2000
 ! On R7: Set high LP on routes from R4
 neighbor 192.1.47.4 route-map LP-200 in

route-map LP-200 permit 10
 set local-preference 200

Result: All routers in AS 2000 prefer exiting via R7 to reach external destinations.

Inbound Traffic Control (MED)

AS 2000’s perspective:

router bgp 2000
 ! On R7: Set high MED on routes to R4
 neighbor 192.1.47.4 route-map MED-70 out

route-map MED-70 permit 10
 set metric 70

Result: AS 1000 (specifically R4) prefers entering via R8 to reach AS 2000’s networks.

The Asymmetric Result

Combining both:

Traffic from AS 2000 to AS 1000:
  Exits via R7 (controlled by Local Preference)

Traffic from AS 1000 to AS 2000:
  Enters via R8 (influenced by MED)

This creates asymmetric routing – outbound and inbound traffic use different links. This is completely normal and very common in BGP networks between ISPs.

my DevOps Odyssey

“Σα βγεις στον πηγαιμό για την Ιθάκη, να εύχεσαι να ‘ναι μακρύς ο δρόμος, γεμάτος περιπέτειες, γεμάτος γνώσεις.” - Kavafis’ Ithaka.