Home » BGP Route Filtering: Prefix-list, Route-map และ Community
BGP Route Filtering: Prefix-list, Route-map และ Community
BGP Route Filtering: Prefix-list, Route-map และ Community
BGP Route Filtering เป็นทักษะสำคัญสำหรับ network engineer ที่ดูแล BGP peering กับ ISPs หรือระหว่าง autonomous systems เพราะ BGP รับ routes จาก peers ทั้งหมดโดย default การ filter routes ที่ไม่ต้องการออก และควบคุม routes ที่ advertise ออกไป เป็นสิ่งจำเป็นเพื่อความปลอดภัยและ routing efficiency
หากไม่ทำ route filtering อย่างเหมาะสม อาจเกิดปัญหาร้ายแรง เช่น route leaks ที่ทำให้ traffic ไหลผิดทาง, BGP hijacking ที่ผู้ไม่หวังดี advertise prefixes ของคนอื่น หรือรับ default route จาก peer โดยไม่ตั้งใจ บทความนี้จะสอนเครื่องมือหลัก 3 ตัวสำหรับ BGP route filtering
เครื่องมือ Route Filtering
| เครื่องมือ |
ใช้ทำอะไร |
ความยืดหยุ่น |
| Prefix-list |
Filter ตาม prefix (network/mask) |
ปานกลาง (match prefix เท่านั้น) |
| Route-map |
Filter + modify route attributes |
สูงสุด (match + set หลาย attributes) |
| Community |
Tag routes แล้ว filter ตาม tag |
สูง (scalable, policy-based) |
| AS-path Access-list |
Filter ตาม AS path (regex) |
ปานกลาง (match AS path pattern) |
| Distribute-list |
Filter ด้วย ACL (legacy) |
ต่ำ (ไม่แนะนำ ใช้ prefix-list แทน) |
Prefix-list
Filter ตาม Network Prefix
| Feature |
รายละเอียด |
| Match criteria |
Network address + subnet mask (exact or range) |
| Syntax |
ip prefix-list NAME seq N permit/deny PREFIX/LEN |
| ge (greater-equal) |
Match prefixes ที่ mask ≥ ค่าที่กำหนด |
| le (less-equal) |
Match prefixes ที่ mask ≤ ค่าที่กำหนด |
| Exact match |
ไม่ใส่ ge/le = match prefix length ตรงๆ |
ตัวอย่าง: ip prefix-list FILTER seq 10 permit 10.0.0.0/8 le 24 = permit 10.0.0.0/8 และ subnets ย่อยจนถึง /24 (ไม่ permit /25 หรือเล็กกว่า) ip prefix-list FILTER seq 20 deny 0.0.0.0/0 = deny default route ip prefix-list FILTER seq 30 permit 0.0.0.0/0 le 32 = permit ทุก prefix
Prefix-list Examples
| Prefix-list Entry |
Match อะไร |
| permit 192.168.1.0/24 |
เฉพาะ 192.168.1.0/24 (exact match) |
| permit 10.0.0.0/8 le 24 |
10.0.0.0/8 ถึง 10.x.x.x/24 (ไม่เกิน /24) |
| permit 10.0.0.0/8 ge 24 |
10.x.x.x/24 ถึง 10.x.x.x/32 (ตั้งแต่ /24 ขึ้นไป) |
| permit 10.0.0.0/8 ge 16 le 24 |
10.x.x.x/16 ถึง 10.x.x.x/24 |
| deny 0.0.0.0/0 |
Default route (0.0.0.0/0) เท่านั้น |
| permit 0.0.0.0/0 le 32 |
ทุก prefix ทั้งหมด |
Route-map
Filter + Modify Route Attributes
| Feature |
รายละเอียด |
| Match |
เงื่อนไข: prefix-list, AS-path, community, next-hop, metric |
| Set |
แก้ไข: local-pref, MED, AS-path prepend, community, next-hop, weight |
| Permit/Deny |
permit = ผ่าน (apply set), deny = block |
| Sequence |
ทำงานตาม sequence number (first match wins) |
| Implicit deny |
ท้ายสุดมี implicit deny all (เหมือน ACL) |
Route-map Attributes ที่ Set ได้
| Attribute |
Set Command |
ผลกระทบ |
| Local Preference |
set local-preference 200 |
ใช้เลือก outbound path (สูง = preferred) |
| MED (Multi-Exit Discriminator) |
set metric 100 |
บอก neighbor ว่าเข้ามาทาง path ไหน (ต่ำ = preferred) |
| AS-path Prepend |
set as-path prepend 65001 65001 |
ทำให้ path ยาวขึ้น = less preferred |
| Weight |
set weight 500 |
Cisco-specific, local to router (สูง = preferred) |
| Community |
set community 65001:100 |
Tag route ด้วย community value |
| Next-hop |
set ip next-hop 10.0.0.1 |
เปลี่ยน next-hop address |
BGP Community
Tag Routes สำหรับ Policy-based Filtering
| Community Format |
ตัวอย่าง |
ความหมาย |
| Standard (AA:NN) |
65001:100 |
AS 65001, value 100 |
| Well-known: NO_EXPORT |
no-export |
ห้าม advertise ไป eBGP peers |
| Well-known: NO_ADVERTISE |
no-advertise |
ห้าม advertise ไปใครเลย |
| Well-known: LOCAL_AS |
local-as |
ห้าม advertise ออกนอก local AS (confederation) |
| Extended Community |
RT:65001:100 |
ใช้ใน MPLS VPN (Route Target) |
| Large Community |
65001:0:100 |
4-byte ASN support (RFC 8092) |
Community Use Cases
| Community Value |
ความหมาย (ตัวอย่าง) |
| 65001:100 |
Routes จาก customer |
| 65001:200 |
Routes จาก peer |
| 65001:300 |
Routes จาก transit provider |
| 65001:666 |
Blackhole route (RTBH) |
| 65001:1000 |
Prepend 1× เมื่อ advertise ออก |
| 65001:2000 |
Prepend 2× เมื่อ advertise ออก |
| 65001:9999 |
Do not advertise to any peer |
Best Practices
| Practice |
รายละเอียด |
| Filter inbound เสมอ |
อย่ารับ routes ทั้งหมดจาก peer โดยไม่ filter |
| Deny default route inbound |
ป้องกันรับ 0.0.0.0/0 โดยไม่ตั้งใจ |
| Filter bogons |
Block RFC1918, RFC5737, RFC6598 prefixes จาก eBGP |
| Max-prefix limit |
กำหนด maximum prefixes per peer |
| ใช้ prefix-list แทน ACL |
Prefix-list เร็วกว่าและยืดหยุ่นกว่า distribute-list |
| ใช้ community สำหรับ policy |
Tag routes ที่ origin → apply policy downstream |
| Document ทุก filter |
เขียน comment อธิบายว่า filter ทำอะไร ทำไม |
Bogon Prefix Filter
| Bogon Prefix |
RFC |
ทำไมต้อง Filter |
| 0.0.0.0/8 |
RFC 1122 |
This network |
| 10.0.0.0/8 |
RFC 1918 |
Private (Class A) |
| 100.64.0.0/10 |
RFC 6598 |
Shared address space (CGNAT) |
| 127.0.0.0/8 |
RFC 1122 |
Loopback |
| 169.254.0.0/16 |
RFC 3927 |
Link-local |
| 172.16.0.0/12 |
RFC 1918 |
Private (Class B) |
| 192.168.0.0/16 |
RFC 1918 |
Private (Class C) |
| 224.0.0.0/4 |
RFC 5771 |
Multicast |
| 240.0.0.0/4 |
RFC 1112 |
Reserved |
ทิ้งท้าย: Route Filtering = BGP Security
BGP Route Filtering เป็น must-have สำหรับทุก BGP deployment Prefix-list: filter ตาม prefix (basic) Route-map: filter + modify attributes (advanced) Community: tag routes สำหรับ scalable policy Filter bogons + default route + set max-prefix limit เสมอ
อ่านเพิ่มเติมเกี่ยวกับ MPLS Enterprise WAN และ Network Segmentation ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com