본문 바로가기
네트워크

BGP #3(weight,local preference,MED)

by CBROJIN 2025. 4. 12.

[학습 목표]

1) BGP weight

2) BGP local preference

3) BGP MED

 

실습 토폴로지

BGP 설정
R1(config)#int e0/0
R1(config-if)#ip add 1.1.12.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#int e0/1
R1(config-if)#ip add 1.1.13.1 255.255.255.0
R1(config-if)#no shut
R1(config)#int e0/0
R1(config-if)#ip ospf network point-to-point
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#ip ospf network point-to-point
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 1.1.1.0 0.0.0.255 area 0
R1(config-router)#network 1.1.12.1 0.0.0.0 area 0
R1(config-router)#passive-interface e0/1
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 1.1.13.3 remote-as 2
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source lo0
R1(config-router)#neighbor 2.2.2.2 next-hop-self
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
R2(config)#int e0/0
R2(config-if)#ip add 1.1.12.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int e0/2
R2(config-if)#ip add 1.1.24.2 255.255.255.0
R2(config-if)#no shut
R2(config)#int e0/0
R2(config-if)#ip ospf network point-to-point
R2(config-if)#int lo0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#ip ospf network point-to-point
R2(config-if)#exit
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
R2(config-router)#network 1.1.12.2 0.0.0.0 area 0
R2(config-router)#passive-interface e0/2
R2(config)#router bgp 1
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 1.1.24.4 remote-as 2
R2(config-router)#neighbor 1.1.1.1 remote-as 1
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 1.1.1.1 next-hop-self
R2(config-router)#network 2.2.2.0 mask 255.255.255.0
R3(config)#int e0/0
R3(config-if)#ip add 1.1.34.3 255.255.255.0
R3(config-if)#no shut
R3(config-if)#int e0/1
R3(config-if)#ip add 1.1.13.3 255.255.255.0
R3(config-if)#no shut
R3(config)#int e0/0
R3(config-if)#ip ospf network point-to-point
R3(config-if)#int lo0 
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#ip ospf network point-to-point
R3(config-if)#exit
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R3(config-router)#network 1.1.34.3 0.0.0.0 area 0
R3(config-router)#passive-interface e0/1
R3(config)#router bgp 2
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 1.1.13.1 remote-as 1
R3(config-router)#neighbor 4.4.4.4 remote-as 2
R3(config-router)#neighbor 4.4.4.4 update-source lo0
R3(config-router)#neighbor 4.4.4.4 next-hop-self
R3(config-router)#network 3.3.3.0 mask 255.255.255.0

local preference 설정
R3(config)#ip prefix-list R2ONLY seq 5 permit 2.2.2.0/24
R3(config)#route-map locR2ONLY permit 10
R3(config-route-map)#match ip address prefix-list R2ONLY
R3(config-route-map)#set local-preference 200
R3(config-route-map)#exit
R3(config)#route-map locR2ONLY permit 20 
R3(config-route-map)#exit
R3(config)#router bgp 2
R3(config-router)#neighbor 4.4.4.4 route-map locR2ONLY in

R4(config)#int e0/0
R4(config-if)#ip add 1.1.34.4 255.255.255.0
R4(config-if)#no shut
R4(config-if)#int e0/2
R4(config-if)#ip add 1.1.24.4 255.255.255.0
R4(config-if)#no shut
R4(config)#int e0/0
R4(config-if)#ip ospf network point-to-point
R4(config-if)#int lo0
R4(config-if)#ip add 4.4.4.4 255.255.255.0
R4(config-if)#ip ospf network point-to-point
R4(config-if)#exit
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0
R4(config-router)#network 1.1.34.4 0.0.0.0 area 0 
R4(config-router)#passive-interface e0/2
R4(config)#router bgp 2
R4(config-router)#bgp router-id 4.4.4.4
R4(config-router)#neighbor 1.1.24.2 remote-as 1
R4(config-router)#neighbor 3.3.3.3 remote-as 2
R4(config-router)#neighbor 3.3.3.3 update-source lo0
R4(config-router)#neighbor 3.3.3.3 next-hop-self 
R4(config-router)#network 4.4.4.0 mask 255.255.255.0

weight 설정
R4(config-router)#neighbor 3.3.3.3 weight 300

