본문 바로가기
Network/BGP

[BGP] BGP 연동 실습#2 - 특정 네트워크 광고 허용/거부 정책 적용 (Filtering)

by chan10 2025. 1. 17.

 

BGP 재분배 설정 (route-map, redistribute)

BGP를 통해 네트워크를 광고하기 위해 BGP 설정에서 광고할 대역을 선언했습니다.

그러나 이런 방식으로 하게되면 광고하는 대역에 비례해서 BGP 설정이 길어지게 됩니다.

R2#show run bgp
!
router bgp 200
 bgp router-id 2.2.2.2
 network 120.2.0.0/24
 network 120.2.1.0/24
 network 120.2.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.12.1 remote-as 100
 neighbor 10.10.12.1 timers 2 6
 neighbor 10.10.12.1 soft-reconfiguration inbound
 neighbor 10.10.12.1 no shutdown

 

route-map, redistribute을 사용하면 이러한 단점을 해소할 수 있습니다.

기존과 동일하게 광고하는 대역을 컨트롤 할 수 있으나 BGP 설정은 길어지지 않고 유지할 수 있습니다.

광고할 대역을 prefix-list로 생성route-map에 매치시켜 redistribute에 적용합니다.

광고할 대역을 prefix-list로 분리해서 관리하기 때문에 수정 시 BGP설정은 편집할 필요가 없어집니다.

[R2]:config 적용
!
ip prefix-list BGP
 seq 10 permit 120.2.0.0/24
 seq 20 permit 120.2.1.0/24
 seq 30 permit 120.2.2.0/24
 seq 100 deny any
!
route-map rmaps permit 10
 match ip address BGP
!
router bgp 200
 bgp router-id 2.2.2.2
 redistribute connected route-map rmaps

 

BGP 전체 설정 확인 시 광고할 네트워크 별로 정의된 명령어 대신 redistribute 명령어 한줄로 대체되었습니다.

R2#show run bgp
!
router bgp 200
 bgp router-id 2.2.2.2
 timers bgp 2 6
 redistribute connected route-map rmaps
 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.12.1 remote-as 100
 neighbor 10.10.12.1 timers 2 6
 neighbor 10.10.12.1 soft-reconfiguration inbound
 neighbor 10.10.12.1 no shutdown

 

R2에서 재분배(redistribute) 설정 후에도 R1에서는 동일하게 BGP 네트워크 경로 광고가 수신되고 있는 것을 볼 수 있습니다.

R1#show ip bgp
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
*>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
*>  120.2.0.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.1.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.2.0/24       10.10.12.2               0                 0 200 ?
*>  130.3.0.0/24       10.10.12.2                                 0 200 i
*>  130.3.1.0/24       10.10.12.2                                 0 200 i
*>  130.3.2.0/24       10.10.12.2                                 0 200 i
*>  140.4.0.0/24       10.10.12.2                                 0 200 i
*>  140.4.1.0/24       10.10.12.2                                 0 200 i
*>  140.4.2.0/24       10.10.12.2                                 0 200 i

 

BGP Peer 별 특정 네트워크 광고 설정 (송신 - Outbound Filtering)

앞서 설정한 BGP network, redistribute 설정은 연결된 모든 neighbor에게 광고하는 설정입니다.

Outbound Filtering은 BGP 테이블에 보유한 모든 대역을 광고하는 것이 아닌 neighbor 개별적으로 특정 대역만 필터링해서 광고할 수 있도록 합니다.

R2에서 BGP로 광고 받는 대역중 특정 대역만 필터링해서 R1에 광고하려고 합니다.

[R2 BGP 테이블]

R2#show ip bgp
...
    Network            Next Hop            Metric     LocPrf Weight Path
*>  110.1.0.0/24       10.10.12.1               0                 0 100 i
*>  110.1.1.0/24       10.10.12.1               0                 0 100 i
*>  110.1.2.0/24       10.10.12.1               0                 0 100 i
*>r 120.2.0.0/24       0.0.0.0                  0             32768 ?
*>r 120.2.1.0/24       0.0.0.0                  0             32768 ?
*>r 120.2.2.0/24       0.0.0.0                  0             32768 ?
*>I 130.3.0.0/24       3.3.3.3                  0        100      0 i
*>I 130.3.1.0/24       3.3.3.3                  0        100      0 i
*>I 130.3.2.0/24       3.3.3.3                  0        100      0 i
*>I 140.4.0.0/24       4.4.4.4                  0        100      0 i
*>I 140.4.1.0/24       4.4.4.4                  0        100      0 i
*>I 140.4.2.0/24       4.4.4.4                  0        100      0 i

 

광고 할 네트워크 대역을 prefix-list로 작성합니다. prefix-list는 permit으로 지정한 네트워크 대역만 광고하고 나머지는 deny 하게 됩니다.

