Changing MED value in BGP (GNS3 lab)

BGP Multiexit Discriminator (MED orMULTI_EXIT_DISC) is an optional nontransative attribute (Type code Value 4). It is usually used to exchange info about a preffered to external BGP neighbours. MED is passed between ASs unlike LOCAL_PREF but each time it is passed to another new AS it is reset back to zero unless it is set using something similar to the example below.

MED values for paths not received from the same AS are not by default compared (The Lowest MED is preferred). If you need to force the router to compair MED values for the same route received from different ASs you can use the “bgp always-compare-med“.

More about other attributes and the order they are valued in can be found [here].

Heres a short example using GNS3

Topology

Grab the initial configs and net file [here] (all addressing and basic bgp setup done using 7200)

Before we change the MED the best route to the 172.16.1.0/24 has been picked via SmileyISP

m00nie#sho ip bgp 172.16.1.0/24
BGP routing table entry for 172.16.1.0/24, version 13
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Advertised to update-groups:
1
300
10.1.13.3 from 10.1.13.3 (172.16.1.3)
Origin incomplete, metric 0, localpref 100, valid, external
300
10.1.14.4 from 10.1.14.4 (10.1.34.4)
Origin incomplete, localpref 100, valid, external
200
10.1.12.2 from 10.1.12.2 (172.16.1.1)
Origin incomplete, metric 0, localpref 100, valid, external, best
m00nie#

Notice the metrics of 0 above.  Now lets configure a route map on the routers to set the MED on all the routers apart from m00nie.

SadISP2#conf t
SadISP2(config)#ip as-path access-list 1 permit ^$
SadISP2(config)#route-map SetMED permit 10
SadISP2(config-route-map)#match as-path 1
SadISP2(config-route-map)#set metric 100
SadISP2(config-route-map)#exit
SadISP2(config)#router bgp 300
SadISP2(config-router)#neighbor 10.1.14.1 route-map SetMED out
SadISP2(config-router)#^Z
SadISP2#

First we create a as-path access-list using a regexp expression to match the updates we want. This expression matches all (^$) to keep things simple. Then we enter route-map configuration mode set the match condition to our as-path access list and using the set command set the metic for this match to 100. Then we enter BGP config mode and tell it to use the route map against a specific neighbour.

Each of the other routers are very similar, only changing the metric value and the neighbour we configure the route map to. After all the config is done we get the following results on the m00nie router. (you might have to clear the bgp session using “clear bgp all 300 “soft or similar)

m00nie#show ip bgp 172.16.1.0/24
BGP routing table entry for 172.16.1.0/24, version 19
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Flag: 0x820
Advertised to update-groups:
1
300
10.1.13.3 from 10.1.13.3 (172.16.1.3)
Origin incomplete, metric 50, localpref 100, valid, external
300
10.1.14.4 from 10.1.14.4 (10.1.34.4)
Origin incomplete, metric 100, localpref 100, valid, external
200
10.1.12.2 from 10.1.12.2 (172.16.1.1)
Origin incomplete, metric 200, localpref 100, valid, external, best
m00nie#

You can now see the metric values have changed but the best route is still via SmileyISP! This is because by default the router doesnt compare MED values from different ASs. If we issue the “bgp always-compare-med” command in bgp config mode things should change 😉

m00nie#conf t
Enter configuration commands, one per line. End with CNTL/Z.
m00nie(config)#router bgp 100
m00nie(config-router)#bgp always-compare-med
m00nie(config-router)#^Z
m00nie#

Again you might have to issue a “clear ip bgp *” command or similar to see the changes but hopefuly once you have you’ll see the output below.

m00nie#show ip bgp 172.16.1.0/24
BGP routing table entry for 172.16.1.0/24, version 6
Paths: (3 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
Advertised to update-groups:
1
300
10.1.13.3 from 10.1.13.3 (172.16.1.3)
Origin incomplete, metric 50, localpref 100, valid, external, best
200
10.1.12.2 from 10.1.12.2 (172.16.1.1)
Origin incomplete, metric 200, localpref 100, valid, external
300
10.1.14.4 from 10.1.14.4 (10.1.34.4)
Origin incomplete, metric 100, localpref 100, valid, external
m00nie#

Now the best route to 172.16.1.0/24 for the m00nie router is via SadISP1.

m00nie 😀