How to configure BGP MED Attribute

The question is whether you have your own AS number or not. If you don’t, you won’t have much control over incoming traffic from ISP A or ISP B. Let’s assume, however, you have been issued an Internet valid BGP Autonomous System number, and you have BGP peerings with both ISP A and ISP B.

You state you want incoming traffic to come from ISP A. In this case, you would use ASPath Pre-pending towards ISP B. This will make your AS Path appear longer (and therefore less desirable) when it is advertised from ISP B.

For outgoing traffic, you have lots of options. If you have only one Cisco router in your company, and it is peered with both ISPs, then you can use Weight. Otherwise, it would be best to use Local Preference, where you set a higher preference for where you want the outgoing traffic to flow (in this case, ISP B).

1 Like

Hi Rene

Does MED distributed to other routers within same AS? I have mpls cloud provided by Verizon, Verizon AS 65000,
my office1 in Houston AS 65400 has two routers, router1 and router2, each has a mpls connections to Verizon , router2 is backup and configure MED 10.
my office2 is in Sanfrancisco AS 65401. sometimes I have some unexplained network issue, connectivity from Sanfrancisco to Houston.
I wonder if MED is the issue not being distributed to all Verizon routers in the mpls cloud and cause asymmetric routing, I am thinking changing MED to AS Path Prepend on Houston router2.

thank you


Hi Hoan,
Yes, MED is communicated to iBGP peers. I tested that this morning. Since MED is an optional, non-transitive attribute, however, those iBGP neighbors will not transmit that MED to any EBGP neighbors they may have.

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