R4(config)#router bgp 2
R4(config-router)#no neighbor 3.3.3.3 weight 300
R4(config)#ip prefix-list R1ONLY seq 5 permit 1.1.1.0/24
R4(config)#route-map WEIGHT_R1ONLY permit 10
R4(config-route-map)#match ip address prefix-list R1ONLY
R4(config-route-map)#set weight 300
R4(config-route-map)#exit
R4(config)#route-map WEIGHT_R1ONLY permit 20
R4(config-route-map)#router bgp 2
R4(config-router)#neighbor 3.3.3.3 route-map WEIGHT_R1ONLY in

1) BGP weight 란?

✅ 정의

BGP Weight는 Cisco 라우터 고유의 BGP Path Attribute로,
동일 라우터 안에서 경로 우선순위를 결정할 때 가장 먼저 고려되는 기준값이다.

  • 숫자가 클수록 우선순위 높음
  • 로컬 라우터에서만 유효함 (전파되지 않음)
  • 경로 선택 시 가장 먼저 고려되는 속성 (제일 높은 우선순위)
  • 빠르고 안전하게 특정 경로를 강제 선택할 수 있음
  • 내 라우터에서만 트래픽 우선 경로를 강제로 지정하고 싶을 때 사용

✅ 특징

항목 설명
범위 0 ~ 65535 (기본값: 0)
전파 여부 전파되지 않음 (이 라우터에만 적용)
우선순위 BGP Path Selection에서 가장 먼저 비교됨
설정 위치 수신 경로에 대해 적용 (inbound)
기본값 자신이 유입시킨 경로 = 32768, 그 외는 0

🔎 실습 1 : Neighbor 단위로 고정 weight 설정

( 목표 : R4 -> R1 경로를 R4 -> R2 -> R1 에서 R4 -> R3 -> R1으로 변경 )

R4 weight 300 설정 전(좌) 후(우)

# R4에서 R1 1.1.1.1 로 가는 경로는 기존에 R4 -> R2 -> R1 이였다.

R4(config-router)#neighbor 3.3.3.3 weight 300 설정 후 의도한대로 R4 -> R3 -> R1로 경로가 바뀌었다.

 

R4 -> R2 ping 경로

하지만 R3으로 부터 수신하는 경로 weight가 300으로 바뀌면서 R4 -> R2 lo0 2.2.2.2로 가는 경로도

R4 -> R3 -> R1 -> R2로 바뀌게 된 문제점이 생겼다.

🔎 실습 2 : route-map으로 특정 prefix에만 weight 설정

( 목표 : R4 -> R1 경로변경 한 R4 -> R3 -> R1을 1.1.1.0/24 Prefix에만 적용 ) 

neighbor weight 설정 후 R4(좌) / 특정 prefix route map 설정 후 R4(우)

R4(config)#router bgp 2
R4(config-router)#no neighbor 3.3.3.3 weight 300


R4(config)#ip prefix-list R1ONLY seq 5 permit 1.1.1.0/24
R4(config)#route-map WEIGHT_R1ONLY permit 10
R4(config-route-map)#match ip address prefix-list R1ONLY
R4(config-route-map)#set weight 300
R4(config-route-map)#exit
R4(config)#route-map WEIGHT_R1ONLY permit 20
R4(config-route-map)#router bgp 2
R4(config-router)#neighbor 3.3.3.3 route-map WEIGHT_R1ONLY in

 

# R4 -> R3 -> R1 -> R2로 바뀌게 된 문제점을 해결 하기 위해 특정 prefix(1.1.1.0/24)에 대해서만 route map을 적용했다.

neighbor 고정 weight 설정 시 Next hop 3.3.3.3 경로는 모두 weight 가 300으로 바뀐 문제가 있었지만,

특정 prefix route map 적용 후 1.1.1.0/24 에 대해서만 weight 300인 모습이다.(위 사진)

 

R4 -> R2 ping 경로

설정 후 R2 lo2 2.2.2.2로 가는 경로가 R4 -> R2로 바꼈다.


2) BGP local preference 란?

✅ 정의

Local Preference
BGP에서 AS 내부(iBGP 라우터들끼리) 트래픽이 외부로 나가는 경로를 선택할 때 사용하는 우선순위 값이다.

  • 숫자가 클수록 우선순위가 높음
  • iBGP 피어 간에 전파됨
  • AS 내부 전체에서 적용되는 전역 속성

✅ 특징

