
BGP Routing Protocol: เข้าใจ BGP สำหรับ Network Engineer
BGP (Border Gateway Protocol) เป็น routing protocol ที่สำคัญที่สุดบน internet เพราะเป็นโปรโตคอลที่ใช้แลกเปลี่ยน routing information ระหว่าง Autonomous Systems (AS) ทั้งหมดบนโลก ทุกครั้งที่คุณเปิดเว็บไซต์ ส่งอีเมล หรือ stream วิดีโอ BGP เป็นตัวกำหนดเส้นทางที่ packet จะเดินทางข้าม network หลายสิบ network กว่าจะถึงปลายทาง
สำหรับ Network Engineer ในองค์กรขนาดกลางถึงใหญ่ ความเข้าใจ BGP เป็นทักษะที่จำเป็น เพราะต้องใช้ BGP ในการเชื่อมต่อกับ ISP (eBGP), ในการ route traffic ระหว่าง data centers (iBGP) และใน SD-WAN หรือ cloud connectivity บทความนี้จะอธิบาย BGP ตั้งแต่พื้นฐานไปจนถึงการ configure จริง
BGP คืออะไร ทำงานอย่างไร
BGP เป็น path-vector routing protocol ที่ทำงานบน TCP port 179 ต่างจาก OSPF หรือ EIGRP ที่เป็น interior gateway protocol (IGP) BGP เป็น exterior gateway protocol (EGP) ออกแบบมาสำหรับการ route ระหว่าง organizations
Autonomous System (AS)
AS คือกลุ่มของ network ที่อยู่ภายใต้การบริหารจัดการเดียวกัน แต่ละ AS มี AS Number (ASN) เป็นตัวระบุ เช่น Google คือ AS15169, Cloudflare คือ AS13335 ในไทย TRUE คือ AS7470, AIS คือ AS131445 BGP ทำหน้าที่แลกเปลี่ยน routing information ระหว่าง AS เหล่านี้ เพื่อให้ทุก AS รู้ว่าจะส่ง packet ไปหา network ไหนผ่านทางไหน
eBGP กับ iBGP
eBGP (External BGP) ใช้ระหว่าง AS ที่ต่างกัน เช่น ระหว่างองค์กรกับ ISP หรือระหว่าง ISP กับ ISP eBGP peers มักเป็น directly connected neighbors iBGP (Internal BGP) ใช้ภายใน AS เดียวกัน เช่น ระหว่าง core routers ในองค์กร iBGP มีกฎพิเศษคือ routes ที่เรียนรู้จาก iBGP peer จะไม่ถูก advertise ต่อให้ iBGP peer อื่น (iBGP split horizon) ต้องใช้ full mesh peering หรือ route reflector เพื่อแก้ปัญหานี้
BGP Path Selection: เลือกเส้นทางอย่างไร
เมื่อ BGP ได้รับ route ไปยัง destination เดียวกันจากหลาย path จะใช้ BGP best path selection algorithm ในการเลือก
BGP Attributes ที่สำคัญ
BGP ใช้ attributes หลายตัวในการตัดสินใจ เรียงตามลำดับความสำคัญ Weight (Cisco-specific, สูงสุดชนะ) Local Preference (สูงสุดชนะ, ใช้ภายใน AS) AS Path Length (สั้นที่สุดชนะ) Origin (IGP ดีกว่า EGP ดีกว่า Incomplete) MED (Multi-Exit Discriminator, ต่ำสุดชนะ, ใช้ระหว่าง AS) eBGP over iBGP IGP Metric (nearest next-hop) การเข้าใจลำดับนี้เป็นหัวใจของ BGP traffic engineering
Traffic Engineering ด้วย BGP
สมมติองค์กรมี ISP 2 ราย ต้องการให้ outbound traffic ไป ISP-A เป็นหลัก ใช้ Local Preference ตั้งค่าให้ routes จาก ISP-A มี local-pref สูงกว่า ISP-B สำหรับ inbound traffic ที่ซับซ้อนกว่า ใช้ AS Path Prepending เพิ่ม AS number ของตัวเองซ้ำหลายครั้งใน path ที่ไม่ต้องการ ทำให้ path ยาวขึ้นและ remote AS จะเลือก path อื่นที่สั้นกว่า
ตารางสรุป BGP Attributes
| ลำดับ | Attribute | ค่าที่ชนะ | ขอบเขต | ใช้ทำอะไร |
|---|---|---|---|---|
| 1 | Weight | สูงสุด | Local router only | เลือก preferred path บน router ตัวนี้ |
| 2 | Local Preference | สูงสุด | ภายใน AS | เลือก preferred exit point จาก AS |
| 3 | Locally Originated | Network/Redistribute | Local | ให้ priority กับ routes ที่ originate เอง |
| 4 | AS Path Length | สั้นที่สุด | ทั่วโลก | เลือก path ที่ผ่าน AS น้อยที่สุด |
| 5 | Origin | IGP > EGP > ? | ทั่วโลก | ให้ priority ตามวิธี originate |
| 6 | MED | ต่ำสุด | ระหว่าง AS | แนะนำ entry point ให้ neighboring AS |
BGP Security: ปกป้อง Routing Infrastructure
BGP ไม่ได้ออกแบบมาให้ secure ตั้งแต่แรก ทำให้เกิดปัญหา route hijacking และ route leaks ที่กระทบ internet ทั่วโลกเป็นระยะ
BGP Hijacking
BGP Hijacking เกิดเมื่อ AS ประกาศ prefix ที่ไม่ใช่ของตัวเอง ทำให้ traffic ที่ควรไปหา destination จริงถูก redirect ไปหา attacker แทน เหตุการณ์ที่มีชื่อเสียง เช่น Pakistan Telecom hijack YouTube prefix ในปี 2008 ทำให้ YouTube ล่มทั่วโลก หรือ BGP hijack ที่ redirect cryptocurrency traffic ไปหา attacker ในปี 2018
RPKI: Resource Public Key Infrastructure
RPKI เป็นมาตรฐานที่ช่วยป้องกัน BGP hijacking โดยใช้ digital certificates (ROA – Route Origin Authorization) ยืนยันว่า AS ไหนมีสิทธิ์ประกาศ prefix ไหน router ที่ enable RPKI Route Origin Validation จะปฏิเสธ routes ที่ AS ไม่มีสิทธิ์ประกาศ องค์กรควร sign ROA สำหรับ IP prefixes ของตัวเอง และ enable RPKI validation บน border routers
BGP Session Security
ใช้ MD5 authentication หรือ TCP-AO สำหรับ BGP sessions ป้องกัน session hijacking กำหนด maximum prefix limit เพื่อป้องกัน route leak ที่อาจทำให้ router crash จาก memory overflow ใช้ prefix filters อนุญาตเฉพาะ prefixes ที่คาดหวังจาก neighbor
Route Reflector: แก้ปัญหา iBGP Full Mesh
ใน iBGP ทุก router ต้อง peer กับทุก router อื่น (full mesh) ถ้ามี 10 routers ต้องมี 45 sessions เมื่อ network โตขึ้น full mesh ไม่ scalable Route Reflector (RR) แก้ปัญหานี้
วิธีทำงานของ Route Reflector
Route Reflector เป็น iBGP router ที่ได้รับอนุญาตให้ส่ง routes ที่เรียนจาก iBGP peer ต่อให้ iBGP peer อื่นได้ (ปกติ iBGP ห้ามทำ) routers อื่นแค่ peer กับ RR ตัวเดียว (หรือ 2 ตัวเพื่อ redundancy) ไม่ต้อง full mesh จาก 45 sessions เหลือแค่ 18 sessions (ถ้ามี RR 2 ตัว) ประหยัดทรัพยากรและง่ายต่อการจัดการ
BGP Communities: Tag Routes เพื่อ Policy
BGP Communities เป็น tag ที่แนบไปกับ route เพื่อระบุ policy ที่ต้องการ ทำให้สามารถกำหนด routing policy ได้ยืดหยุ่นมากขึ้น
Standard Communities
Standard community เป็นค่า 32-bit แสดงในรูป ASN:value เช่น 7470:100 อาจหมายถึง “routes จากลูกค้า” 7470:200 หมายถึง “routes จาก peering” ISP ใช้ communities ในการกำหนด policy เช่น ลูกค้าส่ง community 7470:666 มากับ route เพื่อขอให้ ISP blackhole route นั้น (DDoS mitigation)
Extended และ Large Communities
Extended Communities ใช้ใน VPN และ EVPN สำหรับ route target และ site-of-origin Large Communities (RFC 8092) รองรับ 4-byte ASN ที่ standard communities ไม่รองรับ ใช้รูปแบบ ASN:function:parameter เช่น 131072:1:100 ให้ความยืดหยุ่นมากขึ้น
ทิ้งท้าย: BGP เป็นทักษะที่ขาดไม่ได้
BGP เป็น routing protocol ที่ซับซ้อนแต่ทรงพลัง การเข้าใจ BGP ตั้งแต่ path selection algorithm, eBGP/iBGP, route reflector ไปจนถึง security จะทำให้คุณสามารถออกแบบและ troubleshoot network ระดับ enterprise ได้อย่างมั่นใจ เริ่มจากการ lab ด้วย GNS3 หรือ EVE-NG สร้าง topology ง่ายๆ แล้วค่อยๆ เพิ่มความซับซ้อน
อ่านเพิ่มเติมเกี่ยวกับ SD-WAN และ Network Troubleshooting ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com