MED (or metric) is the sixth BGP attribute:
- MED can be used to advertise to your neighbors how they should enter your AS.
- MED is exchanged between autonomous systems.
- The lowest MED is the preferred path.
- MED is propagated to all routers within the neighbor AS but not passed along any other autonomous systems.
Let’s look at an example:

MED (also called metric) is exchanged between autonomous systems and you can use it to let the other AS know which path they should use to enter your AS. R2 is sending a MED of 200 towards AS 3. R3 is sending a MED of 300 to AS 3. AS 3 will prefer the lower metric and send all traffic for AS 1 through R2. Let me show you how to configure this on a Cisco router:

Above we have two autonomous systems. R1 and R3 will both advertise network 1.1.1.0 /24 in BGP. We can use MED to tell AS 2 which path to use to reach this network.
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
R3(config)#router bgp 1
R3(config-router)#neighbor 192.168.23.2 remote-as 2
R3(config-router)#network 1.1.1.0 mask 255.255.255.0
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 192.168.23.3 remote-as 1
This is the BGP configuration, nothing special so far.
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 1.1.1.0/24 192.168.23.3 0 0 1 i
*> 192.168.12.1 0 0 1 i
You have seen the example above before. R2 prefers the path through 192.168.12.1. Note that the default metric (MED) is 0. Let’s play with the MED now:
R1(config)#route-map MED permit 10
R1(config-route-map)#set metric 700
R1(config-route-map)#exit
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 route-map MED out
R3(config)#route-map MED permit 10
R3(config-route-map)#set metric 500
R3(config-route-map)#exit
R3(config)#router bgp 1
R3(config-router)#neighbor 192.168.23.2 route-map MED out
I’ll use route-maps so that R1 advertises everything with a med of 700 and R3 will advertise everything with a med of 500.
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 1.1.1.0/24 192.168.12.1 700 0 1 i
*> 192.168.23.3 500 0 1 i
You can see R2 prefers the path through 192.168.23.3 because the med is lower. That’s all there is to it.
hostname R2
!
interface fastEthernet0/0
ip address 192.168.12.2 255.255.255.0
!
interface fastEthernet1/0
ip address 192.168.23.2 255.255.255.0
!
router bgp 2
neighbor 192.168.12.1 remote-as 1
neighbor 192.168.23.3 remote-as 1
!
end
hostname R1
!
interface Loopback 0
ip address 1.1.1.1 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.12.1 255.255.255.0
!
router bgp 1
neighbor 192.168.12.2 remote-as 2
network 1.1.1.0 mask 255.255.255.0
neighbor 192.168.12.2 route-map MED out
!
route-map MED permit 10
set metric 700
!
end
hostname R3
!
interface Loopback 0
ip address 1.1.1.1 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.23.3 255.255.255.0
!
router bgp 1
neighbor 192.168.23.2 remote-as 2
network 1.1.1.0 mask 255.255.255.0
neighbor 192.168.23.2 route-map MED out
!
route-map MED permit 10
set metric 500
!
end
I hope this has helped you to understand BGP MED. If you have any questions just leave a comment.
No comments:
Post a Comment