항목 내용
역할 AS 내부에서 외부로 나가는 경로 우선순위 결정
우선순위 방향 큰 값일수록 우선
기본값 Cisco IOS 기본값: 100
적용 범위 같은 AS 내부의 모든 iBGP 라우터에 전파됨
설정 위치 수신(inbound) 경로에서 조정 (route-map in)
경로 선택 우선순위 Weight 다음으로 가장 먼저 고려되는 속성

 

🔎 실습 : route-map으로 특정 prefix에만 local preference설정

( 목표 : R3 -> R2 경로를 R3 -> R1 -> R2 에서 R3 -> R4 -> R2로 변경 )

R3 BGP 테이블(좌) / R3 -> R2 경로(우)

 

# R3 -> R2 lo0 2.2.2.2 목적지로 갈때 Next Hop 4.4.4.4의 LocPrf가 100이고 1.1.13.1은 보이지 않지만(기본값 100)

Best 경로는 1.1.13.1로 되어 있다.(왼쪽 사진)

2.2.2.0/24에 대한 weight , LocPrf 값(모름)이 같고 두 경로다 iBGP에서 받아 왔기 때문에,

그다음 비교대상인 IGP 메트릭 값에 의해 1.1.13.1로 경로가 설정되있다.

 

참고 : BGP 경로 선택 우선순위 요약 (중요한 6단계만)

  1. Weight (Cisco 전용, 클수록 우선)
  2. Local Preference (AS 내부, 클수록 우선)
  3. Locally originated (내가 직접 만든 경로)
  4. AS Path Length (짧을수록 우선)
  5. Origin type (IGP < EGP < Incomplete)
  6. MED (Metric) (낮을수록 우선)

IGP metric 값 1.1.13.1 경로(좌) / 4.4.4.4 경로(우)

# R3 -> R2 lo 2.2.2.2에 대해서 IGP metric 값이 낮은 1.1.13.1이 선택된 이유이다.(위 사진)

하지만  R3 -> R2로 경로를 기존 R3 -> R1 -> R2 에서 R3 -> R4 -> R2로 바꾸고싶다.

 

route-map 설정 후 R3 테이블(좌) / R3 -> R2 경로(우)

 

R3(config)#ip prefix-list R2ONLY seq 5 permit 2.2.2.0/24
R3(config)#route-map locR2ONLY permit 10
R3(config-route-map)#match ip address prefix-list R2ONLY
R3(config-route-map)#set local-preference 200
R3(config-route-map)#exit
R3(config)#route-map locR2ONLY permit 20 
R3(config-route-map)#exit
R3(config)#router bgp 2
R3(config-router)#neighbor 4.4.4.4 route-map locR2ONLY in

 

# 2.2.2.0/24에 대한 route-map 설정 후 LocPrf가 200으로 바뀌고 BGP 경로 선택 우선순위에 따라,

R3 -> R2 lo0 2.2.2.2에 대한 경로가 R3 -> R4 -> R2로 바뀐 모습이다.


3) BGP MED 란?

✅정의

MED(Multi Exit Discriminator)
같은 외부 AS에서 들어온 경로 중 어떤 경로를 더 선호할지를 상대방에게 제안하는 값이다.

  • 값이 작을수록 우선
  • 기본값은 0 또는 infinity (값 없음)
  • 경로의 수신자(BGP 피어)가 이 값을 보고 판단
  • 경로 선택 시 AS_PATH, Local Preference보다 낮은 우선순위를 가짐

✅특징

항목 내용
역할 같은 AS에서 온 경로들끼리 비교하여 우선순위 선택
값 비교 방식 작을수록 우선 (Lower is Better)
적용 방향 수신자 측에서 적용되는 판단 기준
설정 위치 광고하는 라우터 쪽에서 설정 (route-map out)
기본값 Cisco에서는 MED가 설정되지 않으면 광고 안 함
전파 범위 BGP 경로 속성으로 포함되어 상대방에게 전파됨
적용 범위 제한 같은 AS 번호에서 온 경로끼리만 비교 가능

'네트워크' 카테고리의 다른 글

BGP #2(Next Hop,Split Horizon)  (0) 2025.04.10
BGP #1(iBGP,eBGP)  (0) 2025.04.07
OSPF #4(Virtual-link,Demand circuit)  (0) 2025.04.05
OSPF #3(Summarization,Authentication)  (0) 2025.04.02
OPSF #2(LSA,Stub Area)  (0) 2025.03.30