Multi Exit Discriminator (MED) also called metric. MED is an optional and
nontransitive attribute; MED allows an autonomous system to tell a neighboring
autonomous system the best way to forward packets into the first autonomous
system. MED is used to advertise one autonomous system into another, propagated
inside the autonomous system, but not sent to any other autonomous systems. A
smaller MED value means more preferred, by default 0 and the range is 0 through
4,294,967,295. MED originally worked for a dual-homed design.
MED is used in the route selection process only if
all the paths come from the same Autonomous System. BGP uses the BGP
always-compare-med command to force the router to compare the MED even if the
paths come from different autonomous systems. If you are enabling this option
then enable it entire autonomous system otherwise loops can occur.
Before we start BGP
configuration check out some important of BGP CCIE exam topics.
Here is the list of all BGP labs
and theories CCNA to CCIE
1.Introduction of BGP
2.BGP Neighbors
3.BGP Peer Group
4.BGP Attributes
5.BGP Weight Attribute
6.BGP Local Preference (Local_Pref)
7.BGP Multi Exit Discriminator (MED)
8.BGP AS Path Prepending
9.BGP Route Reflectors (RR)
10.BGP Communities_No-advertise configuration
11.BGP community Local-AS
12.BGP Confederations and configuration
13.BGP Route filtering methods
Topology:-
configure the topology as per the diagram
configure the IP addressing as per the
topology
configure IBGP and EBGP, advertise all the directly
connected interface
configure next hop behavior at AS 6023
configure AS 6001 (R-1) should exit via AS 6005 to
reach 192.168.20.1 or any network.
configure weight attribute on (AS 6001)
make sure AS 6001 return traffic should use the
same path which it exits via 6005,6004,6003 and 6023
configure MED on and MED compare to tell BGP router
to compare MED in the entire 6023 AS.
in the end, make sure traffic will move as we
thought.
configure the IP addressing as per the topology
R1(config)#interface serial 4/0
R1(config-if)#ip address 1.1.1.2 255.0.0.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface fastethernet 0/0
R1(config-if)#ip address 192.168.10.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface serial 4/4
R1(config-if)#ip address 5.5.5.2 255.0.0.0
R1(config-if)#no shutdown
R1(config-if)#exit
AS-6001-R1-#show ip interface brief
Interface
IP-Address OK? Method Status
Protocol
FastEthernet0/0
192.168.10.1 YES NVRAM up
up
Serial4/0
1.1.1.1 YES NVRAM up
up
Serial4/4
5.5.5.2 YES NVRAM up
up
Loopback0
10.1.1.1 YES NVRAM up
up
R2(config)#interface serial 4/0
R2(config-if)#ip address 1.1.1.2 255.0.0.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface serial 4/1
R2(config-if)#ip address 2.2.2.1 255.0.0.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface fastethernet 0/0
R2(config-if)#ip address 192.168.20.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#no keepalive
R2(config-if)#exit
R2(config)#interface loopback 0
R2(config-if)#ip address 20.1.1.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
AS6023-R2-#show ip interface brief
Interface
IP-Address OK? Method Status
Protocol
FastEthernet0/0
192.168.20.1 YES NVRAM up
up
Serial4/0
1.1.1.2 YES NVRAM up
up
Serial4/1
2.2.2.1 YES NVRAM up
up
Loopback0
20.1.1.1
YES NVRAM up
up
R3(config)#interface serial 4/1
R3(config-if)#ip address 2.2.2.2 255.0.0.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface serial 4/2
R3(config-if)#ip address 3.3.3.1 255.0.0.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface fastEthernet 0/0
R3(config-if)#ip address 192.168.30.1 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#no keepalive
R3(config-if)#exit
R3(config)#interface loopback 0
R3(config-if)#ip address 30.1.1.1 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R4(config)#interface
serial 4/2
R4(config-if)#ip address 3.3.3.2 255.0.0.0
R4(config-if)#no sh
R4(config-if)#no shutdown
R4(config-if)#exit
R4(config)#interface serial 4/3
R4(config-if)#ip address 4.4.4.1 255.0.0.0
R4(config-if)#no sh
R4(config-if)#no shutdown
R4(config-if)#exit
R4(config)#interface fastEthernet 0/0
R4(config-if)#ip address 192.168.40.1 255.255.255.0
R4(config-if)#no keepalive
R4(config-if)#no shutdown
R4(config-if)#exit
R4(config)#interface loopback 0
R4(config-if)#ip address 40.1.1.1 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit
AS6004-R4-#show
ip interface brief
Interface
IP-Address
OK? Method Status
Protocol
FastEthernet0/0
192.168.40.1 YES NVRAM up
up
Serial4/2
3.3.3.2 YES NVRAM up
up
Serial4/3
4.4.4.1 YES NVRAM up
up
Loopback0
40.1.1.1
YES NVRAM up
up
R5(config)#interface serial 4/3
R5(config-if)#ip address 4.4.4.2 255.0.0.0
R5(config-if)#no shutdown
R5(config-if)#exit
R5(config)#interface serial 4/4
R5(config-if)#ip address 5.5.5.1 255.0.0.0
R5(config-if)#no shutdown
R5(config-if)#exit
AS6005-R5-(config)#interface fastEthernet 0/0
AS6005-R5-(config-if)#ip address 50.1.1.1
255.255.255.0
AS6005-R5-(config-if)#no shutdown
AS6005-R5-(config-if)#no keepalive
AS6005-R5-(config-if)#exit
R5(config)#interface loopback 0
R5(config-if)#ip address 192.168.50.1 255.255.255.0
R5(config-if)#no shutdown
R5(config-if)#exit
AS6005-R5-#show ip interface brief
Interface
IP-Address OK? Method Status
Protocol
FastEthernet0/0
50.1.1.1 YES manual
up up
Serial4/3
4.4.4.2
YES NVRAM up
up
Serial4/4
5.5.5.1
YES NVRAM up
up
Loopback0
192.168.50.1 YES
NVRAM up
up
configure IBGP and EBGP, advertise all the directly connected interface
configure next hop behavior at AS 6023
AS-6001-R1-(config)#router bgp 6001
AS-6001-R1-(config-router)#neighbor 1.1.1.2 remote-as 6023
AS-6001-R1-(config-router)#neighbor 5.5.5.1 remote-as 6005
AS-6001-R1-(config-router)#network 192.168.10.0 mask 255.255.255.0
AS-6001-R1-(config-router)#network 10.0.0.0 mask 255.255.255.0
AS-6001-R1-(config-router)#network 1.0.0.0
AS-6001-R1-(config-router)#network 5.0.0.0
AS-6001-R1-(config-router)#no auto-summary
AS-6001-R1-(config-router)#no synchronization
AS-6001-R1-(config-router)#exit
AS-6001-R1-#show ip route bgp
B 2.0.0.0/8 [20/0]
via 1.1.1.2, 00:23:52
B 3.0.0.0/8 [20/0]
via 1.1.1.2, 00:23:21
B 192.168.30.0/24
[20/0] via 1.1.1.2, 00:23:21
B 4.0.0.0/8 [20/0]
via 5.5.5.1, 00:23:49
B 192.168.40.0/24
[20/0] via 1.1.1.2, 00:23:21
B 192.168.20.0/24
[20/0] via 1.1.1.2, 00:23:52
B 192.168.50.0/24
[20/0] via 5.5.5.1, 00:23:49
AS-6001-R1-#show ip bgp summary
BGP router identifier 10.1.1.1, local AS number
6001
BGP table version is 10, main routing table version
10
9 network entries using 1188 bytes of memory
17 path entries using 884 bytes of memory
8/5 BGP path/bestpath attribute entries using 1344
bytes of memory
5 BGP AS-PATH entries using 120 bytes of memory
0 BGP route-map cache entries using 0 bytes of
memory
0 BGP filter-list cache entries using 0 bytes of
memory
Bitfield cache entries: current 1 (at peak 1) using
32 bytes of memory
BGP using 3568 total bytes of memory
BGP activity 9/0 prefixes, 17/0 paths, scan
interval 60 secs
Neighbor V
AS MsgRcvd MsgSent TblVer InQ OutQ
Up/Down State/PfxRcd
1.1.1.2
4 6023 29
31 10 0 0
00:25:25 7
5.5.5.1
4 6005 30
31 10 0 0
00:25:24 8
AS6023-R2-(config)#router bgp 6023
AS6023-R2-(config-router)#neighbor 1.1.1.1 remote-as 6001
AS6023-R2-(config-router)#neighbor 2.2.2.2 remote-as 6023
AS6023-R2-(config-router)#neighbor 2.2.2.2 next-hop-self
AS6023-R2-(config-router)#network 192.168.20.0 mask 255.255.255.0
AS6023-R2-(config-router)#network 20.0.0.0 mask 255.255.255.0
AS6023-R2-(config-router)#network 1.0.0.0
AS6023-R2-(config-router)#network 2.0.0.0
AS6023-R2-(config-router)#no auto-summary
AS6023-R2-(config-router)#no synchronization
AS6023-R2-(config-router)#exit
AS6023-R2-#show ip route bgp
B 3.0.0.0/8 [200/0]
via 2.2.2.2, 00:29:32
B 192.168.30.0/24
[200/0] via 2.2.2.2, 00:29:32
B 4.0.0.0/8 [200/0]
via 2.2.2.2, 00:29:29
B 5.0.0.0/8 [20/0]
via 1.1.1.1, 00:29:33
B 192.168.10.0/24 [20/0] via 1.1.1.1,
00:01:35
B 192.168.40.0/24
[200/0] via 2.2.2.2, 00:29:29
B 192.168.50.0/24
[20/0] via 1.1.1.1, 00:29:06
AS6023-R2-#show ip bgp summary
BGP router identifier 20.1.1.1, local AS number
6023
BGP table version is 11, main routing table version
11
9 network entries using 1188 bytes of memory
13 path entries using 676 bytes of memory
7/5 BGP path/bestpath attribute entries using 1176
bytes of memory
4 BGP AS-PATH entries using 96 bytes of memory
0 BGP route-map cache entries using 0 bytes of
memory
0 BGP filter-list cache entries using 0 bytes of
memory
Bitfield cache entries: current 3 (at peak 3) using
96 bytes of memory
BGP using 3232 total bytes of memory
BGP activity 9/0 prefixes, 13/0 paths, scan
interval 60 secs
Neighbor V
AS MsgRcvd MsgSent TblVer InQ OutQ
Up/Down State/PfxRcd
1.1.1.1
4 6001 37
35 11 0 0
00:31:31 4
2.2.2.2
4 6023 35
35 11 0 0
00:31:22 6
AS6023-R3-(config)#router bgp 6023
AS6023-R3-(config-router)#neighbor 2.2.2.1 remote-as 6023
AS6023-R3-(config-router)#neighbor 2.2.2.1 remote-as 6023
AS6023-R3-(config-router)#neighbor 3.3.3.2 remote-as 6004
AS6023-R3-(config-router)#neighbor 2.2.2.1 next-hop-self
AS6023-R3-(config-router)#network 192.168.30.0 mask 255.255.255.0
AS6023-R3-(config-router)#network 30.0.0.0 mask 255.255.255.0
AS6023-R3-(config-router)#network 3.0.0.0
AS6023-R3-(config-router)#network 2.0.0.0
AS6023-R3-(config-router)#no auto-summary
AS6023-R3-(config-router)#no synchronization
AS6023-R3-(config-router)#exit
AS6023-R3-#show ip route bgp
B 1.0.0.0/8 [200/0]
via 2.2.2.1, 00:33:25
B 4.0.0.0/8 [20/0]
via 3.3.3.2, 00:33:22
B 5.0.0.0/8 [200/0]
via 2.2.2.1, 00:33:25
B 192.168.10.0/24 [200/0] via 2.2.2.1,
00:02:17
B 192.168.40.0/24
[20/0] via 3.3.3.2, 00:33:22
B 192.168.20.0/24
[200/0] via 2.2.2.1, 00:33:25
B 192.168.50.0/24
[20/0] via 3.3.3.2, 00:33:22
AS6023-R3-#show ip bgp
BGP table version is 10, local router ID is
30.1.1.1
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
*>i1.0.0.0
2.2.2.1 0
100 0 i
* i2.0.0.0
2.2.2.1 0
100 0 i
*>
0.0.0.0
0 32768 i
* 3.0.0.0
3.3.3.2 0
0 6004 i
*>
0.0.0.0
0 32768 i
*> 4.0.0.0
3.3.3.2 0
0 6004 i
* 5.0.0.0
3.3.3.2
0 6004 6005 i
*>i
2.2.2.1
0 100 0 6001 i
* 192.168.10.0
3.3.3.2
0 6004 6005 6001 i
*>i
2.2.2.1
0 100 0
6001 i
*>i192.168.20.0
2.2.2.1
0 100 0 i
*> 192.168.30.0
0.0.0.0
0 32768 i
*> 192.168.40.0
3.3.3.2
0 0 6004 i
* i192.168.50.0
2.2.2.1
0 100 0 6001 6005 i
*>
3.3.3.2
0 6004 6005 i
AS6004-R4-(config)#router bgp 6004
AS6004-R4-(config-router)#neighbor 3.3.3.1 remote-as 6023
AS6004-R4-(config-router)#neighbor 4.4.4.2 remote-as 6005
AS6004-R4-(config-router)#network 192.168.40.0 mask 255.255.255.0
AS6004-R4-(config-router)#network 40.0.0.0 mask 255.255.255.0
AS6004-R4-(config-router)#network 3.0.0.0
AS6004-R4-(config-router)#network 4.0.0.0
AS6004-R4-(config-router)#no auto-summary
AS6004-R4-(config-router)#no synchronization
AS6004-R4-(config-router)#exit
AS6004-R4-#show ip route bgp
B 1.0.0.0/8 [20/0]
via 3.3.3.1, 00:38:47
B 2.0.0.0/8 [20/0]
via 3.3.3.1, 00:38:47
B 192.168.30.0/24
[20/0] via 3.3.3.1, 00:38:47
B 5.0.0.0/8 [20/0]
via 4.4.4.2, 00:38:47
B 192.168.20.0/24
[20/0] via 3.3.3.1, 00:38:47
B 192.168.50.0/24
[20/0] via 4.4.4.2, 00:38:47
AS6004-R4-#show ip bgp
BGP table version is 10, local router ID is
40.1.1.1
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.0.0.0
4.4.4.2
0 6005 6001 i
*>
3.3.3.1
0 6023 i
*> 2.0.0.0
3.3.3.1 0
0 6023 i
* 3.0.0.0
3.3.3.1 0
0 6023 i
*>
0.0.0.0
0 32768 i
* 4.0.0.0
4.4.4.2 0
0 6005 i
*>
0.0.0.0
0 32768 i
*> 5.0.0.0
4.4.4.2 0
0 6005 i
*
3.3.3.1
0 6023 6001 i
* 192.168.10.0
3.3.3.1
0 6023 6001 i
*>
4.4.4.2
0
6005 6001 i
*> 192.168.20.0
3.3.3.1
0 6023 i
*> 192.168.30.0
3.3.3.1
0 0 6023 i
*> 192.168.40.0
0.0.0.0
0 32768 i
*> 192.168.50.0
4.4.4.2
0 0 6005 i
AS6005-R5-(config)#router bgp 6005
AS6005-R5-(config-router)#neighbor 4.4.4.1 remote-as 6004
AS6005-R5-(config-router)#neighbor 4.4.4.1 remote-as 6001
AS6005-R5-(config-router)#neighbor 5.5.5.2 remote-as 6001
AS6005-R5-(config-router)#network 192.168.50.0 mask 255.255.255.0
AS6005-R5-(config-router)#network 50.0.0.0 mask 255.255.255.0
AS6005-R5-(config-router)#network 5.0.0.0
AS6005-R5-(config-router)#network 4.0.0.0
AS6005-R5-(config-router)#no auto-summary
AS6005-R5-(config-router)#no synchronization
AS6005-R5-(config-router)#exit
AS6005-R5-#show ip route bgp
B 1.0.0.0/8 [20/0]
via 5.5.5.2, 00:39:33
B 2.0.0.0/8 [20/0]
via 4.4.4.1, 00:39:32
B 3.0.0.0/8 [20/0]
via 4.4.4.1, 00:39:32
B 192.168.10.0/24 [20/0] via 5.5.5.2,
00:05:06
B 192.168.30.0/24
[20/0] via 4.4.4.1, 00:39:32
B 192.168.40.0/24
[20/0] via 4.4.4.1, 00:39:32
B 192.168.20.0/24
[20/0] via 4.4.4.1, 00:39:32
AS6005-R5-#show ip bgp
BGP table version is 10, local router ID is
192.168.50.1
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.0.0.0
4.4.4.1
0 6004 6023 i
*>
5.5.5.2
0 0 6001 i
* 2.0.0.0
5.5.5.2
0 6001 6023 i
*>
4.4.4.1
0 6004 6023 i
* 3.0.0.0
5.5.5.2
0 6001 6023 i
*>
4.4.4.1
0 0 6004 i
* 4.0.0.0
4.4.4.1 0
0 6004 i
*>
0.0.0.0
0 32768 i
* 5.0.0.0
5.5.5.2 0
0 6001 i
*>
0.0.0.0
0 32768 i
*> 192.168.10.0
5.5.5.2
0 0 6001 i
* 192.168.20.0
5.5.5.2
0 6001 6023 i
*>
4.4.4.1
0
6004 6023 i
* 192.168.30.0
5.5.5.2
0 6001 6023 i
*>
4.4.4.1
0
6004 6023 i
* 192.168.40.0
5.5.5.2
0 6001 6023 6004 i
*>
4.4.4.1
0 0
6004 i
*> 192.168.50.0
0.0.0.0
0 32768 i
AS-6001-R1-#traceroute 192.168.20.1
Type escape sequence to abort.
Tracing the route to 192.168.20.1
1 1.1.1.2 20 msec 28 msec 36 msec
{As you can see, to reach 192.168.20.1/24 router 1
(6001) is using path serial 4/0 because this path has less number of AS. Our
task is, to reach any or 192.168.20.1/24 network from AS 6001 router 1 should
use the path 6005+6004+6023}
AS-6001-R1-#show ip bgp 192.168.20.1
BGP routing table entry for 192.168.20.0/24,
version 4
Paths: (2 available, best #2, table
Default-IP-Routing-Table)
Advertised to update-groups:
1
6005
6004 6023
5.5.5.1 from
5.5.5.1 (192.168.50.1)
Origin IGP,
localpref 100, valid, external
6023
1.1.1.2 from
1.1.1.2 (20.1.1.1)
Origin IGP,
metric 0, localpref 100, valid, external, best
configure AS 6001 (R-1) should exit via AS
6005 to reach 192.168.20.1 or any network.
configure weight attribute on (AS 6001)
AS-6001-R1-(config)#router bgp 6001
AS-6001-R1-(config-router)#neighbor 5.5.5.1 weight
3000
AS-6001-R1-(config-router)#end
AS-6001-R1-#clear ip bgp * soft
AS-6001-R1-#traceroute 192.168.20.1
Type escape sequence to abort.
Tracing the route to 192.168.20.1
1
5.5.5.1 16 msec 28 msec 32 msec
2 4.4.4.1 [AS 6005] 76
msec 64 msec 72 msec
3 3.3.3.1 [AS 6004] 68
msec 88 msec 68 msec
4 2.2.2.1 [AS 6023] 76
msec 76 msec 80 msec
AS-6001-R1-#show ip bgp 192.168.20.1 bestpath
BGP routing table entry for
192.168.20.0/24, version 17
Paths: (2 available, best #1,
table Default-IP-Routing-Table)
Advertised to
update-groups:
1
6005 6004 6023
5.5.5.1 from
5.5.5.1 (192.168.50.1)
Origin IGP,
localpref 100, weight
3000, valid,
external, best
{as you can see now AS 6001 is using the path that
we configure via 6005+ 6004+6023}
AS-6001-R1-(config)#route-map INTERNETWORKS 1
AS-6001-R1-(config-route-map)#set metric 130
AS-6001-R1-(config-route-map)#set as-path prepend
600
AS-6001-R1-(config-route-map)#exit
AS-6001-R1-(config)#router bgp 6001
AS-6001-R1-(config-router)#neighbor 1.1.1.2
route-map INTERNETWORKS out
AS-6001-R1-(config-router)#end
AS-6001-R1-#clear ip bgp * soft
AS6023-R2-#traceroute 192.168.10.1
Type escape sequence to abort.
Tracing the route to 192.168.10.1
1 1.1.1.1 20 msec 24 msec
36 msec
AS6023-R2-#show ip bgp 192.168.10.1
BGP routing table entry for 192.168.10.0/24,
version 13
Paths: (1 available, best #1, table
Default-IP-Routing-Table)
Flag: 0x820
Advertised to update-groups:
1
6001 600
1.1.1.1 from 1.1.1.1 (10.1.1.1)
Origin IGP, metric 130,
localpref 100, valid, external, best
{but the return traffic is not
using the same path 6004+6005+6001 instead it's using 6001 serial 4/0}
make sure AS 6001 return traffic
should use the same path which it exits via 6005,6004,6003 and 6023
configure MED on and MED compare
to tell BGP router to compare MED in the entire 6023 AS.
AS6023-R2-(config)#router bgp 6023
AS6023-R2-(config-router)#bgp bestpath as-path
ignore
AS6023-R2-(config-router)#bgp always-compare-med
AS6023-R2-(config-router)#exit
AS6023-R2-#clear ip bgp * soft
AS6023-R3-(config)#router bgp 6023
AS6023-R3-(config-router)#bgp bestpath as-path
ignore
AS6023-R3-(config-router)#bgp always-compare-med
AS6023-R3-(config-router)#exit
AS6023-R3-(config)#end
AS6023-R3-#clear ip bgp * soft
AS6023-R2-#traceroute 192.168.10.1
Type escape sequence to abort.
Tracing the route to 192.168.10.1
1
2.2.2.2 20 msec 24 msec 32 msec
2 3.3.3.2 76 msec 52 msec
80 msec
3 4.4.4.2 [AS 6004] 80
msec 84 msec 80 msec
4 5.5.5.2 [AS 6005] 68
msec 80 msec 72 msec
AS6023-R2-#show ip bgp 192.168.10.1/24 bestpath
BGP routing table entry for 192.168.10.0/24,
version 11
Paths: (2 available, best #1, table
Default-IP-Routing-Table)
Flag: 0x820
Advertised to update-groups:
2
6004
6005 6001
2.2.2.2 from
2.2.2.2 (30.1.1.1)
Origin IGP,
metric 0, localpref 100, valid, internal, best