OSPF — Open Shortest Path First เป็น Dynamic Routing Protocol แบบ Link-State ที่ใช้กันใน IP Network เพื่อให้ Router แลกเปลี่ยนข้อมูลเกี่ยวกับ Network Topology และคำนวณเส้นทาง ด้วย Shortest Path First Algorithm
การเข้าใจ OSPF ไม่ควรเริ่มจากการจำคำสั่ง Cisco เพียงอย่างเดียว แต่ควรเข้าใจว่า Router ค้นพบกันอย่างไร สร้าง Neighbor และ Adjacency อย่างไร แลกเปลี่ยน LSA อย่างไร สร้าง LSDB อย่างไร และสุดท้ายคำนวณ Route เข้าสู่ Routing Table ได้อย่างไร
บทความนี้จึงเรียงกระบวนการตั้งแต่ Router ID → Hello → Neighbor → Adjacency → LSA → LSDB → SPF → Cost → Routing Table → Area พร้อม Cisco Lab และ Troubleshooting
สารบัญ
- OSPF คืออะไร?
- Link-State คืออะไร?
- Router ID
- OSPF Hello Packet
- Neighbor คืออะไร?
- OSPF Neighbor States
- Adjacency คืออะไร?
- LSA คืออะไร?
- LSDB คืออะไร?
- SPF Algorithm
- OSPF Cost
- OSPF Area
- Area 0 คืออะไร?
- DR และ BDR
- OSPF Route ใน Routing Table
- Cisco OSPF Configuration
- OSPF Lab
- Verification
- Troubleshooting
- OSPF Security
- Command Cheat Sheet
- FAQ
ภาค 1: OSPF Fundamentals
OSPF คืออะไร?
OSPF ย่อมาจาก Open Shortest Path First เป็น Interior Gateway Protocol หรือ IGP ที่ทำงานแบบ Link-State
OSPF สำหรับ IPv4 คือ OSPFv2 ส่วน IPv6 ใช้ OSPFv3 โดยรายละเอียดและ Configuration มีความแตกต่างกัน
ภาพพื้นฐาน:
LAN A
|
|
R1
|
|
R2
|
|
R3
|
|
LAN B
Router ที่ใช้ OSPF สามารถแลกเปลี่ยนข้อมูล เกี่ยวกับ Links และ Networks เพื่อสร้างมุมมองของ Topology และคำนวณเส้นทาง
แนวคิดโดยย่อ:
Discover Neighbor
|
v
Exchange Information
|
v
Build LSDB
|
v
Run SPF
|
v
Calculate Paths
|
v
Install Routes
|
v
Routing Table
Link-State คืออะไร?
Link-State Routing Protocol มุ่งให้ Router มีข้อมูล เกี่ยวกับ Topology ภายใน Area ผ่าน Link-State Information
สมมติ:
R2
/ \
/ \
R1----R3
\ /
\ /
R4
Router ไม่ได้พิจารณาเพียงว่า Destination อยู่ห่างกี่ Router แบบแนวคิด Hop Count ของ RIP แต่ใช้ข้อมูล Link-State และ Cost เพื่อคำนวณ Path
กระบวนการโดยย่อ:
Links
|
v
LSA
|
v
LSDB
|
v
SPF Calculation
|
v
Shortest-Path Tree
|
v
Routes
ภาค 2: Router ID และ Neighbor Discovery
OSPF Router ID คืออะไร?
OSPF Router ต้องมี Router ID เพื่อระบุตัว Router ใน OSPF Domain
Router ID มีรูปแบบ 32-bit ที่แสดงคล้าย IPv4 Address เช่น:
1.1.1.1
2.2.2.2
3.3.3.3
แต่ Router ID ไม่จำเป็นต้องเป็น IP Address ที่ใช้ Forward User Traffic จริง
กำหนด Router ID บน Cisco
Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1
การกำหนด Router ID อย่างชัดเจนช่วยให้ Topology และ Troubleshooting อ่านได้ง่าย
OSPF Hello Packet คืออะไร?
OSPF ใช้ Hello Packet สำหรับ Neighbor Discovery และช่วยรักษาความสัมพันธ์ ระหว่าง OSPF Routers
R1 R2
| |
|------ OSPF Hello ----->|
| |
|<----- OSPF Hello ------|
| |
+------ Neighbor --------+
Hello Packet มี Parameters ที่เกี่ยวข้องกับการสร้าง Neighbor/Adjacency หลายรายการ
ตัวอย่างสิ่งที่ควรตรวจเมื่อ Neighbor ไม่ขึ้น:
- Area
- Hello/Dead Timers
- Authentication เมื่อใช้งาน
- Network Type
- IP Subnet / Connectivity
- Router ID ต้องไม่ซ้ำกัน
- Stub-related Area Options ใน Design ที่เกี่ยวข้อง
OSPF Neighbor คืออะไร?
OSPF Neighbor คือ OSPF Router อีกตัว ที่ถูกค้นพบผ่าน OSPF บน Network Segment ที่เกี่ยวข้อง
ตรวจสอบบน Cisco:
Router# show ip ospf neighbor
ตัวอย่าง:
Neighbor ID State
2.2.2.2 FULL/-
3.3.3.3 FULL/DR
State และข้อความหลังเครื่องหมาย อาจแตกต่างตาม Network Type และบทบาท DR/BDR
OSPF Neighbor States
OSPF Neighbor สามารถผ่านหลาย State ระหว่างการสร้างความสัมพันธ์
Down
|
v
Init
|
v
2-Way
|
v
ExStart
|
v
Exchange
|
v
Loading
|
v
Full
State สำคัญ:
| State | แนวคิด |
|---|---|
| Down | ยังไม่ได้รับ Hello ที่ใช้สร้าง Neighbor State |
| Init | ได้รับ Hello จาก Neighbor แต่ความสัมพันธ์ยังไม่เป็น Two-Way |
| 2-Way | Router เห็น Router ID ของตัวเองใน Hello ของอีกฝั่ง |
| ExStart | เริ่มเตรียมกระบวนการแลกเปลี่ยน Database Description |
| Exchange | แลกเปลี่ยน Database Description Information |
| Loading | ร้องขอ Link-State Information ที่ยังต้องการ |
| Full | Adjacency มี LSDB Synchronization ตามที่ OSPF ต้องการ |
Neighbor กับ Adjacency เหมือนกันหรือไม่?
ไม่ควรใช้สองคำนี้ แทนกันทุกกรณี
Router สามารถเป็น OSPF Neighbor แต่ไม่จำเป็นต้องสร้าง Full Adjacency กับ Neighbor ทุกตัว บน Network Type บางประเภท
Neighbor
|
v
2-Way
|
| If adjacency required
v
ExStart
|
v
Exchange
|
v
Loading
|
v
Full Adjacency
ภาค 3: LSA, LSDB และ SPF
LSA คืออะไร?
LSA — Link-State Advertisement คือข้อมูล Link-State ที่ OSPF ใช้ในการอธิบาย Topology และ Routing Information ตามประเภทของ LSA
แนวคิด:
Router / Network Information
|
v
LSA
|
v
Flood through OSPF scope
|
v
Other OSPF Routers
OSPF มี LSA หลาย Type และ Scope แตกต่างกัน รายละเอียดจะขึ้นอยู่กับ OSPF Area Design และ Route Type
สำหรับพื้นฐาน สิ่งสำคัญคือเข้าใจว่า LSA เป็นข้อมูลที่ใช้สร้าง Link-State Database ไม่ใช่ Routing Table โดยตรง
LSDB คืออะไร?
LSDB — Link-State Database คือฐานข้อมูล Link-State ที่ OSPF Router ใช้ เพื่อสร้างมุมมองของ Topology ภายใน Scope ที่เกี่ยวข้อง
LSA from R1
\
\
LSA from R2 ---> LSDB
/
/
LSA from R3
ตรวจ LSDB บน Cisco:
Router# show ip ospf database
อย่าสับสนระหว่าง:
LSDB
=
Topology / Link-State Information
Routing Table
=
Routes selected for forwarding
SPF Algorithm คืออะไร?
OSPF ใช้ Shortest Path First — SPF หรือ Dijkstra Algorithm ในการคำนวณ Shortest-Path Tree จากข้อมูลใน LSDB
R2
/ \
10/ \10
/ \
R1 R4
\ /
20\ /10
\ /
R3
Router จะใช้ Topology และ OSPF Cost เพื่อคำนวณ Path ตาม SPF Algorithm
กระบวนการ:
LSDB
|
v
SPF Algorithm
|
v
Shortest-Path Tree
|
v
Best OSPF Paths
|
v
Routing Information
|
v
Routing Table
OSPF Cost คืออะไร?
Cost เป็น Metric ที่ OSPF ใช้สำหรับ Path Calculation
แนวคิดพื้นฐานใน OSPF เกี่ยวข้องกับ Reference Bandwidth และ Interface Bandwidth
OSPF Cost
≈
Reference Bandwidth
-------------------
Interface Bandwidth
แต่ค่า Default Reference Bandwidth, Cost Calculation และพฤติกรรม ต้องตรวจสอบตาม Cisco Platform และ Software Release
ตรวจ OSPF Cost
Router# show ip ospf interface
หรือ Interface เฉพาะ:
Router# show ip ospf interface gigabitEthernet 0/0
กำหนด Cost โดยตรง
Router(config)# interface gigabitEthernet 0/0
Router(config-if)# ip ospf cost 10
ภาค 4: OSPF Area
OSPF Area คืออะไร?
OSPF สามารถแบ่ง Routing Domain ออกเป็นหลาย Area เพื่อจัดโครงสร้าง Link-State Database และ Routing Architecture
+-----------+
| Area 1 |
| R1 -- R2 |
+-----+-----+
|
|
+-----+-----+
| Area 0 |
| R3 -- R4 |
+-----+-----+
|
|
+-----+-----+
| Area 2 |
| R5 -- R6 |
+-----------+
Multi-Area OSPF มี Router Roles และ LSA Behavior เพิ่มเติม ซึ่งควรศึกษาแยกจาก Single-Area OSPF
Area 0 คืออะไร?
Area 0 คือ OSPF Backbone Area และเป็นแกนกลางสำคัญ ของ Multi-Area OSPF Design
Area 1
|
v
Area 0
|
v
Area 2
การรับส่ง Inter-Area Routing Information ใน OSPF ปกติ ถูกออกแบบให้สัมพันธ์กับ Backbone Area
สำหรับผู้เริ่มต้น ควรเริ่มจาก Single-Area OSPF Area 0 ก่อนเข้าสู่ ABR, ASBR, Stub Area, NSSA และ Virtual Link
DR และ BDR คืออะไร?
บน OSPF Multiaccess Network Type บางประเภท เช่น Broadcast Ethernet OSPF สามารถเลือก Designated Router — DR และ Backup Designated Router — BDR
สมมติ Router หลายตัวอยู่ LAN เดียวกัน:
R1
|
|
R2 ----SW---- R3
|
|
R4
หาก Router ทุกคู่ ต้องสร้าง Full Adjacency ต่อกันทั้งหมด จำนวน Adjacencies จะเพิ่มตามจำนวน Router
DR/BDR ช่วยจัดโครงสร้าง การสร้าง Adjacency และ Link-State Exchange บน Segment ดังกล่าว
DR
/ | \
/ | \
R1 BDR R3
ภาค 5: OSPF Route และ Cisco Configuration
OSPF Route ใน Routing Table
ตรวจ:
Router# show ip route ospf
ตัวอย่าง:
O 192.168.30.0/24 [110/20] via 10.0.12.2
อ่านแบบพื้นฐาน:
O
|
+-- OSPF Route
192.168.30.0/24
|
+-- Destination Prefix
[110/20]
| |
| +-- OSPF Metric / Cost
|
+------ Administrative Distance
10.0.12.2
|
+-- Next Hop
OSPF มี Route Codes เพิ่มเติมใน Multi-Area และ External Routing เช่น O IA, O E1, O E2 ตามประเภท Route
Cisco OSPF Configuration พื้นฐาน
ตัวอย่าง Router R1:
router ospf 1
router-id 1.1.1.1
network 10.0.12.0 0.0.0.3 area 0
network 192.168.10.0 0.0.0.255 area 0
ส่วน:
router ospf 1
เลข 1
เป็น OSPF Process ID
ซึ่งมี Local Significance
บน Router
Process ID ของ Router ไม่จำเป็นต้องตรงกัน เพื่อให้ Router สร้าง OSPF Neighbor
อีกวิธี: เปิด OSPF ที่ Interface
Cisco IOS/IOS XE หลาย Platform รองรับ Interface-Level Configuration เช่น:
interface gigabitEthernet 0/0
ip ospf 1 area 0
แนวทางที่ใช้จริง ขึ้นอยู่กับ Platform, Software Version และมาตรฐาน Configuration ขององค์กร
ภาค 6: OSPF Lab
Lab: Single-Area OSPF Area 0
Topology:
LAN A
192.168.10.0/24
|
|
R1
1.1.1.1
|
10.0.12.0/30
|
R2
2.2.2.2
|
10.0.23.0/30
|
R3
3.3.3.3
|
|
LAN C
192.168.30.0/24
IP Plan
| Router | Interface/Network | IP Address |
|---|---|---|
| R1 | LAN A | 192.168.10.1/24 |
| R1 | R1-R2 | 10.0.12.1/30 |
| R2 | R1-R2 | 10.0.12.2/30 |
| R2 | R2-R3 | 10.0.23.1/30 |
| R3 | R2-R3 | 10.0.23.2/30 |
| R3 | LAN C | 192.168.30.1/24 |
Step 1 — Configure R1
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 10.0.12.0 0.0.0.3 area 0
R1(config-router)# network 192.168.10.0 0.0.0.255 area 0
Step 2 — Configure R2
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 10.0.12.0 0.0.0.3 area 0
R2(config-router)# network 10.0.23.0 0.0.0.3 area 0
Step 3 — Configure R3
R3(config)# router ospf 1
R3(config-router)# router-id 3.3.3.3
R3(config-router)# network 10.0.23.0 0.0.0.3 area 0
R3(config-router)# network 192.168.30.0 0.0.0.255 area 0
Step 4 — ตรวจ Neighbor
R1:
R1# show ip ospf neighbor
ควรเห็น R2 เมื่อ OSPF Parameters และ Connectivity ถูกต้อง
R2:
R2# show ip ospf neighbor
ควรเห็น R1 และ R3 ใน Topology นี้
Step 5 — ตรวจ Routing Table
R1:
R1# show ip route ospf
ควรเรียนรู้ Network
192.168.30.0/24
ผ่าน OSPF
เมื่อระบบทำงานถูกต้อง
Step 6 — ตรวจ LSDB
R1# show ip ospf database
Step 7 — ตรวจ OSPF Interface
R1# show ip ospf interface brief
Step 8 — End-to-End Test
R1# ping 192.168.30.1
ตรวจ Path:
R1# traceroute 192.168.30.1
Passive Interface กับ OSPF
LAN Interface ที่เชื่อมต่อ End Devices มักไม่จำเป็นต้องพยายาม สร้าง OSPF Neighbor กับ Client
ตัวอย่าง:
router ospf 1
passive-interface gigabitEthernet 0/0
Topology:
PCs
|
|
Gi0/0
R1
|
|
Gi0/1
|
R2
Gi0/0 อาจเป็น Passive ในขณะที่ Router-to-Router Interface Gi0/1 ต้องสามารถ สร้าง Neighbor ตาม Design
OSPF Verification Checklist
1. Interface Status
show ip interface brief
2. OSPF Process
show ip ospf
3. OSPF Interface
show ip ospf interface brief
4. Neighbor
show ip ospf neighbor
5. Neighbor Detail
show ip ospf neighbor detail
6. LSDB
show ip ospf database
7. Routing Table
show ip route ospf
8. Protocol Information
show ip protocols
9. Connectivity
ping x.x.x.x
10. Path
traceroute x.x.x.x
ภาค 7: OSPF Troubleshooting
OSPF Neighbor ไม่ขึ้น ตรวจอะไร?
ควรตรวจจากพื้นฐานก่อน แทนการแก้ OSPF Configuration แบบสุ่ม
Physical Link
|
v
Interface Up?
|
v
IP Address correct?
|
v
Same connected subnet?
|
v
OSPF enabled?
|
v
Correct Area?
|
v
Timers compatible?
|
v
Authentication compatible?
|
v
Network Type?
|
v
Passive Interface?
|
v
Unique Router ID?
|
v
Neighbor State
ตรวจ Physical / IP ก่อน
show ip interface brief
Ping Neighbor:
ping 10.0.12.2
ตรวจว่า OSPF ทำงานบน Interface หรือไม่
show ip ospf interface brief
ตรวจ Area
show ip ospf interface gigabitEthernet 0/1
ตรวจ Hello และ Dead Interval
show ip ospf interface
ตรวจ Passive Interface
show ip protocols
ตรวจ Router ID
show ip ospf
Router ID ซ้ำกัน สามารถสร้างปัญหา ต่อ OSPF Operation ได้
Neighbor ค้างใน State ต่าง ๆ บอกอะไรได้บ้าง?
| อาการ | จุดที่ควรตรวจ |
|---|---|
| ไม่มี Neighbor | Physical, IP, OSPF enablement, Area, Timer, Authentication, Passive Interface |
| INIT | ตรวจ Two-Way Hello Communication และ Network Connectivity |
| 2-Way | อาจเป็น State ปกติบน Multiaccess Network สำหรับ Neighbor บางคู่ |
| ExStart / Exchange ค้าง | ตรวจ MTU, DBD Exchange, Duplicate Router ID และ Connectivity |
| Loading ค้าง | ตรวจ LSA Request/Update, Packet Loss และ Link Stability |
| Full แต่ไม่มี Route | ตรวจ LSDB, Prefix Advertisement, Route Type, Filtering และ Routing Table |
ภาค 8: OSPF Security
OSPF Security ควรคำนึงถึงอะไร?
OSPF เป็น Control-Plane Protocol ดังนั้นไม่ควรเปิด OSPF บน Interface โดยไม่จำเป็น
แนวทางพื้นฐาน:
- กำหนด Router ID อย่างเป็นระบบ
- เปิด OSPF เฉพาะ Interface ที่ต้องการ
- ใช้ Passive Interface สำหรับ User LAN เมื่อเหมาะสม
- ใช้ OSPF Authentication ตาม Platform และ Design
- จำกัด Management Access
- Monitor Neighbor Changes
- Monitor Routing Table และ LSDB
- ป้องกัน Unauthorized Configuration Changes
- สำรอง Configuration
OSPF Authentication
OSPF รองรับกลไก Authentication ตาม Version และ Platform เพื่อช่วยตรวจสอบ OSPF Protocol Exchanges ระหว่าง Routers
Syntax แตกต่างกันระหว่าง OSPFv2, OSPFv3, Cisco IOS/IOS XE Version และ Authentication Method จึงควรอ้างอิง Documentation ของ Platform จริงก่อนนำไปใช้
Cisco OSPF Command Cheat Sheet
| Command | หน้าที่ |
|---|---|
show ip ospf |
ดูข้อมูล OSPF Process |
show ip ospf neighbor |
ดู OSPF Neighbors |
show ip ospf neighbor detail |
ดู Neighbor แบบละเอียด |
show ip ospf interface |
ดู OSPF Interface Details |
show ip ospf interface brief |
ดู OSPF Interfaces แบบสรุป |
show ip ospf database |
ดู Link-State Database |
show ip route ospf |
ดู OSPF Routes |
show ip protocols |
ดู Routing Protocol Information |
show ip interface brief |
ตรวจ IP และ Interface State |
show running-config | section router ospf |
ตรวจ OSPF Configuration ตาม Syntax ที่ Platform รองรับ |
ping |
ทดสอบ IP Reachability |
traceroute |
ตรวจ Path ในระดับหนึ่ง |
คำถามที่พบบ่อย — FAQ
OSPF คืออะไร?
OSPF เป็น Link-State Interior Gateway Protocol ที่ใช้ Link-State Information และ SPF Algorithm เพื่อคำนวณเส้นทาง ภายใน Routing Domain
OSPF ใช้ Metric อะไร?
OSPF ใช้ Cost เป็น Routing Metric สำหรับการคำนวณ Path
Router ID คือ IP Address ของ Interface หรือไม่?
Router ID เป็น 32-bit Identifier ที่แสดงในรูปแบบคล้าย IPv4 Address แต่ไม่ได้หมายความว่า ต้องเป็น Interface Address ที่ใช้ Forward User Traffic
OSPF Process ID ต้องตรงกันทุก Router หรือไม่?
ไม่จำเป็น Cisco OSPF Process ID มี Local Significance บน Router แต่ละตัว
OSPF Neighbor กับ Adjacency เหมือนกันหรือไม่?
ไม่เหมือนกันทุกกรณี Router สามารถเป็น Neighbor โดยไม่จำเป็นต้องสร้าง Full Adjacency ระหว่างกัน บน Network Type บางประเภท
LSA คืออะไร?
LSA หรือ Link-State Advertisement เป็นข้อมูล Link-State ที่ OSPF ใช้สำหรับ การสร้างและ Synchronize Link-State Database ตาม Scope ของ LSA
LSDB กับ Routing Table ต่างกันอย่างไร?
LSDB เก็บ Link-State Information เกี่ยวกับ OSPF Topology ส่วน Routing Table เก็บ Routes ที่ผ่าน Route Selection Process และถูกใช้ในการ Forward Traffic
Area 0 คืออะไร?
Area 0 คือ OSPF Backbone Area และเป็นองค์ประกอบสำคัญ ของ Multi-Area OSPF Architecture
ทำไม OSPF Neighbor ค้างที่ 2-Way?
บน Broadcast Multiaccess Network State 2-Way อาจเป็นพฤติกรรมปกติ สำหรับ Router บางคู่ ที่ไม่จำเป็นต้องสร้าง Full Adjacency กันโดยตรง
OSPF Neighbor Full แล้วทำไมไม่มี Route?
Full Adjacency แสดงว่า Neighbor Relationship และ Database Synchronization มาถึงสถานะที่เกี่ยวข้องแล้ว แต่ยังต้องตรวจว่า Prefix ถูก Advertise หรือไม่, LSDB มีข้อมูลหรือไม่, มี Filtering หรือไม่ และ Route Selection เป็นอย่างไร
สรุป
OSPF ไม่ใช่เพียงคำสั่ง
router ospf
แต่เป็นกระบวนการ
Link-State Routing
ที่มีหลายขั้นตอนเชื่อมต่อกัน
Router ID
|
v
Hello Packet
|
v
Neighbor
|
v
Adjacency
|
v
LSA Exchange
|
v
LSDB
|
v
SPF Calculation
|
v
OSPF Cost
|
v
Best OSPF Path
|
v
Routing Table
|
v
Packet Forwarding
แนวคิดสำคัญที่ควรจำคือ LSA ไม่ใช่ Route, LSDB ไม่ใช่ Routing Table และ Neighbor ไม่ได้หมายถึง Full Adjacency ทุกกรณี
สำหรับการเริ่มต้น Single-Area OSPF Area 0 ช่วยให้เห็นกระบวนการทั้งหมด ได้ง่ายที่สุด ก่อนเพิ่มความซับซ้อน ด้วย Multi-Area OSPF
บทความลำดับต่อไปควรเจาะลึก OSPF Neighbor States และ DR/BDR: Down, Init, 2-Way, ExStart, Exchange, Loading, Full และการเลือก Designated Router เพราะเป็นหัวใจสำคัญ ของการ Troubleshoot OSPF ในระบบจริง
Share your thoughts here
Join the conversation and share your perspective on this article.