BGP의 neighbor 설정에서 distribute-list [prefix-list]를 적용하고 방향을 지정합니다. 여기서 방향을 out으로 지정하면 적용한 neighbor에게는 prefix-list로 작성한 대역에 대해서만 광고를 수행하게 됩니다.

[R2]:config 적용
!
ip prefix-list BGP-Peer-Out
 seq 10 permit 120.2.0.0/24
 seq 20 permit 120.2.1.0/24
 seq 30 permit 120.2.2.0/24
 seq 40 permit 130.3.0.0/24
 seq 50 permit 140.4.0.0/24
 seq 100 deny any
!
router bgp 200
neighbor 10.10.12.1 distribute-list BGP-Peer out
======================
R2#show run bgp
!
router bgp 200
 bgp router-id 2.2.2.2
 timers bgp 2 6
 redistribute connected route-map rmaps
 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.12.1 remote-as 100
 neighbor 10.10.12.1 distribute-list BGP-Peer-Out out
 neighbor 10.10.12.1 timers 2 6
 neighbor 10.10.12.1 soft-reconfiguration inbound
 neighbor 10.10.12.1 no shutdown

 

show ip bgp neighbors x.x.x.x advertised-routes 명령어를 입력하면 해당 neighbor에 전달하는 네트워크 대역 정보를 확인할 수 있습니다.

Filter 설정 후 R2에서 R1에게 광고하는 네트워크 수는 prefix-list에 작성한 5개로 줄어들었습니다.

R2#show ip bgp neighbors 10.10.12.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       10.10.12.2               0          0      0 200 ?
*> 120.2.1.0/24       10.10.12.2               0          0      0 200 ?
*> 120.2.2.0/24       10.10.12.2               0          0      0 200 ?
*> 130.3.0.0/24       10.10.12.2               0          0      0 200 i
*> 140.4.0.0/24       10.10.12.2               0          0      0 200 i
Total number of prefixes: 5

 

R1에서도 마찬가지로 R2에서 5개 대역만 광고하기에 5개 대역에 대한 라우팅만 등록 됨을 확인할 수 있습니다.

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
*>  120.2.0.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.1.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.2.0/24       10.10.12.2               0                 0 200 ?
*>  130.3.0.0/24       10.10.12.2                                 0 200 i
*>  140.4.0.0/24       10.10.12.2                                 0 200 i

=====================

R1#show ip route
...
       Destination        Gateway               Dist/Metric Last Change
       -----------        -------               ----------- -----------
  C    1.1.1.1/32         Direct, Lo 1                  0/0        7w4d
  C    10.10.12.0/24      Direct, Vl 12                 0/0        7w2d
  C    10.10.14.0/24      Direct, Gi 1/47               0/0       1d23h
  C    110.1.0.0/24       Direct, Lo 2                  0/0        7w4d
  C    110.1.1.0/24       Direct, Lo 3                  0/0        7w4d
  C    110.1.2.0/24       Direct, Lo 4                  0/0        7w4d
  B EX 120.2.0.0/24       via 10.10.12.2               20/0    00:09:12
  B EX 120.2.1.0/24       via 10.10.12.2               20/0    00:09:12
  B EX 120.2.2.0/24       via 10.10.12.2               20/0    00:09:12
  B EX 130.3.0.0/24       via 10.10.12.2               20/0    22:35:42
  B EX 140.4.0.0/24       via 10.10.12.2               20/0    00:19:42

 

BGP Peer 별 특정 네트워크 광고 설정 (수신 - Inbound Filtering)

Inbound Filtering은 neighbor로 부터 전달받은 BGP 경로 정보를 Filtering해서 저장할 수 있도록 합니다.

R2에서 이전에 적용한 설정을 제거하여 R1에게 모든 네트워크 대역을 광고하도록 합니다.

(no neighbor 10.10.12.1 distribute-list BGP-Peer out)

R2에서 설정을 제거 함에 따라 R1에서는 R2~R4 대역 모두 수신하고 있습니다.

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
*>  120.2.0.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.1.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.2.0/24       10.10.12.2               0                 0 200 ?
*>  130.3.0.0/24       10.10.12.2                                 0 200 i
*>  130.3.1.0/24       10.10.12.2                                 0 200 i
*>  130.3.2.0/24       10.10.12.2                                 0 200 i
*>  140.4.0.0/24       10.10.12.2                                 0 200 i
*>  140.4.1.0/24       10.10.12.2                                 0 200 i
*>  140.4.2.0/24       10.10.12.2                                 0 200 i

=================

