In this post I’ll continue from BGP Influencing Inbound Routing – AS Path. The topology and initial setup are identical. However this time we’ll use MED to influence.

MED is an BGP optional-nontransitive attribute and is not always known by peers. In fact, peers can ignore updates which it is included, and not pass it along to peers. The lower MED value is preferred.

Start with a sanity check to ensure the system is back to its default state.

R4#show ip bgp | b Network

Network          Next Hop            Metric LocPrf Weight Path
*  100.1.1.1/32     10.1.34.3                              0 100 i
*>                  10.1.14.1                0             0 100 i
*  100.2.2.2/32     10.1.14.1                              0 100 i
*>                  10.1.34.3                              0 100 i
*  100.3.3.3/32     10.1.14.1                              0 100 i
*>                  10.1.34.3                0             0 100 i
*> 100.4.4.4/32       0.0.0.0                0             32768 i

Lets say all routers from even routers (R2) should come in to R1, and from odd routers (R1, R3) should come in R3. No we will use MED to perform this.

To do this, we’ll set the MED higher for odd routes from R1, and set the MED higher to even routes from R3.

**** R1 Configuration

R1(config)#ip prefix-list ODD_ROUTER_ROUTES seq 10 permit 100.1.1.1/32
R1(config)#ip prefix-list ODD_ROUTER_ROUTES seq 20 permit 100.3.3.3/32

R1(config)#route-map TO_R4_OUT per 10
R1(config-route-map)#match ip add prefix-list ODD_ROUTER_ROUTES
R1(config-route-map)#set metric 1111
R1(config-route-map)#route-map TO_R4_OUT per 100
R1(config-route-map)#set metric 1

R1(config-route-map)#router bgp 100
R1(config-router)#neighbor 10.1.14.4 route-map TO_R4_OUT out

***** R3 Configuration

R3(config)#ip prefix-list EVEN_ROUTER_ROUTES per 100.2.2.2/32

R3(config)#route-map TO_R4_OUT per 10
R3(config-route-map)#match ip address prefix-list EVEN_ROUTER_ROUTES
R3(config-route-map)#set metric 3333
R3(config-route-map)#route-map TO_R4_OUT per 100
R3(config-route-map)#set metric 3

R3(config)#router bgp 100
R3(config-router)#neighbor 10.1.34.4 route-map TO_R4_OUT out

Check the results.

R4#show ip bgp | b Net
Network          Next Hop            Metric LocPrf Weight Path
*> 100.1.1.1/32     10.1.34.3                  3             0 100 i
*                             10.1.14.1             1111             0 100 i
*> 100.2.2.2/32     10.1.14.1                  1             0 100 i
*                             10.1.34.3             3333             0 100 i
*  100.3.3.3/32          10.1.14.1             1111             0 100 i
*>                       10.1.34.3                  3             0 100 i
*> 100.4.4.4/32        0.0.0.0                  0             32768 i

All is working as expected. The even router routes prefer the next hop of 10.1.14.1 and the odd one prefer 10.1.34.3. The paths can be verified with the traceroute command if desired.

The same results were accomplished in the end with both MED and AS perpend, however is most commercial deployments MED is never used.