BGP Basics: พื้นฐาน Border Gateway Protocol สำหรับ Network Engineer

BGP Basics: พื้นฐาน Border Gateway Protocol สำหรับ Network Engineer

BGP (Border Gateway Protocol) เป็น routing protocol ที่ใช้เชื่อมต่อระหว่าง Autonomous Systems (AS) บน internet เป็น protocol ที่ทำให้ internet ทำงานได้ ทุก ISP, cloud provider, large enterprise ใช้ BGP BGP เป็น path-vector protocol ที่เลือก best path จาก AS attributes ไม่ใช่ metric แบบ OSPF หรือ EIGRP

สำหรับ network engineer ที่ทำงานกับ ISP, data center หรือ multi-homed enterprise การเข้าใจ BGP เป็นสิ่งจำเป็น บทความนี้จะอธิบายพื้นฐาน BGP, eBGP vs iBGP, path selection และ basic configuration

BGP คืออะไร

Autonomous System (AS)

AS คือกลุ่มของ networks ที่อยู่ภายใต้การบริหารจัดการเดียวกัน มี AS Number (ASN) เฉพาะ: Public ASN: 1-64511, 131072-4199999999 (ใช้บน internet) Private ASN: 64512-65534, 4200000000-4294967294 (ใช้ภายใน) ตัวอย่าง: ISP แต่ละราย, Google, Facebook, Amazon แต่ละรายมี ASN ของตัวเอง BGP ใช้เชื่อมต่อระหว่าง AS

eBGP vs iBGP

คุณสมบัติ eBGP (External BGP) iBGP (Internal BGP)
ใช้ระหว่าง AS ต่างกัน (เช่น ISP กับ ISP) ภายใน AS เดียวกัน
AD (Administrative Distance) 20 200
Next-hop เปลี่ยนเป็น peer IP ไม่เปลี่ยน (ต้อง next-hop-self)
TTL 1 (directly connected) 255 (ไม่ต้อง directly connected)
Full mesh ไม่จำเป็น จำเป็น (หรือใช้ Route Reflector)

BGP Path Selection

BGP Best Path Algorithm

BGP เลือก best path ตามลำดับ attributes ต่อไปนี้ (จากสำคัญมากไปน้อย):

ลำดับ Attribute ค่าที่ต้องการ หมายเหตุ
1 Weight (Cisco) สูงสุด Local to router, default 0 (eBGP 32768)
2 Local Preference สูงสุด ใช้ภายใน AS, default 100
3 Locally Originated Prefer locally originated network command หรือ redistribute
4 AS Path Length สั้นที่สุด จำนวน AS ที่ผ่าน
5 Origin IGP > EGP > Incomplete i > e > ?
6 MED (Multi-Exit Discriminator) ต่ำสุด ใช้ระหว่าง AS เพื่อบอก preferred entry point
7 eBGP over iBGP Prefer eBGP eBGP AD 20 < iBGP AD 200
8 Lowest IGP metric to next-hop ต่ำสุด Nearest exit point

BGP Message Types

Message หน้าที่
OPEN เริ่ม BGP session (แลกเปลี่ยน AS number, hold time, router ID)
UPDATE ส่ง route advertisements (new routes, withdrawn routes)
KEEPALIVE รักษา session alive (ส่งทุก 60 วินาที default)
NOTIFICATION แจ้ง error และ close session

BGP States

State ความหมาย ถ้าค้างที่ state นี้
Idle ยังไม่เริ่ม BGP process ตรวจ neighbor config
Connect TCP connection กำลังเปิด ตรวจ connectivity (ping)
Active TCP connection ล้มเหลว กำลัง retry ตรวจ ACL, firewall (port 179)
OpenSent OPEN message ส่งแล้ว รอ OPEN กลับ ตรวจ AS number mismatch
OpenConfirm OPEN ได้รับ รอ KEEPALIVE ตรวจ hold time mismatch
Established BGP session up สมบูรณ์ ปกติ (เป้าหมาย)

Basic Configuration (Cisco)

eBGP Peering

Router A (AS 65001, IP 10.0.0.1): router bgp 65001 neighbor 10.0.0.2 remote-as 65002 network 192.168.1.0 mask 255.255.255.0 Router B (AS 65002, IP 10.0.0.2): router bgp 65002 neighbor 10.0.0.1 remote-as 65001 network 172.16.0.0 mask 255.255.0.0

iBGP Peering

iBGP ใช้ loopback interfaces (stability): router bgp 65001 neighbor 2.2.2.2 remote-as 65001 neighbor 2.2.2.2 update-source Loopback0 neighbor 2.2.2.2 next-hop-self iBGP ต้อง full mesh (ทุก router peer กับทุก router) หรือใช้ Route Reflector

Route Reflector

แก้ปัญหา iBGP Full Mesh

iBGP full mesh: n routers ต้องมี n(n-1)/2 peerings (10 routers = 45 peerings) Route Reflector (RR) ลดเหลือ: clients peer กับ RR เท่านั้น RR “reflect” routes ให้ clients RR ไม่เปลี่ยน attributes (ยกเว้นเพิ่ม cluster-id) สำหรับ large AS ใช้ hierarchical RR

BGP Security

Threat Prevention
BGP Hijacking (route hijack) RPKI (Resource Public Key Infrastructure)
Unauthorized peering MD5 authentication (neighbor password)
Route leaks Prefix filtering (prefix-lists, route-maps)
DDoS via BGP Maximum-prefix limits, TTL security

ทิ้งท้าย: BGP เป็น Protocol ที่ทำให้ Internet ทำงานได้

BGP เป็น routing protocol ที่ซับซ้อนที่สุดแต่สำคัญที่สุด เข้าใจ AS, eBGP/iBGP, path selection เป็นพื้นฐาน ฝึก lab configuration ก่อน deploy production ระวัง BGP misconfiguration เพราะอาจกระทบ internet ทั้งระบบ

อ่านเพิ่มเติมเกี่ยวกับ MPLS VPN และ SD-WAN vs MPLS ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com

จัดส่งรวดเร็วส่งด่วนทั่วประเทศ
รับประกันสินค้าเคลมง่าย มีใบรับประกัน
ผ่อนชำระได้บัตรเครดิต 0% สูงสุด 10 เดือน
สะสมแต้ม รับส่วนลดส่วนลดและคะแนนสะสม

© 2026 SiamLancard — จำหน่ายการ์ดแลน อุปกรณ์ Server และเครื่องพิมพ์ใบเสร็จ

SiamLancard
Logo
Free Forex EA Download — XM Signal · EA Forex ฟรี
iCafeForex.com - สอนเทรด Forex | SiamCafe.net
Shopping cart