BGP – Changing MED/Metric to Influence Inbound Routing with Lab Examples

The reason I decided to make this post is because all other MED/Metric changing tutorials out there only include an example of one prefix. I wanted to make one that looked more realistic.

Before we begin let’s overview the BGP MED attribute:
MED/Metric are synonymous
MED influences how your eBGP neighbors should enter your autonomous system
The lower the MED/Metric, the more preferred route.
MED is sent to eBGP neighbors on the border, no more than 1 AS away.  (It shouldn’t propagate across the internet!)
MED is NOT sent to IBGP neighbors


In my lab I have 4 autonomous systems, but we’ll only be working with AS 2,3, and 4.

AS 2 = IOSV2, 3, 4,  and 5
AS 3 = IOSV6
AS 4 = IOSV7


Currently all of my traffic is traversing IOSV-4 because IOSV-5 has a MED/Metric of 200, and BGP prefers a lower one.
I want to influence how traffic from AS 3 and 4 reaches the prefix of which is the Loopback interface of IOSV2.
Specifically I only want traffic destined for that loopback interface to go through IOSV-5.


Since MED/Metric determines how traffic will enter your Autonomous System, I know I need to make the change on AS2.
If you recall the point above, the lower the MED/Metric, the more preferred route. So I will be making my changes on the router
that I DON’T want the traffic to be preferred for. I want my traffic to traverse IOSV5, so i will make my changes on IOSV4.
I will making configuration changes so that IOSV4 advertises with a MED of 900, thus making BGP prefer
IOSV5’s route with a metric of 200.


caution: I am assuming you know a little bit about route-maps, however I do my best to explain the config
On IOSV4 I will create a route-map, then match my prefix via an ACL, then configure my route map to set a metric of 900 for BGP, for that matched prefix,
Then I will add a sequence to the route-map to match all other traffic, but do nothing with it.
note: If I don’t do the second sequence match in my route-map, all other prefixes except for the matched one will be filtered from the updates, and that’s NOT
what we want at all. 


So let’s get started.

configure terminal
access-list 1 permit host
route-map MED-CHANGE permit 10
match ip address 1
set metric 900
route-map MED-CHANGE permit 20
router bgp 2
neighbor route-map MED-CHANGE out

Now if we jump on IOSV6 (which is Autonomous System 3) we should see the prefix of have a metric of 900 from (IOSV4). It has a metric of 200 from which is IOSV5.

As we can see from the above screenshot we got exactly what we expected. AS3 wants to take the path of IOSV5 for this prefix of and IOSV4 for  every other prefix. Now remember when I said that MED/METRIC is only propogated to border routers since it doesn’t influence the whole path? If I check IOSV7, I shouldn’t see that METRIC/MED of 900 for that prefix.


As you can see , IOSV7 doesn’t know anything about that MED/METRIC, and it shouldn’t. That attribute only influences routing decisions for inbound traffic, on bordering AS’.