BGP MED Configuration Step by Step [Gns3 Lab]
Topology
Initial configuration without MED Manipulation
* R1 Configuration:
interface Ethernet0/0
ip address 10.0.0.1 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.5 255.255.255.252
half-duplex
!
router bgp 266
no synchronization
bgp log-neighbor-changes
network 10.0.0.0 mask 255.255.255.252
network 10.0.0.4 mask 255.255.255.252
neighbor 10.0.0.2 remote-as 277
neighbor 10.0.0.6 remote-as 277
no auto-summary
* R2 Configuration:
interface Ethernet0/0
ip address 10.0.0.2 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.9 255.255.255.252
half-duplex
router bgp 277
no synchronization
bgp log-neighbor-changes
neighbor 10.0.0.1 remote-as 266
neighbor 10.0.0.10 remote-as 277
no auto-summary
* R3 Configuration:
interface Ethernet0/0
ip address 10.0.0.6 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.13 255.255.255.252
half-duplex
!
router bgp 277
no synchronization
bgp log-neighbor-changes
redistribute connected
neighbor 10.0.0.5 remote-as 266
neighbor 10.0.0.5 route-map MEDI out
neighbor 10.0.0.14 remote-as 277
no auto-summary
* R4 Configuration:
interface Loopback0
ip address 4.4.4.2 255.255.255.255
!
interface Loopback1
ip address 4.4.4.3 255.255.255.255
!
interface Ethernet0/0
ip address 10.0.0.10 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.14 255.255.255.252
half-duplex
!
router bgp 277
no synchronization
bgp log-neighbor-changes
network 4.4.4.2 mask 255.255.255.255
network 4.4.4.3 mask 255.255.255.255
neighbor 10.0.0.9 remote-as 277
neighbor 10.0.0.13 remote-as 277
no auto-summary
Verifications:
So, before modifying the MED value, we can see that the subnets 4.4.4.2 and 4.4.4.3 are preferred via 10.0.0.2 which is the Router R2.
R1#show ip bgp
BGP table version is 22, local router ID is 10.0.0.5
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
* 4.4.4.2/32 10.0.0.6 0 277 i
*> 10.0.0.2 0 277 i
* 4.4.4.3/32 10.0.0.6 0 277 i
*> 10.0.0.2 0 277 i
* 10.0.0.0/30 10.0.0.2 0 0 277 ?
*> 0.0.0.0 0 32768 i
* 10.0.0.4/30 10.0.0.6 0 0 277 ?
*> 0.0.0.0 0 32768 i
*> 10.0.0.8/30 10.0.0.2 0 0 277 ?
*> 10.0.0.12/30 10.0.0.6 0 0 277 ?
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
4.0.0.0/32 is subnetted, 2 subnets
B 4.4.4.2 [20/0] via 10.0.0.2, 00:00:45
B 4.4.4.3 [20/0] via 10.0.0.2, 00:00:45
10.0.0.0/30 is subnetted, 4 subnets
B 10.0.0.8 [20/0] via 10.0.0.2, 00:00:45
B 10.0.0.12 [20/0] via 10.0.0.6, 00:00:25
C 10.0.0.0 is directly connected, Ethernet0/0
C 10.0.0.4 is directly connected, Ethernet1/0
R1#
Our target in the next part is to modify the MED value in order to:
- make the Endpoint 4.4.4.2 prefered via Router R2, to do this we will configure R2 to advertise this subnet to R1 with a lower metric (MED value) than the metric advertised by R3.
- make the Endpoint 4.4.4.3 prefered via Router R3, to do this we will configure R3 to advertise the subnet to R1 with a lower metric (MED value) than the metric advertised by R2.
MED Configuration
Let’s configure BGP and change the MED for each destination:
in Router R2: We will prefer route 4.4.4.2 by giving it a lower BGP metric (MED) than route 4.4.4.3:
- we will set the MED value to 100 for 4.4.4.2 IP when advertising this route to R1.
- we will set the MED value to 200 for 4.4.4.3 IP when advertising this route to R1.
in Router R2: We will do the exact opposite in order to prefer route 4.4.4.3 by giving it a lower BGP metric (MED) than route 4.4.4.2:
- we will set the MED value to 100 for 4.4.4.3 IP when advertising this route to R1.
- we will set the MED value to 200 for 4.4.4.2 IP when advertising this route to R1.
* R2 configuration:
We will prefer the 4.4.4.2 to pass through R2 by giving it a lower metric (100) and 4.4.4.3 a higher metric (200).
interface Ethernet0/0
ip address 10.0.0.2 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.9 255.255.255.252
half-duplex
router bgp 277
no synchronization
bgp log-neighbor-changes
neighbor 10.0.0.1 remote-as 266
neighbor 10.0.0.1 route-map MEDI out
neighbor 10.0.0.10 remote-as 277
no auto-summary
access-list 1 permit 4.4.4.2
access-list 2 permit 4.4.4.3
!
route-map MEDI permit 10
match ip address 1
set metric 100
!
route-map MEDI permit 20
match ip address 2
set metric 200
* R3 configuration:
interface Ethernet0/0
ip address 10.0.0.6 255.255.255.252
half-duplex
!
interface Ethernet1/0
ip address 10.0.0.13 255.255.255.252
half-duplex
!
router bgp 277
no synchronization
bgp log-neighbor-changes
redistribute connected
neighbor 10.0.0.5 remote-as 266
neighbor 10.0.0.5 route-map MEDI out
neighbor 10.0.0.14 remote-as 277
no auto-summary
!
access-list 1 permit 4.4.4.2
access-list 2 permit 4.4.4.3
!
route-map MEDI permit 10
match ip address 1
set metric 200
!
route-map MEDI permit 20
match ip address 2
set metric 100
Verification:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
4.0.0.0/32 is subnetted, 2 subnets
B 4.4.4.2 [20/100] via 10.0.0.2, 00:01:32
B 4.4.4.3 [20/100] via 10.0.0.6, 00:01:21
10.0.0.0/30 is subnetted, 2 subnets
C 10.0.0.0 is directly connected, Ethernet0/0
C 10.0.0.4 is directly connected, Ethernet1/0
R1#show ip bgp
BGP table version is 35, local router ID is 10.0.0.5
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
* 4.4.4.2/32 10.0.0.6 200 0 277 i
*> 10.0.0.2 100 0 277 i
*> 4.4.4.3/32 10.0.0.6 100 0 277 i
* 10.0.0.2 200 0 277 i
*> 10.0.0.0/30 0.0.0.0 0 32768 i
*> 10.0.0.4/30 0.0.0.0 0 32768 i
R1#