When there are many exterior points for a single AS, the Multi-Exit Discriminator (MED) is an optional BGP attribute that is used to differentiate between the various exits.
Suppose, for instance, that you want traffic that is coming into your AS and is headed for network A to take a particular path, while traffic that is destined for network B should take a different way.
Through the process of giving a MED value to the prefix, which is then advertised to the upstream router, this is accomplished by both routers that are part of the single AS infrastructure. Additionally, as part of the process of selecting the best way, the upstream router will select the necessary path based on the path that has the lowest MED for the prefix that has been provided.
Example
Let’s see a MED in action.
Topology
Our example and topology depend on:
- Being advertised from behind R4 are two networks.
- The necessary MED attributes will be added to networks 100.1.100.0/24 and 100.2.100.0/24 through a route map that is configured on R2 and R3.
- By utilizing the MED characteristics, R1 will direct traffic entering AS200 to 100.1.100.0/24 via R2 and 100.2.100.0/24 via R3.
Looking at the optimal route, we can observe that 2.2.2.2 (R2) is the best choice (shown by >) for both prefixes (100.[1-2].100.0/24) initially.
R1#show ip bgp
BGP table version is 4, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
* 100.1.100.0/24 3.3.3.3 0 200 i
*> 2.2.2.2 0 200 i
* 100.2.100.0/24 3.3.3.3 0 200 i
*> 2.2.2.2 0 200 i
Configuration
On R2 and R3, our configuration will proceed exactly as described in the following steps:
- The network will come to be defined by an access list.
- An action will be assigned a route map, which will be assigned to the network (ACL).
- Setting the MED value for the route will be the action that corresponds to the route map.
- After then, the route map will be assigned to the R1 neighbor, taking into consideration the outbound advertisements.
Let us get started…
R2
R2(config)# access-list 1 permit 100.1.100.0 0.0.0.255
R2(config)# access-list 2 permit 100.2.100.0 0.0.0.255
R2(config)# route-map MED permit 10
R2(config-route-map)# match ip address 1
R2(config-route-map)# set metric 100
R2(config)# route-map MED permit 20
R2(config-route-map)# match ip address 2
R2(config-route-map)# set metric 200
R2(config)# router bgp 200
R2(config-router)# neighbor 1.1.1.1 route-map MED out
R2# clear bgp ip * soft
R3
R3(config)# access-list 1 permit 100.1.100.0 0.0.0.255
R3(config)# access-list 2 permit 100.2.100.0 0.0.0.255
R3(config)# route-map MED permit 10
R3(config-route-map)# match ip address 1
R3(config-route-map)# set metric 200
R3(config)# route-map MED permit 20
R3(config-route-map)# match ip address 2
R3(config-route-map)# set metric 100
R3(config)# router bgp 200
R3(config-router)# neighbor 1.1.1.1 route-map MED out
R3# clear bgp ip * soft
Verification
We may check the BGP table for the best and valid BGP paths on R1 to make sure our configuration is working. Once again, the metric is appropriately allocated to each R2 and R3 prefix.