
BGP Route Filtering: Prefix-list, Route-map และ AS-path ACL
BGP Route Filtering เป็นทักษะสำคัญของ network engineer ที่ทำงานกับ BGP เพราะ BGP รับ routes จาก peers หลายตัว ถ้าไม่ filter จะรับ routes ที่ไม่ต้องการ ทำให้ routing table ใหญ่เกินไป หรืออาจ route traffic ผิดทาง การ filter routes ช่วยควบคุมว่าจะรับ (inbound) หรือส่ง (outbound) routes ใดบ้าง
BGP route filtering มี เครื่องมือหลายตัว ที่ใช้ร่วมกัน: prefix-list สำหรับ filter ตาม network/prefix length, AS-path ACL สำหรับ filter ตาม AS path, route-map สำหรับ combine conditions + set attributes และ community lists สำหรับ filter ตาม BGP community บทความนี้จะสอนวิธีใช้แต่ละเครื่องมือ
BGP Filtering Tools
| Tool | Filter ตาม | ใช้เมื่อไหร่ |
|---|---|---|
| Prefix-list | Network address + prefix length | Filter specific networks (เช่น permit 10.0.0.0/8) |
| AS-path ACL | AS path (regex) | Filter ตาม origin AS หรือ transit AS |
| Route-map | Multiple conditions + set actions | Complex filtering + attribute manipulation |
| Community List | BGP community values | Filter ตาม community tags |
| Distribute-list (ACL) | Network address (legacy) | ไม่แนะนำ (ใช้ prefix-list แทน) |
Prefix-list
Filter ตาม Network + Prefix Length
Syntax: ip prefix-list [name] seq [number] [permit/deny] [network/length] [ge/le modifier]
| ตัวอย่าง | ความหมาย |
|---|---|
| permit 10.0.0.0/8 | อนุญาตเฉพาะ 10.0.0.0/8 (exact match) |
| permit 10.0.0.0/8 le 24 | อนุญาต 10.0.0.0 ที่ prefix length 8-24 |
| permit 10.0.0.0/8 ge 16 le 24 | อนุญาต 10.0.0.0 ที่ prefix length 16-24 |
| permit 0.0.0.0/0 le 32 | อนุญาตทุก route (any prefix) |
| deny 0.0.0.0/0 ge 25 | ปฏิเสธ routes ที่ specific กว่า /24 |
ตัวอย่าง: รับเฉพาะ routes ที่ไม่เกิน /24
ip prefix-list FILTER-IN seq 5 deny 0.0.0.0/0 ge 25 → ปฏิเสธ /25 ขึ้นไป ip prefix-list FILTER-IN seq 10 permit 0.0.0.0/0 le 24 → อนุญาต /0 ถึง /24 router bgp 65001 → neighbor 10.1.1.1 prefix-list FILTER-IN in
AS-path ACL
Filter ตาม AS Path (Regex)
| Regex | ความหมาย | ตัวอย่าง |
|---|---|---|
| ^$ | Locally originated routes (empty AS path) | Routes ที่ AS นี้สร้างเอง |
| ^65001$ | Routes ที่มา directly จาก AS 65001 | 1 hop away |
| _65001_ | Routes ที่ผ่าน AS 65001 | AS 65001 อยู่ใน path |
| ^65001_ | Routes ที่เริ่มต้นจาก AS 65001 | Adjacent peer AS 65001 |
| _65001$ | Routes ที่ originated จาก AS 65001 | Origin AS = 65001 |
| .* | ทุก route | Match all |
ตัวอย่าง: รับเฉพาะ routes จาก AS 65002
ip as-path access-list 10 permit _65002$ → อนุญาต routes ที่ originated จาก AS 65002 router bgp 65001 → neighbor 10.1.1.1 filter-list 10 in
Route-map
Combine Conditions + Set Actions
Route-map ทรงพลังที่สุดเพราะรวม match conditions หลายตัว + set actions ได้:
| Match Conditions | Set Actions |
|---|---|
| match ip address prefix-list [name] | set local-preference [value] |
| match as-path [acl] | set weight [value] |
| match community [list] | set metric [value] (MED) |
| match ip next-hop [acl] | set as-path prepend [ASN…] |
| match metric [value] | set community [value] |
ตัวอย่าง: ตั้ง Local Preference ตาม Prefix
ip prefix-list PREFERRED seq 5 permit 192.168.0.0/16 le 24 route-map SET-LP permit 10 → match ip address prefix-list PREFERRED → set local-preference 200 route-map SET-LP permit 20 → (default: permit all with default LP) router bgp 65001 → neighbor 10.1.1.1 route-map SET-LP in
Filtering Direction
| Direction | ใช้เมื่อไหร่ | ตัวอย่าง |
|---|---|---|
| Inbound (in) | ควบคุม routes ที่รับจาก neighbor | ไม่รับ default route, ไม่รับ routes เล็กกว่า /24 |
| Outbound (out) | ควบคุม routes ที่ส่งให้ neighbor | ส่งเฉพาะ customer routes, ไม่ส่ง full table |
Common Filtering Scenarios
| Scenario | Tool | วิธี |
|---|---|---|
| ไม่รับ default route (0.0.0.0/0) | Prefix-list | deny 0.0.0.0/0 → permit all |
| ไม่รับ routes เล็กกว่า /24 | Prefix-list | deny 0.0.0.0/0 ge 25 → permit all |
| รับเฉพาะ routes จาก specific AS | AS-path ACL | permit _XXXXX$ |
| ไม่ส่ง private AS routes | AS-path ACL | deny _6450[0-9]_ → permit .* |
| Prefer path ผ่าน ISP-A | Route-map | match + set local-preference 200 |
| Prepend AS path outbound | Route-map | set as-path prepend 65001 65001 65001 |
| Tag routes with community | Route-map | set community 65001:100 |
Bogon Filtering
ป้องกัน Routes ที่ไม่ควรมีบน Internet
| Bogon Prefix | รายละเอียด |
|---|---|
| 0.0.0.0/8 | “This” network |
| 10.0.0.0/8 | RFC 1918 private |
| 127.0.0.0/8 | Loopback |
| 169.254.0.0/16 | Link-local |
| 172.16.0.0/12 | RFC 1918 private |
| 192.168.0.0/16 | RFC 1918 private |
| 224.0.0.0/4 | Multicast |
| 240.0.0.0/4 | Reserved |
Verification Commands
| Command | แสดงอะไร |
|---|---|
| show ip bgp | BGP table ทั้งหมด |
| show ip bgp neighbors [IP] received-routes | Routes ที่รับจาก neighbor (ก่อน filter) |
| show ip bgp neighbors [IP] routes | Routes ที่รับจาก neighbor (หลัง filter) |
| show ip bgp neighbors [IP] advertised-routes | Routes ที่ส่งให้ neighbor |
| show ip prefix-list [name] | Prefix-list entries + hit count |
| show route-map [name] | Route-map entries |
ทิ้งท้าย: Filter BGP = ปกป้อง Network
BGP Route Filtering จำเป็นสำหรับทุกองค์กรที่ใช้ BGP ใช้ prefix-list สำหรับ filter ตาม network ใช้ AS-path ACL สำหรับ filter ตาม AS ใช้ route-map สำหรับ complex policies Filter bogons ทั้ง inbound + outbound
อ่านเพิ่มเติมเกี่ยวกับ BGP Configuration และ Network Segmentation ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com