R1#show ip route
...
       Destination        Gateway               Dist/Metric Last Change
       -----------        -------               ----------- -----------
  C    1.1.1.1/32         Direct, Lo 1                  0/0        7w4d
  C    10.10.12.0/24      Direct, Vl 12                 0/0        7w2d
  C    10.10.14.0/24      Direct, Gi 1/47               0/0       1d23h
  C    110.1.0.0/24       Direct, Lo 2                  0/0        7w4d
  C    110.1.1.0/24       Direct, Lo 3                  0/0        7w4d
  C    110.1.2.0/24       Direct, Lo 4                  0/0        7w4d
  B EX 120.2.0.0/24       via 10.10.12.2               20/0    00:15:32
  B EX 120.2.1.0/24       via 10.10.12.2               20/0    00:15:32
  B EX 120.2.2.0/24       via 10.10.12.2               20/0    00:15:32
  B EX 130.3.0.0/24       via 10.10.12.2               20/0    22:42:02
  B EX 130.3.1.0/24       via 10.10.12.2               20/0    00:01:17
  B EX 130.3.2.0/24       via 10.10.12.2               20/0    00:01:17
  B EX 140.4.0.0/24       via 10.10.12.2               20/0    00:26:01
  B EX 140.4.1.0/24       via 10.10.12.2               20/0    00:01:17
  B EX 140.4.2.0/24       via 10.10.12.2               20/0    00:01:17

 

이번에는 수신하는 BGP 경로를 제어할 것이기에 R1에서 설정을 합니다.

마찬가지로 수신할 네트워크 대역을 prefix-list로 작성하고 BGP neighbor distribute-list [prefix-list]을 적용하는데 이 때 방향은 in으로 적용함으로써 수신 경로에 대한 필터를 수행합니다.

[R1]:config 적용
!
ip prefix-list BGP-Peer-In
 seq 10 permit 120.2.0.0/24
 seq 20 permit 120.2.1.0/24
 seq 30 permit 120.2.2.0/24
 seq 40 permit 130.3.0.0/24
 seq 50 permit 140.4.0.0/24
 seq 100 deny any
!
router bgp 100
neighbor 10.10.12.2 distribute-list BGP-Peer-In in
======================
R1#show run bgp
!
router bgp 100
 bgp router-id 1.1.1.1
 network 110.1.0.0/24
 network 110.1.1.0/24
 network 110.1.2.0/24
 timers bgp 2 6
 bgp bestpath as-path multipath-relax
 neighbor 10.10.12.2 remote-as 200
 neighbor 10.10.12.2 distribute-list BGP-Peer-In in
 neighbor 10.10.12.2 timers 2 6
 neighbor 10.10.12.2 soft-reconfiguration inbound
 neighbor 10.10.12.2 no shutdown

 

R2에서는 R2~R4의 대역인 9개 네트워크를 R1에게 광고하고 있습니다.

R2#show ip bgp neighbors 10.10.12.1 advertised-routes
...
    Network            Next Hop            Metric     LocPrf Weight Path
*> 120.2.0.0/24       10.10.12.2               0          0      0 200 ?
*> 120.2.1.0/24       10.10.12.2               0          0      0 200 ?
*> 120.2.2.0/24       10.10.12.2               0          0      0 200 ?
*> 130.3.0.0/24       10.10.12.2               0          0      0 200 i
*> 130.3.1.0/24       10.10.12.2               0          0      0 200 i
*> 130.3.2.0/24       10.10.12.2               0          0      0 200 i
*> 140.4.0.0/24       10.10.12.2               0          0      0 200 i
*> 140.4.1.0/24       10.10.12.2               0          0      0 200 i
*> 140.4.2.0/24       10.10.12.2               0          0      0 200 i
Total number of prefixes: 9

 

R1에서는 prefix-list로 필터한 대역에 대해서만 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
*>  120.2.0.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.1.0/24       10.10.12.2               0                 0 200 ?
*>  120.2.2.0/24       10.10.12.2               0                 0 200 ?
*>  130.3.0.0/24       10.10.12.2                                 0 200 i
*>  140.4.0.0/24       10.10.12.2                                 0 200 i

=================

R1#show ip route
...
       Destination        Gateway               Dist/Metric Last Change
       -----------        -------               ----------- -----------
  C    1.1.1.1/32         Direct, Lo 1                  0/0        7w4d
  C    10.10.12.0/24      Direct, Vl 12                 0/0        7w2d
  C    10.10.14.0/24      Direct, Gi 1/47               0/0       1d23h
  C    110.1.0.0/24       Direct, Lo 2                  0/0        7w4d
  C    110.1.1.0/24       Direct, Lo 3                  0/0        7w4d
  C    110.1.2.0/24       Direct, Lo 4                  0/0        7w4d
  B EX 120.2.0.0/24       via 10.10.12.2               20/0    00:19:58
  B EX 120.2.1.0/24       via 10.10.12.2               20/0    00:19:58
  B EX 120.2.2.0/24       via 10.10.12.2               20/0    00:19:58
  B EX 130.3.0.0/24       via 10.10.12.2               20/0    22:46:28
  B EX 140.4.0.0/24       via 10.10.12.2               20/0    00:30:27

 

[참고사이트]

https://blog.naver.com/printf7/220556946885

https://m.blog.naver.com/happy_jhyo/222108683004

https://creathink.tistory.com/entry/Route-map-경로-맵