How to configure BGP MED Attribute

19 posts were merged into an existing topic: How to configure BGP MED Attribute

MED (also called metric) is exchanged between autonomous systems and you can use it to let the other AS know which path they should use to enter your AS. R2 is sending a MED of 200 towards AS 3. R3 is sending a MED of 300 to AS 3. AS 3 will prefer the lower metric and send all traffic for AS 1 through AS 1. <------- R2

late reply but thanks, it is fixed.

Hello Rene

please , how can in control downstream traffic between two bgp neighbor in Dual Homed bgp topology ? looking forward to your reply .

only two router with two different connections .

Hello Rawaz.

If I understand correctly, your scenario involves a dual homed BGP topology and you want to know how to control, or at least influence, inbound traffic, correct?

Because inbound traffic is essentially sent to you, you do not have the ultimate control of how traffic enters your AS. Your ISP may have outbound policies that will always override all of your attempts to influence inbound traffic. However, you do have the option of influencing inbound traffic. There are several ways to do this including:

* Leaking more specific routes
* Using the MED attribute
* AS PATH prepending
* Community/local pref agreement

Remember however, that the ISP has the final word for inbound traffic.

I hope this has been helpful!


Can you explain between:

  • deterministic-med
  • non-deterministic-med

Hello Nguyen

The following excerpt from Cisco documentation very clearly describes the use of these features:

Enabling the bgp deterministic-med command ensures the comparison of the MED variable when choosing routes advertised by different peers in the same autonomous system. Enabling the bgp always-compare-med command ensures the comparison of the MED for paths from neighbors in different autonomous systems. The bgp always-compare-med command is useful when multiple service providers or enterprises agree on a uniform policy for setting MED. Thus, for network X, if Internet Service Provider A (ISP A) sets the MED to 10, and ISP B sets the MED to 20, both ISPs agree that ISP A has the better performing path to X.

This information has come from the following Cisco documentation:

I hope this has been helpful!


It’s confusing when you say BGP MED aka/or/(Metric). Yes it’s a Metric in the CLI but in Cisco’s docs (at least some of them) it’s Multi Exit Discriminator. IF you search the cisco documentation I liked bellow about MED for Metric it doesn’t find anything. I think you should update your documents to at least mention the Cisco definition I liked. Thanks! I really enjoy your site!

Hello Brian

Thanks for bringing this to our attention. I can understand how this can be confusing. According to this Cisco documentation, MED is also known as the external metric of a route, because the lower the MED value, the more preferred a route becomes.

Similarly, the following BGP case studies documentation refers to MED as “the metric attribute” which is also known as “MED”.

The truth is that the original naming of the attribute was Inter AS Metric, and has since been changed to Multi Exit Discriminator, so this is the reason why the term Metric is still sometimes used.

However, to be absolutely correct, the term should be MED. I will let Rene know to clarify the wording to avoid confusion in the future.

I hope this has been helpful!


Absolutely brilliant!

I was going to ask the difference between MED and AS-PATH prepending but it has been answered. One more thing though at the beginning you wrote: “R1 and R3 will both advertise network /24 in BGP. We can use MED to tell AS 1 which path to use to reach this network”. I think it should be AS 2 instead


Hello sales2161

Yes, you are correct. I will let Rene know.



Afternoon chaps - I realise that MED is only meant for eBGP peers but is there actually anything in the BGP UPDATE message which would prevent it from being advertised to an iBGP neighbor?

Hello Gareth

Actually, it is a little more complex than that. The MED is actually shared between iBGP peers such that the same prefix will have the associated metric that it has been given. When eBGP peers share these same prefixes, the metric is reset to 0 as the MED value is not transferred to an external AS.

HOWEVER, when sharing prefixes between eBGP members, the MED can be modified in order to influence routing. Cisco states it best like so:

When a BGP speaker learns a route from a peer, it can pass the route’s MED to any iBGP peers, but not to eBGP peers. As a result the MED has relevance only between neighbouring autonomous systems.

This is the behaviour BY DEFAULT. BUT, you can change the advertised MED between eBGP peers thus influencing the metric between AS’es.

You can find more detailed information at this Cisco documentation:

I hope this has been helpful!


1 Like

Thanks Laz.

One more question please…

If the lowest MED value wins then shouldn’t a value of 0 always take precedence?

Hello Gareth

Yes, if you change the MED for a particular path to a non-zero value, and you leave another path’s MED at the default (0) then the default MED value will take precedence simply because it is lower. There is an option where you can enable the following command:

bgp bestpath med missing-as-worst

This causes any route that is advertised without a MED to be assigned the maximum value of 4,294,967,295, instead of the default value of 0, thus making it by default worse than all other explicitly configured MED values. You can find out more about this command at this Cisco Command Reference.

I hope this has been helpful!


Hello Rene,
Very good article on MED.
I think you could include the note about the default value for MED which is zero


Hi Gilson

Thanks for the valuable feedback, I’ll let @ReneMolenaar know!


Hi Gilson,

I agree, just added and highlighted this.


Hello Rene,

All the MED examples I have seen are between two autonomous systems. What if there are two routers (belonging to the same company but different sites) having different ASN’s advertising identical routes to an external organization.

I want the external organization to send traffic via only one of the sites. Only if the link fails can it be sent to via the other site. Can this still be done by MED values?

So can i configure a route-map on site 1’s router where the MED value is 100 and a route-map on site 2 router where the MED value is 200. Can this ensure that the external routers always sends traffic via site 1?