BGP Attribute : Multi-Exit Discriminator or Known as MED
Today I am going to talk about the other BGP attribute which is widely used for the inbound traffic to come in to your network. MED is generally set by the service provider and the lower value of the MED will be selected as a preference route for incoming traffic into the network.
MED attribute is exchanged between ASs, but a MED attribute that comes into an AS does not leave the AS. When an update enters the AS with a certain MED value, that value is used for decision making within the AS. When BGP sends that update to another AS, the MED is reset to 0.
MED is called as optional non-transtive attribute and the router compares MED attributes for paths from external neighbors that are in the same AS. Hope you got the exact point of the MED use in the BGP enabled network. Lets take an topology and the configuration part of the MED. The topology and the IP addresses showing in this example is taken only for the demo purposes and have no relevance with any of the live or the enterprise network.
MED attribute is exchanged between ASs, but a MED attribute that comes into an AS does not leave the AS. When an update enters the AS with a certain MED value, that value is used for decision making within the AS. When BGP sends that update to another AS, the MED is reset to 0.
MED is called as optional non-transtive attribute and the router compares MED attributes for paths from external neighbors that are in the same AS. Hope you got the exact point of the MED use in the BGP enabled network. Lets take an topology and the configuration part of the MED. The topology and the IP addresses showing in this example is taken only for the demo purposes and have no relevance with any of the live or the enterprise network.
![]() |
Fig 1.1- BGP Attribute- MED |
Configurations on Router A
!
router bgp 100
neighbor 2.2.2.1 remote-as 300
neighbor 3.3.3.3 remote-as 300
neighbor 4.4.4.3 remote-as 400
Configurations on Router B
!
router bgp 400
neighbor 4.4.4.4 remote-as 100
neighbor 4.4.4.4 route-map SETMEDOUT out
neighbor 5.5.5.4 remote-as 300
!
route-map SETMEDOUT permit 10
set metric 50
Configurations on Router C
!
router bgp 300
neighbor 2.2.2.2 remote-as 100
neighbor 2.2.2.2 route-map SETMEDOUT out
neighbor 5.5.5.5 remote-as 400
neighbor 1.1.1.2 remote-as 300
!
route-map SETMEDOUT permit 10
set metric 120
Configurations on Router D
!
router bgp 300
neighbor 3.3.3.2 remote-as 100
neighbor 3.3.3.2 route map SETMEDOUT out
neighbor 1.1.1.1 remote-as 300
!
route-map SETMEDOUT permit 10
set metric 200
By default, BGP compares the MED attributes of routes coming from neighbors in the same external AS. Router A can only compare the MED attribute coming from Router C (120) to the MED attribute coming from Router D (200) even though the update coming from Router B has the lowest MED value.
Router A will choose Router C as the best path for reaching network 180.10.0.0. If you want to change the route of Router A to include updates for network 180.10.0.0 from Router B in the comparison then we need to use the bgp always-compare-med router configuration command, as in the following modified configuration for Router A
Configurations on Router A
!
router bgp 100
neighbor 2.2.2.1 remote-as 300
neighbor 3.3.3.3 remote-as 300
neighbor 4.4.4.3 remote-as 400
bgp always-compare-med
Similarly we have Router A will choose Router B as the best next hop for reaching network 180.10.0.0 as we taken as parameters are same or you can say all attributes are same here in this case.You can also set the MED attribute when you configure the redistribution of routes into BGP. For example, on Router B you can inject the static route into BGP with a MED of 50 as in the following configuration:
Configurations on Router B
!
router bgp 400
redistribute static
default-metric 50
!
ip route 160.10.0.0 255.255.0.0 null 0
The preceding configuration causes Router B to send out updates for 160.10.0.0 with a MED attribute of 50.