MED(Multi-Exit Discriminator)
MED(Multi-Exit Discriminator)는 BGP에서 Metric이라고도 불리며, 동일한 AS(Autonomous System)으로 들어오는 여러 경로 중 어느 경로를 선택할지 결정하는 데 사용됩니다. 일반적으로 AS 내부의 여러 경로 중 특정 경로를 더 선호하도록 하기 위해 설정됩니다.
MED는 상대 AS가 선택하도록 제공하는 경로 우선순위 힌트의 역할을 하며, 값이 작을수록 더 선호됩니다. 그러나 MED는 iBGP 내에서만 전파되며, 다른 eBGP 피어에게는 전달되지 않는다는 특징이 있습니다. 따라서, AS 간의 트래픽 흐름을 조정하기 위해서는 해당 값이 올바르게 해석될 수 있도록 상대 AS와의 정책 조율이 필요합니다.
이번 글에서는 MED의 개념과 동작 방식, 그리고 네트워크에서 이를 활용하는 방법에 대해 자세히 살펴보겠습니다.
AS 100에서 들어오는 트래픽을 R3으로 유도하기 위해 R4의 MED 값을 높여서 R2에게 전파합니다.
[기존 MED 0으로 적용]
R4#show run route-map
!
route-map rmap-MED permit 10
set metric 0
==================================
[기존 MED 0 -> 100으로 변경]
R4#show run route-map
!
route-map rmap-MED permit 10
set metric 100
R4#show run bgp
!
router bgp 200
bgp router-id 4.4.4.4
network 140.4.0.0/24
network 140.4.1.0/24
network 140.4.2.0/24
timers bgp 2 6
neighbor 3.3.3.3 remote-as 200
neighbor 3.3.3.3 update-source Loopback 1
neighbor 3.3.3.3 timers 2 6
neighbor 3.3.3.3 next-hop-self
neighbor 3.3.3.3 soft-reconfiguration inbound
neighbor 3.3.3.3 no shutdown
neighbor 10.10.24.2 remote-as 100
neighbor 10.10.24.2 route-map rmap-MED out
neighbor 10.10.24.2 timers 2 6
neighbor 10.10.24.2 soft-reconfiguration inbound
neighbor 10.10.24.2 no shutdown
R4#clear ip bgp 10.10.24.2 soft out
MED 조정 후 R4에서 R2에게 광고하는 정보 확인 시 MED 100으로 광고하고 있습니다.
R4#show ip bgp neighbors 10.10.24.2 advertised-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 4.4.4.4
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 130.3.0.0/24 10.10.24.4 100 0 0 200 i
*> 130.3.1.0/24 10.10.24.4 100 0 0 200 i
*> 130.3.2.0/24 10.10.24.4 100 0 0 200 i
*> 140.4.0.0/24 10.10.24.4 100 0 0 200 i
*> 140.4.1.0/24 10.10.24.4 100 0 0 200 i
*> 140.4.2.0/24 10.10.24.4 100 0 0 200 i
Total number of prefixes: 6
R2에서 R4에게 전달받는 정보 확인 시 MED 100으로 전달 받고 있습니다.
R2#show ip bgp neighbors 10.10.24.4 received-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 2.2.2.2
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 130.3.0.0/24 10.10.24.4 100 0 200 i
* 130.3.1.0/24 10.10.24.4 100 0 200 i
* 130.3.2.0/24 10.10.24.4 100 0 200 i
* 140.4.0.0/24 10.10.24.4 100 0 200 i
* 140.4.1.0/24 10.10.24.4 100 0 200 i
* 140.4.2.0/24 10.10.24.4 100 0 200 i
R4에서 전달 받은 정보는 MED 100으로 우선 순위에 밀려 R1에서 전달받은 경로가 Best Path로 선정됩니다.
이로써 AS 100에서 AS 200에 대한 경로는 R1→R3으로 들어가게 됩니다.
[R2 BGP 테이블]
R2#show ip bgp
...
Network Next Hop Metric LocPrf Weight Path
*>I 110.1.0.0/24 1.1.1.1 0 100 0 i
*>I 110.1.1.0/24 1.1.1.1 0 100 0 i
*>I 110.1.2.0/24 1.1.1.1 0 100 0 i
*>n 120.2.0.0/24 0.0.0.0 0 32768 i
*>n 120.2.1.0/24 0.0.0.0 0 32768 i
*>n 120.2.2.0/24 0.0.0.0 0 32768 i
*>I 130.3.0.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 130.3.1.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 130.3.2.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 140.4.0.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 140.4.1.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 140.4.2.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
====================================================================
R2#show ip bgp 140.4.0.0
BGP routing table entry for 140.4.0.0/24
Paths: (2 available, table Default-IP-Routing-Table.)
Advertised to :
10.10.24.4
Received from :
10.10.24.4 (4.4.4.4)
AS_PATH : 200
Next-Hop : 10.10.24.4, Cost : 0
Origin IGP, Metric 100, LocalPref 100, Weight 0, external
Inactive reason: MED
Received from :
1.1.1.1 (1.1.1.1) Best
AS_PATH : 200
Next-Hop : 1.1.1.1, Cost : 1
Origin IGP, Metric 0, LocalPref 100, Weight 0, internal
[R1 BGP 테이블]
R1#show ip bgp
...
Network Next Hop Metric LocPrf Weight Path
*>n 110.1.0.0/24 0.0.0.0 0 32768 i
*>n 110.1.1.0/24 0.0.0.0 0 32768 i
*>n 110.1.2.0/24 0.0.0.0 0 32768 i
*>I 120.2.0.0/24 2.2.2.2 0 100 0 i
*>I 120.2.1.0/24 2.2.2.2 0 100 0 i
*>I 120.2.2.0/24 2.2.2.2 0 100 0 i
*> 130.3.0.0/24 10.10.13.3 0 0 200 i
*> 130.3.1.0/24 10.10.13.3 0 0 200 i
*> 130.3.2.0/24 10.10.13.3 0 0 200 i
*> 140.4.0.0/24 10.10.13.3 0 0 200 i
*> 140.4.1.0/24 10.10.13.3 0 0 200 i
*> 140.4.2.0/24 10.10.13.3 0 0 200 i
추가) R1 경로 정보 확인 - AS 200 대체 경로 미존재 이유
추가로 R1의 BGP 테이블 확인 시 AS 200에 대한 경로는 R3으로 가는 경로를 Best Path로 선정되어 있습니다.
그러나 AS 200에 대한 대체 경로(R2→R4)가 없어 확인을 해보니 R4가 광고한 AS 200 정보를 R2를 통해서 전달 받지 못하고 있습니다.
R1#show ip bgp
...
Network Next Hop Metric LocPrf Weight Path
*>n 110.1.0.0/24 0.0.0.0 0 32768 i
*>n 110.1.1.0/24 0.0.0.0 0 32768 i
*>n 110.1.2.0/24 0.0.0.0 0 32768 i
*>I 120.2.0.0/24 2.2.2.2 0 100 0 i
*>I 120.2.1.0/24 2.2.2.2 0 100 0 i
*>I 120.2.2.0/24 2.2.2.2 0 100 0 i
*> 130.3.0.0/24 10.10.13.3 0 0 200 i
*> 130.3.1.0/24 10.10.13.3 0 0 200 i
*> 130.3.2.0/24 10.10.13.3 0 0 200 i
*> 140.4.0.0/24 10.10.13.3 0 0 200 i
*> 140.4.1.0/24 10.10.13.3 0 0 200 i
*> 140.4.2.0/24 10.10.13.3 0 0 200 i
====================================================================
R1#show ip bgp neighbors 2.2.2.2 received-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 1.1.1.1
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>I 120.2.0.0/24 2.2.2.2 0 100 0 i
*>I 120.2.1.0/24 2.2.2.2 0 100 0 i
*>I 120.2.2.0/24 2.2.2.2 0 100 0 i
R2는 R4로 부터 AS 200 대역에 대한 정보를 받았습니다.
그러나 BGP는 route advertisement rules에 따라 Best로 선정된 경로에 대해서만 다른 BGP Peer에게 광고하기에 Best Path인 R1에게는 AS 200에 대한 경로를 광고하지 않습니다.
R1에서는 R3에게 받은 AS 200에 대한 경로 정보가 Best Path로 되었기에 R2에게 광고를 하게 됩니다.
R2#show ip bgp neighbors 1.1.1.1 advertised-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 2.2.2.2
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 120.2.0.0/24 2.2.2.2 0 100 0 i
*> 120.2.1.0/24 2.2.2.2 0 100 0 i
*> 120.2.2.0/24 2.2.2.2 0 100 0 i
Total number of prefixes: 3
====================================================================
R1#show ip bgp neighbors 2.2.2.2 advertised-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 1.1.1.1
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 110.1.0.0/24 1.1.1.1 0 100 0 i
*> 110.1.1.0/24 1.1.1.1 0 100 0 i
*> 110.1.2.0/24 1.1.1.1 0 100 0 i
*> 130.3.0.0/24 1.1.1.1 0 100 0 200 i
*> 130.3.1.0/24 1.1.1.1 0 100 0 200 i
*> 130.3.2.0/24 1.1.1.1 0 100 0 200 i
*> 140.4.0.0/24 1.1.1.1 0 100 0 200 i
*> 140.4.1.0/24 1.1.1.1 0 100 0 200 i
*> 140.4.2.0/24 1.1.1.1 0 100 0 200 i
Total number of prefixes: 9
====================================================================
R2#show ip bgp neighbors 1.1.1.1 received-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 2.2.2.2
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>I 110.1.0.0/24 1.1.1.1 0 100 0 i
*>I 110.1.1.0/24 1.1.1.1 0 100 0 i
*>I 110.1.2.0/24 1.1.1.1 0 100 0 i
*>I 130.3.0.0/24 1.1.1.1 0 100 0 200 i
*>I 130.3.1.0/24 1.1.1.1 0 100 0 200 i
*>I 130.3.2.0/24 1.1.1.1 0 100 0 200 i
*>I 140.4.0.0/24 1.1.1.1 0 100 0 200 i
*>I 140.4.1.0/24 1.1.1.1 0 100 0 200 i
*>I 140.4.2.0/24 1.1.1.1 0 100 0 200 i
Total number of prefixes: 9
MED (AS 200 R3 Network 경로 조정)
AS 200에서 R3에 대한 경로(130.3.0.0~2.0)만 조정하기 위해 R4의 MED 값을 조정합니다.
- R4 MED
- R3 Network(130.3.x.x/24) MED : 100
- R4 Network(140.4.x.x/24) MED : 0
MED값을 조정하여 목적지 대역에 따라 트래픽 인입 경로를 조정합니다. (R4 Network MED 0 조정은 다른 대역과 동일하게 적용 - Default MED 0)
R3 대역을 목적지로 하는 트래픽은 R3을 통해 AS 200 내부로 인입되고, R4 대역은 R1, R2 각각 라우터의 eBGP 경로를 통해 R1→R3, R2→R4로 인입됩니다.
[Prefix List] // R3 대역에 대한 Prefix List 설정
R4#show run prefix-list
!
ip prefix-list R3
seq 10 permit 130.3.0.0/24
seq 20 permit 130.3.1.0/24
seq 30 permit 130.3.2.0/24
seq 100 deny any
[Route Map] // MED 100 route map에 prefix list 적용
R4#show run route-map
!
route-map rmap-MED permit 10
match ip address R3
set metric 100
!
route-map rmap-MED permit 20
R4#clear ip bgp 10.10.24.2 soft out
R4에서 R2에게 AS 200에 대한 정보 전달 시 R3 대역에 대한 경로만 MED 100으로 전달 합니다.
R4#show ip bgp neighbors 10.10.24.2 advertised-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 4.4.4.4
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 130.3.0.0/24 10.10.24.4 100 0 0 200 i
*> 130.3.1.0/24 10.10.24.4 100 0 0 200 i
*> 130.3.2.0/24 10.10.24.4 100 0 0 200 i
*> 140.4.0.0/24 10.10.24.4 0 0 0 200 i
*> 140.4.1.0/24 10.10.24.4 0 0 0 200 i
*> 140.4.2.0/24 10.10.24.4 0 0 0 200 i
Total number of prefixes: 6
====================================================================
R2#show ip bgp neighbors 10.10.24.4 received-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 2.2.2.2
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 130.3.0.0/24 10.10.24.4 100 0 200 i
* 130.3.1.0/24 10.10.24.4 100 0 200 i
* 130.3.2.0/24 10.10.24.4 100 0 200 i
*> 140.4.0.0/24 10.10.24.4 0 0 200 i
*> 140.4.1.0/24 10.10.24.4 0 0 200 i
*> 140.4.2.0/24 10.10.24.4 0 0 200 i
R2 BGP 테이블에서 R4로 부터 전달받은 R3 대역에 대한 경로는 MED 값이 높아 Best Path로 선정되지 못하고 R1에서 전달한 경로가 Best Path로 선정되었습니다.
R4 대역에 대한 경로는 MED 값이 조정되지 않았기에 R4 경로가 Best Path로 선정되었습니다. (eBGP 경로 우선 선출)
[R2 BGP 테이블]
R2#show ip bgp
...
Network Next Hop Metric LocPrf Weight Path
*>I 110.1.0.0/24 1.1.1.1 0 100 0 i
*>I 110.1.1.0/24 1.1.1.1 0 100 0 i
*>I 110.1.2.0/24 1.1.1.1 0 100 0 i
*>n 120.2.0.0/24 0.0.0.0 0 32768 i
*>n 120.2.1.0/24 0.0.0.0 0 32768 i
*>n 120.2.2.0/24 0.0.0.0 0 32768 i
*>I 130.3.0.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 130.3.1.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
*>I 130.3.2.0/24 1.1.1.1 0 100 0 200 i
* 10.10.24.4 100 0 200 i
* I 140.4.0.0/24 1.1.1.1 0 100 0 200 i
*> 10.10.24.4 0 0 200 i
* I 140.4.1.0/24 1.1.1.1 0 100 0 200 i
*> 10.10.24.4 0 0 200 i
* I 140.4.2.0/24 1.1.1.1 0 100 0 200 i
*> 10.10.24.4 0 0 200 i
====================================================================
R2#show ip bgp 130.3.0.0
BGP routing table entry for 130.3.0.0/24
Paths: (2 available, table Default-IP-Routing-Table.)
Advertised to :
10.10.24.4
Received from :
10.10.24.4 (4.4.4.4)
AS_PATH : 200
Next-Hop : 10.10.24.4, Cost : 0
Origin IGP, Metric 100, LocalPref 100, Weight 0, external
Inactive reason: MED
Received from :
1.1.1.1 (1.1.1.1) Best
AS_PATH : 200
Next-Hop : 1.1.1.1, Cost : 1
Origin IGP, Metric 0, LocalPref 100, Weight 0, internal
이처럼 단일 AS에서 인입되는 경로가 여러개인 경우 MED 값을 통해 경로를 조정할 수 있습니다.
추가) 경로 정보 확인 - AS 200 R3 Network 대체 경로 미존재 이유
R1의 BGP 테이블 확인 시 R4에 대한 경로는 R2(2.2.2.2), R3(10.10.13.3) 두 가지 경로가 존재합니다.
그러나 R3에 대한 경로는 R3으로 보내는 하나의 경로만 존재합니다.
[R1 BGP 테이블]
R1#show ip bgp
...
Network Next Hop Metric LocPrf Weight Path
*>n 110.1.0.0/24 0.0.0.0 0 32768 i
*>n 110.1.1.0/24 0.0.0.0 0 32768 i
*>n 110.1.2.0/24 0.0.0.0 0 32768 i
*>I 120.2.0.0/24 2.2.2.2 0 100 0 i
*>I 120.2.1.0/24 2.2.2.2 0 100 0 i
*>I 120.2.2.0/24 2.2.2.2 0 100 0 i
*> 130.3.0.0/24 10.10.13.3 0 0 200 i
*> 130.3.1.0/24 10.10.13.3 0 0 200 i
*> 130.3.2.0/24 10.10.13.3 0 0 200 i
* I 140.4.0.0/24 2.2.2.2 0 100 0 200 i
*> 10.10.13.3 0 0 200 i
* I 140.4.1.0/24 2.2.2.2 0 100 0 200 i
*> 10.10.13.3 0 0 200 i
* I 140.4.2.0/24 2.2.2.2 0 100 0 200 i
*> 10.10.13.3 0 0 200 i
====================================================================
R1#show ip bgp 140.4.0.0
BGP routing table entry for 140.4.0.0/24
Paths: (2 available, table Default-IP-Routing-Table.)
Advertised to :
2.2.2.2
Received from :
2.2.2.2 (2.2.2.2)
AS_PATH : 200
Next-Hop : 2.2.2.2, Cost : 1
Origin IGP, Metric 0, LocalPref 100, Weight 0, internal
Inactive reason: from non external peer
Received from :
10.10.13.3 (3.3.3.3) Best
AS_PATH : 200
Next-Hop : 10.10.13.3, Cost : 0
Origin IGP, Metric 0, LocalPref 100, Weight 0, external
마찬가지로 R2에서 Best Path로 선정된 R4대역에 대해서만 R1에게 광고를 하기 때문입니다.
R1은 R2로 부터 R3 대역에 대한 정보를 전달받지 못했기에 R3 하나의 경로만 저장하게 됩니다.
R2#show ip bgp neighbors 1.1.1.1 advertised-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 2.2.2.2
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 120.2.0.0/24 2.2.2.2 0 100 0 i
*> 120.2.1.0/24 2.2.2.2 0 100 0 i
*> 120.2.2.0/24 2.2.2.2 0 100 0 i
*> 140.4.0.0/24 2.2.2.2 0 100 0 200 i
*> 140.4.1.0/24 2.2.2.2 0 100 0 200 i
*> 140.4.2.0/24 2.2.2.2 0 100 0 200 i
Total number of prefixes: 6
====================================================================
R1#show ip bgp neighbors 2.2.2.2 received-routes
BGP local RIB : Routes to be Added 0, Replaced 0, Withdrawn 0
BGP local router ID is 1.1.1.1
Status codes: s suppressed, S stale, d dampened, h history, * valid, > best
Path source: I - internal, a - aggregate, c - confed-external, r - redistributed
n - network, D - denied, S - stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>I 120.2.0.0/24 2.2.2.2 0 100 0 i
*>I 120.2.1.0/24 2.2.2.2 0 100 0 i
*>I 120.2.2.0/24 2.2.2.2 0 100 0 i
* I 140.4.0.0/24 2.2.2.2 0 100 0 200 i
* I 140.4.1.0/24 2.2.2.2 0 100 0 200 i
* I 140.4.2.0/24 2.2.2.2 0 100 0 200 i
[참고 사이트]
'Network > BGP' 카테고리의 다른 글
[BGP] Next-Hop 이슈 및 해결방안 2가지 (0) | 2025.02.16 |
---|---|
[BGP] BGP 연동 실습#5 - Attribute를 이용한 경로 조정 (AS Prepend) (0) | 2025.02.10 |
[BGP] BGP 연동 실습#3 - Attribute를 이용한 경로 조정 (Local Preference) (0) | 2025.01.27 |
[BGP] BGP 연동 실습#2 - 특정 네트워크 광고 허용/거부 정책 적용 (Filtering) (0) | 2025.01.17 |
[BGP] Split Horizon 방지를 위한 Route-Reflector란? (0) | 2024.12.28 |