DynagenでCCIEを目指す
20100531 BGP フィルタの設定
最終更新:
it_certification
-
view
目的
- BGPにおいて、ルートをフィルタする方法を確認します。
構成
- 設定概要
- LAN内はOSPFによってルーティングします。
- R1, ISP10の間でeBGP neighborを確立します。
- 構成図

- netファイル
model = 3620 [localhost] [[3620]] image = C:\Program Files\Dynamips\images\c3620-j1s3-mz.123-18.bin ram = 128 [[ROUTER R1]] f0/0 = R2 f0/0 f1/0 = ISP10 f1/0 [[ROUTER R2]] [[ROUTER ISP10]]
- 初期設定 R1
! version 12.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R1 ! boot-start-marker boot-end-marker ! ! no aaa new-model ip subnet-zero ! ! ! ip cef ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface Loopback0 ip address 1.1.1.1 255.255.255.255 ! interface FastEthernet0/0 ip address 192.168.1.1 255.255.255.0 duplex auto speed auto ! interface FastEthernet1/0 ip address 192.168.2.1 255.255.255.0 duplex auto speed auto ! router ospf 1 router-id 1.1.1.1 log-adjacency-changes network 192.168.1.1 0.0.0.0 area 0 ! ip http server ip classless ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
- 初期設定 R2
! version 12.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R2 ! boot-start-marker boot-end-marker ! ! no aaa new-model ip subnet-zero ! ! ! ip cef ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface Loopback0 ip address 172.16.0.1 255.255.240.0 secondary ip address 172.16.16.1 255.255.240.0 secondary ip address 172.16.32.1 255.255.252.0 secondary ip address 172.16.36.1 255.255.252.0 secondary ip address 2.2.2.2 255.255.255.255 ! interface FastEthernet0/0 ip address 192.168.1.2 255.255.255.0 duplex auto speed auto ! router ospf 1 router-id 2.2.2.2 log-adjacency-changes redistribute connected subnets network 192.168.1.2 0.0.0.0 area 0 ! ip http server ip classless ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
- 初期設定 ISP10
! version 12.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname ISP10 ! boot-start-marker boot-end-marker ! ! no aaa new-model ip subnet-zero ! ! ! ip cef ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface Loopback0 ip address 10.10.10.10 255.255.255.255 ! interface FastEthernet1/0 ip address 192.168.2.10 255.255.255.0 duplex auto speed auto ! ip http server ip classless ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
検証1 BGPの設定
- BGPの設定
R1, ISP10の間でBGP neighborを定義します。
R1(config)#route-map SET_ORIGIN permit 10 R1(config-route-map)#set origin igp R1(config-route-map)#exit R1(config)# R1(config)# R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.2.10 remote-as 2 R1(config-router)#redistribute ospf 1 route-map SET_ORIGIN ISP10(config)#router bgp 2 ISP10(config-router)#neighbor 192.168.2.1 remote-as 1 ISP10(config-router)#network 10.10.10.10 mask 255.255.255.255
- ルーティングテーブルの確認
R1, ISP10の間で経路が交換できている事を確認します。
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 1.0.0.0/32 is subnetted, 1 subnets C 1.1.1.1 is directly connected, Loopback0 2.0.0.0/32 is subnetted, 1 subnets O E2 2.2.2.2 [110/20] via 192.168.1.2, 00:22:14, FastEthernet0/0 172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks O E2 172.16.36.0/22 [110/20] via 192.168.1.2, 00:22:14, FastEthernet0/0 O E2 172.16.32.0/22 [110/20] via 192.168.1.2, 00:22:14, FastEthernet0/0 O E2 172.16.16.0/20 [110/20] via 192.168.1.2, 00:22:14, FastEthernet0/0 O E2 172.16.0.0/20 [110/20] via 192.168.1.2, 00:22:14, FastEthernet0/0 10.0.0.0/32 is subnetted, 1 subnets B 10.10.10.10 [20/0] via 192.168.2.10, 00:12:43 C 192.168.1.0/24 is directly connected, FastEthernet0/0 C 192.168.2.0/24 is directly connected, FastEthernet1/0 R1# ISP10#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 2.0.0.0/32 is subnetted, 1 subnets B 2.2.2.2 [20/20] via 192.168.2.1, 00:01:38 172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks B 172.16.36.0/22 [20/20] via 192.168.2.1, 00:01:38 B 172.16.32.0/22 [20/20] via 192.168.2.1, 00:01:38 B 172.16.16.0/20 [20/20] via 192.168.2.1, 00:01:38 B 172.16.0.0/20 [20/20] via 192.168.2.1, 00:01:38 10.0.0.0/32 is subnetted, 1 subnets C 10.10.10.10 is directly connected, Loopback0 B 192.168.1.0/24 [20/0] via 192.168.2.1, 00:01:38 C 192.168.2.0/24 is directly connected, FastEthernet1/0 ISP10#
検証2 distribute-list 標準ACL
- フィルタの設定
標準アクセスリストによるフィルタを作成し、そのフィルタをBGP neighborに対し設定します。
R1(config)#access-list 1 deny 172.16.0.0 R1(config)#access-list 1 deny 172.32.0.0 R1(config)#access-list 1 permit any R1(config)# R1(config)# R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.2.10 distribute-list 1 out
- ルートの再送信
以下のコマンドで、BGPで通知するルートを再送信します。なお、このコマンドを使用してもBGP sessionは切れません。
R1#clear ip bgp * out
- 通知するルートの確認
R1がISP10に通知するルートを確認します。show ip bgp neighbors <ip address> advertised-rotesコマンドで確認できます。
R1#show ip bgp neighbors 192.168.2.10 advertised-routes BGP table version is 8, local router ID is 1.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 *> 2.2.2.2/32 192.168.1.2 20 32768 i *> 172.16.0.0/20 192.168.1.2 20 32768 i *> 172.16.36.0/22 192.168.1.2 20 32768 i *> 192.168.1.0 0.0.0.0 0 32768 i R1#
- ルーティングテーブルの確認
ISP10のルーティングテーブルを確認します。172.16.0.0/20, 172.16.32.0/20がフィルタされ、ルーティングテーブルから消えた事が確認できます。
ISP10#show ip route bgp 2.0.0.0/32 is subnetted, 1 subnets B 2.2.2.2 [20/20] via 192.168.2.1, 00:00:39 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks B 172.16.36.0/22 [20/20] via 192.168.2.1, 00:00:39 B 172.16.0.0/20 [20/20] via 192.168.2.1, 00:00:39 B 192.168.1.0/24 [20/0] via 192.168.2.1, 00:00:39 ISP10#
検証3 distribute-list 拡張ACL
- フィルタの設定
拡張アクセスリストによるフィルタを作成し、そのフィルタをBGP neighborに対し設定します。
拡張アクセスリストを使う場合は設定が若干複雑です。送信元ip address, maskでフィルタ対象を定義し、宛先ip address, maskでサブネット長を定義します。以下の設定例では、送信元が172.16.0.0 0.0.255.255となっているので、上位16ビットが172.16.0.0に一致するものという意味です。また、宛先が255.255.0.0 0.0.255.0となっているので、サブネットマスク長さが16以上24以下という意味になります。
かなり分かりづらい設定なので、検証4のprefix-listを使った方が保守しやすいと思います。
拡張アクセスリストを使う場合は設定が若干複雑です。送信元ip address, maskでフィルタ対象を定義し、宛先ip address, maskでサブネット長を定義します。以下の設定例では、送信元が172.16.0.0 0.0.255.255となっているので、上位16ビットが172.16.0.0に一致するものという意味です。また、宛先が255.255.0.0 0.0.255.0となっているので、サブネットマスク長さが16以上24以下という意味になります。
かなり分かりづらい設定なので、検証4のprefix-listを使った方が保守しやすいと思います。
R1(config)#access-list 100 deny ip 172.16.0.0 0.0.255.255 255.255.0.0 0.0.255.0 R1(config)#access-list 100 permit ip any any R1(config)# R1(config)# R1(config)# R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.2.10 distribute-list 100 out
- ルートの再送信
以下のコマンドで、BGPで通知するルートを再送信します。
R1#clear ip bgp * out
- 通知するルートの確認
R1がISP10に通知するルートを確認します。
R1#show ip bgp neighbors 192.168.2.10 advertised-routes BGP table version is 8, local router ID is 1.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 *> 2.2.2.2/32 192.168.1.2 20 32768 i *> 192.168.1.0 0.0.0.0 0 32768 i R1#
検証4 prefix-list
- フィルタの設定
prefix-listによるフィルタを作成し、そのフィルタをBGP neighborに対し設定します。
R1(config)#ip prefix-list DENY_PRIVATE seq 10 deny 172.16.0.0/16 ge 20 le 22 R1(config)#ip prefix-list DENY_PRIVATE seq 20 permit 0.0.0.0/0 le 32 R1(config)# R1(config)# R1(config)# R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.2.10 prefix-list DENY_PRIVATE out
- ルートの再送信
以下のコマンドで、BGPで通知するルートを再送信します。
R1#clear ip bgp * out
- 通知するルートの確認
R1がISP10に通知するルートを確認します。
R1#show ip bgp neighbors 192.168.2.10 advertised-routes BGP table version is 8, local router ID is 1.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 *> 2.2.2.2/32 192.168.1.2 20 32768 i *> 192.168.1.0 0.0.0.0 0 32768 i R1#
検証5 filter-list
filter-listを使用すると、AS-PATHなどを正規表現に基づいてフィルタを作成する事ができます。
以下の例はAS-PATHが空であるものをフィルタするという意味です。(正規表現「^$」は空文字列に合致)
以下の例はAS-PATHが空であるものをフィルタするという意味です。(正規表現「^$」は空文字列に合致)
R1(config)#ip as-path access-list 1 deny ^$ R1(config)#ip as-path access-list 1 permit .* R1(config)# R1(config)# R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.2.10 filter-list 1 out
- ルートの再送信
以下のコマンドで、BGPで通知するルートを再送信します。
R1#clear ip bgp * out
- 通知するルートの確認
R1がISP10に通知するルートを確認します。全てのルートがフィルタされた事が確認できます。
R1#show ip bgp neighbors 192.168.2.10 advertised-routes <- 何も表示されない R1#
添付ファイル