BGP MED
Suggest a preferred entry into an AS with a lower metric, then verify whether the neighboring AS actually selects it.
Two entries into one AS
R1 and R3 in AS 65010 advertise the same /24 to R2 in AS 65020. Because both candidates come from the same neighboring AS, the ordinary MED comparison applies when earlier criteria tie.
| Link | First endpoint | Second endpoint |
|---|---|---|
| R1–R2 | R1 GigabitEthernet1: 192.0.2.1/30 | R2 GigabitEthernet1: 192.0.2.2/30 |
| R2–R3 | R2 GigabitEthernet2: 192.0.2.5/30 | R3 GigabitEthernet1: 192.0.2.6/30 |
Complete baseline configurations
R1
hostname R1
ip cef
interface Loopback0
ip address 10.255.0.1 255.255.255.255
exit
interface Loopback10
ip address 198.51.100.1 255.255.255.0
exit
interface GigabitEthernet1
ip address 192.0.2.1 255.255.255.252
no shutdown
exit
router bgp 65010
bgp router-id 10.255.0.1
no bgp default ipv4-unicast
neighbor 192.0.2.2 remote-as 65020
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.2 activate
network 198.51.100.0 mask 255.255.255.0
exit-address-family
endR2
hostname R2
ip cef
interface Loopback0
ip address 10.255.0.2 255.255.255.255
exit
interface GigabitEthernet1
ip address 192.0.2.2 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip address 192.0.2.5 255.255.255.252
no shutdown
exit
router bgp 65020
bgp router-id 10.255.0.2
no bgp default ipv4-unicast
neighbor 192.0.2.1 remote-as 65010
neighbor 192.0.2.6 remote-as 65010
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.1 activate
neighbor 192.0.2.6 activate
exit-address-family
endR3
hostname R3
ip cef
interface Loopback0
ip address 10.255.0.3 255.255.255.255
exit
interface Loopback10
ip address 198.51.100.3 255.255.255.0
exit
interface GigabitEthernet1
ip address 192.0.2.6 255.255.255.252
no shutdown
exit
router bgp 65010
bgp router-id 10.255.0.3
no bgp default ipv4-unicast
neighbor 192.0.2.5 remote-as 65020
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.5 activate
network 198.51.100.0 mask 255.255.255.0
exit-address-family
endR2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*> 198.51.100.0/24 192.0.2.1 0 0 65010 i
* 192.0.2.6 0 0 65010 iMED is optional non-transitive. Lower is preferred when the paths are comparable. The Metric column displays it in these tables.
Advertise different metrics
On R1, set the target prefix’s exported MED to 200:
ip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map ENTRY-METRIC permit 10
match ip address prefix-list TARGET
set metric 200
exit
route-map ENTRY-METRIC permit 20
exitrouter bgp 65010
address-family ipv4 unicast
neighbor 192.0.2.2 route-map ENTRY-METRIC out
exit-address-familyOn R3, advertise MED 50:
ip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map ENTRY-METRIC permit 10
match ip address prefix-list TARGET
set metric 50
exit
route-map ENTRY-METRIC permit 20
exitrouter bgp 65010
address-family ipv4 unicast
neighbor 192.0.2.5 route-map ENTRY-METRIC out
exit-address-familyR1# clear ip bgp 192.0.2.2 soft out
R3# clear ip bgp 192.0.2.5 soft outObserve the preference
R2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
* 198.51.100.0/24 192.0.2.1 200 0 65010 i
*> 192.0.2.6 50 0 65010 iR2# show ip route 198.51.100.0
Routing entry for 198.51.100.0/24
Known via "bgp 65020", distance 20, metric 50
* 192.0.2.6, via GigabitEthernet2R2 chooses R3’s lower value. This influences traffic arriving from R2; the receiving AS can still apply earlier local policy that overrides the hint.
Comparison and propagation
Received MED can be carried internally within the neighboring AS, but it is not simply passed onward to another external AS. By default these examples compare MED for paths from the same neighboring AS, not arbitrary unrelated providers. Missing MED is normally treated as zero in this command family; configuration can change that behavior.
MED is neither an end-to-end sum nor the local IGP cost to a next hop. Always-compare-med and deterministic-MED change aspects of comparison and grouping; do not enable them merely to make a diagram’s preferred arrow win.
Restore the baseline
Detach ENTRY-METRIC on both originators and refresh their external advertisements.
R1
router bgp 65010
address-family ipv4 unicast
no neighbor 192.0.2.2 route-map ENTRY-METRIC out
exit-address-familyR3
router bgp 65010
address-family ipv4 unicast
no neighbor 192.0.2.5 route-map ENTRY-METRIC out
exit-address-familyR1# clear ip bgp 192.0.2.2 soft out
R3# clear ip bgp 192.0.2.5 soft outR2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*> 198.51.100.0/24 192.0.2.1 0 0 65010 i
* 192.0.2.6 0 0 65010 iKey Takeaways
- Lower MED is preferred among comparable candidates after earlier checks tie.
- The Metric column shows MED in these examples.
- MED normally compares routes from the same neighboring AS.
- A receiving AS can carry MED internally but does not blindly pass it to a third external AS.
- MED is a preference hint, not an accumulated end-to-end IGP cost.
Protocol and command references
Best-path comparison rules · BGP path attributes · Router-symbol attribution.