Techerest

Static Route และ Default Route บน Cisco คืออะไร? พื้นฐาน Routing พร้อม Lab

หลังจากเข้าใจ VLAN, Inter-VLAN Routing และการ Troubleshoot ภายใน LAN แล้ว ขั้นต่อไปคือการเรียนรู้ว่า Router หรือ Layer 3 Switch จะส่ง Packet ไปยัง Network ที่ไม่ได้เชื่อมต่อโดยตรงได้อย่างไร ซึ่งเป็นพื้นฐานของ Routing

บทความนี้จะเริ่มจาก Routing Table, Connected Route, Static Route และ Default Route พร้อมตัวอย่าง Cisco IOS เพื่อให้เข้าใจเส้นทางของ Packet ก่อนเข้าสู่ Dynamic Routing Protocol ในบทต่อไป

ภาค 1: Routing Fundamentals

Routing คืออะไร?

Routing คือกระบวนการเลือกเส้นทาง เพื่อ Forward IP Packet จาก Network หนึ่ง ไปยังอีก Network หนึ่ง

ตัวอย่าง:

PC-A
192.168.10.100
      |
      v
Router A
      |
      v
Router B
      |
      v
Server
192.168.20.100

เมื่อ Router ได้รับ Packet จะตรวจสอบ Destination IP Address แล้วค้นหา Routing Table เพื่อหาเส้นทางที่เหมาะสม

Packet arrives
      |
      v
Read Destination IP
      |
      v
Search Routing Table
      |
      v
Select Route
      |
      v
Determine Next Hop / Exit
      |
      v
Forward Packet

Routing Table คืออะไร?

Routing Table เป็นข้อมูลที่ Layer 3 Device ใช้ตัดสินใจว่าจะส่ง Packet ไปทางใด

Cisco IOS:

Router# show ip route

ตัวอย่างแบบย่อ:

C    192.168.10.0/24 is directly connected, GigabitEthernet0/0
L    192.168.10.1/32 is directly connected, GigabitEthernet0/0
S    192.168.20.0/24 [1/0] via 10.0.0.2

ตัวอักษรด้านหน้า Route ช่วยบอก Source เช่น:

Code ความหมาย
C Connected
L Local
S Static
O OSPF

Routing Protocol อื่น สามารถมี Route Code อื่นเพิ่มเติม ตาม Platform และ Protocol ที่ใช้งาน

Connected Route คืออะไร?

Connected Route เกิดจาก Network ที่เชื่อมต่อโดยตรงกับ Layer 3 Interface ซึ่งอยู่ในสถานะที่เหมาะสม

ตัวอย่าง:

interface gigabitEthernet 0/0
 ip address 192.168.10.1 255.255.255.0
 no shutdown

Routing Table อาจมี:

C 192.168.10.0/24 is directly connected, GigabitEthernet0/0

Topology:

192.168.10.0/24
       |
       |
Gi0/0 192.168.10.1
+-------------+
|  Router A   |
+-------------

Local Route คืออะไร?

บน Cisco IOS/IOS XE มักเห็น Route Code L สำหรับ IP Address ของ Interface เอง

L 192.168.10.1/32 is directly connected, GigabitEthernet0/0

ดังนั้น Connected Route และ Local Route ไม่ใช่สิ่งเดียวกัน

C = Connected Network

192.168.10.0/24


L = Interface Address

192.168.10.1/32

ภาค 2: Static Route

Static Route คืออะไร?

Static Route คือ Route ที่ผู้ดูแลระบบ กำหนดด้วย Configuration แทนการเรียนรู้ผ่าน Dynamic Routing Protocol

สมมติ:

LAN A
192.168.10.0/24
       |
       |
   Router A
       |
       | 10.0.0.1
       |
       | 10.0.0.2
       |
   Router B
       |
       |
LAN B
192.168.20.0/24

Router A รู้จัก 192.168.10.0/24 เพราะเป็น Connected Network

แต่หากต้องการไป 192.168.20.0/24 Router A ต้องมี Route ที่บอกว่าจะส่ง Packet ไปทางไหน

Next-Hop Static Route

รูปแบบพื้นฐาน:

ip route DESTINATION MASK NEXT-HOP

ตัวอย่างบน Router A:

RouterA(config)# ip route 192.168.20.0 255.255.255.0 10.0.0.2

ความหมาย:

Destination Network
192.168.20.0/24

Next Hop
10.0.0.2

เมื่อ Router A ต้องส่ง Packet ไป 192.168.20.x จึงใช้ 10.0.0.2 เป็น Next Hop ตาม Route นี้

Exit Interface Static Route

ในบาง Topology และ Interface Type สามารถกำหนด Static Route โดยอ้างอิง Exit Interface ตาม Syntax ที่ Platform รองรับ

Router(config)# ip route 192.168.20.0 255.255.255.0 gigabitEthernet 0/1

อย่างไรก็ตามพฤติกรรมของ Exit-Interface Route ต้องพิจารณาตาม Interface Type, Address Resolution และ Platform จึงไม่ควรเลือก Syntax โดยไม่เข้าใจ Topology

Fully Specified Static Route

Static Route บางรูปแบบ สามารถระบุทั้ง Exit Interface และ Next-Hop Address

Router(config)# ip route 192.168.20.0 255.255.255.0 gigabitEthernet 0/1 10.0.0.2

แนวคิด:

Destination
192.168.20.0/24

Exit Interface
Gi0/1

Next Hop
10.0.0.2
การเลือก Next-Hop, Exit Interface หรือ Fully Specified Static Route ควรพิจารณา Interface Type, Topology และ Cisco Platform ที่ใช้งานจริง

ภาค 3: Default Route

Default Route คืออะไร?

Default Route เป็น Route ที่ใช้เมื่อ ไม่มี Route ที่ Specific กว่า สำหรับ Destination นั้น

IPv4 Default Route:

0.0.0.0/0

ตัวอย่าง:

Router(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.1

แนวคิด:

Destination known?
      |
   +--+--+
   |     |
  Yes    No
   |     |
   v     v
Specific Default
 Route    Route

Default Route มักถูกใช้กับ Edge Router หรืออุปกรณ์ที่มีเส้นทางหลัก ออกไปยัง Upstream Network

ตัวอย่าง:

LAN
 |
 v
Router
 |
 | Default Route
 v
Firewall
 |
 v
ISP / Internet
Default Route ไม่ได้หมายความว่า Destination ทุกแห่งจะใช้งานได้โดยอัตโนมัติ ยังต้องมี Next-Hop Reachability, Return Path, Firewall Policy, NAT และ Infrastructure อื่น ตาม Network Design

Longest Prefix Match คืออะไร?

Router ไม่ได้เลือก Default Route เพียงเพราะมันมีอยู่ หากมี Route ที่ Specific กว่า และใช้ได้สำหรับ Destination Router จะพิจารณา Route ตามหลัก Routing Lookup

สมมติ Routing Table มี:

192.168.0.0/16
192.168.10.0/24
192.168.10.128/25
0.0.0.0/0

Destination:

192.168.10.200

สามารถ Match:

/0
/16
/24
/25

Route /25 มี Prefix ที่ยาวและ Specific กว่า Route อื่นที่ Match Destination นี้

Longest Matching Prefix
        |
        v
192.168.10.128/25
Longest Prefix Match และ Administrative Distance เป็นคนละแนวคิด บทความถัดไปจะอธิบาย Administrative Distance และ Metric โดยเฉพาะ

Return Route สำคัญอย่างไร?

นี่เป็นหนึ่งในจุดที่ผู้เริ่มต้น Troubleshoot Routing พลาดบ่อย

สมมติ:

PC-A
192.168.10.100
   |
Router A
   |
Router B
   |
Server
192.168.20.100

Router A มี Route ไป LAN B ไม่ได้หมายความว่า Communication จะสำเร็จเสมอไป

ฝั่งกลับต้องสามารถ ส่ง Packet กลับไปยัง 192.168.10.0/24 ได้ด้วย

Forward Path

192.168.10.100
       |
       v
192.168.20.100


Return Path

192.168.20.100
       |
       v
192.168.10.100

ตัวอย่าง Router A:

ip route 192.168.20.0 255.255.255.0 10.0.0.2

Router B:

ip route 192.168.10.0 255.255.255.0 10.0.0.1
เมื่อ Ping หรือ Application เดินทางไปถึงปลายทาง แต่ Response กลับไม่ได้ ควรตรวจสอบ Return Path ก่อนสรุปว่า ACL หรือ Firewall เป็นสาเหตุ

ภาค 4: Floating Static Route

Floating Static Route คืออะไร?

Static Route สามารถกำหนด Administrative Distance เพิ่มเติมได้ เพื่อใช้เป็นเส้นทางสำรอง ในบาง Network Design

ตัวอย่าง:

Router(config)# ip route 192.168.20.0 255.255.255.0 10.0.0.2 200

เลข 200 ในตัวอย่างนี้คือ Administrative Distance ของ Static Route ดังกล่าว

แนวคิด:

Primary Route
     |
     | Available
     v
   Used


Primary unavailable
     |
     v
Backup Static Route
with higher AD
     |
     v
May become selected

Static Route ที่ตั้ง AD ให้สูงกว่า Route หลัก ใน Design ที่เหมาะสม มักเรียกว่า Floating Static Route

การเลือก Route ไม่ได้พิจารณา Administrative Distance เพียงค่าเดียวในทุกสถานการณ์ ต้องเข้าใจ Route Lookup, Prefix Length, Routing Source และ Metric ร่วมกัน

Static Route บน Layer 3 Switch

Layer 3 Switch ที่รองรับ Routing สามารถมี Static Route ได้ เช่นเดียวกับ Router ตาม Feature ของ Platform

ตัวอย่าง:

Switch(config)# ip routing

สร้าง Routed Link:

Switch(config)# interface gigabitEthernet 1/0/48
Switch(config-if)# no switchport
Switch(config-if)# ip address 10.0.0.2 255.255.255.252
Switch(config-if)# no shutdown

Default Route:

Switch(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.1

Topology:

VLAN 10
VLAN 20
VLAN 30
   |
   v
Layer 3 Switch
   |
10.0.0.2
   |
10.0.0.1
   |
Firewall / Router
   |
Internet
คำสั่งและ Routing Capability แตกต่างตาม Cisco Platform, License และ Software Release ควรตรวจสอบ Documentation ของอุปกรณ์จริง

ภาค 5: Cisco Static Routing Lab

Lab: เชื่อมสอง LAN ด้วย Static Route

Topology:

PC-A
192.168.10.100/24
GW 192.168.10.1
       |
       |
192.168.10.1
+--------------+
|   Router A   |
+--------------+
10.0.0.1/30
       |
       |
10.0.0.2/30
+--------------+
|   Router B   |
+--------------+
192.168.20.1
       |
       |
PC-B
192.168.20.100/24
GW 192.168.20.1

Step 1 — Router A

RouterA# configure terminal

RouterA(config)# interface gigabitEthernet 0/0
RouterA(config-if)# ip address 192.168.10.1 255.255.255.0
RouterA(config-if)# no shutdown
RouterA(config-if)# exit

RouterA(config)# interface gigabitEthernet 0/1
RouterA(config-if)# ip address 10.0.0.1 255.255.255.252
RouterA(config-if)# no shutdown
RouterA(config-if)# exit

Step 2 — Router B

RouterB# configure terminal

RouterB(config)# interface gigabitEthernet 0/0
RouterB(config-if)# ip address 192.168.20.1 255.255.255.0
RouterB(config-if)# no shutdown
RouterB(config-if)# exit

RouterB(config)# interface gigabitEthernet 0/1
RouterB(config-if)# ip address 10.0.0.2 255.255.255.252
RouterB(config-if)# no shutdown
RouterB(config-if)# exit

Step 3 — ตรวจ Connected Routes

Router A:

RouterA# show ip route

ควรมี Network ที่เชื่อมต่อโดยตรง:

192.168.10.0/24
10.0.0.0/30

Router B:

RouterB# show ip route

ควรมี:

192.168.20.0/24
10.0.0.0/30

Step 4 — Router A เรียนรู้ LAN B ด้วย Static Route

RouterA(config)# ip route 192.168.20.0 255.255.255.0 10.0.0.2

Step 5 — Router B สร้าง Return Route

RouterB(config)# ip route 192.168.10.0 255.255.255.0 10.0.0.1

Step 6 — ตรวจ Routing Table

RouterA# show ip route
RouterB# show ip route

Router A ควรมี:

S 192.168.20.0/24 via 10.0.0.2

Router B ควรมี:

S 192.168.10.0/24 via 10.0.0.1

Step 7 — ทดสอบ Next Hop

จาก Router A:

RouterA# ping 10.0.0.2

จาก Router B:

RouterB# ping 10.0.0.1

Step 8 — ทดสอบ End-to-End

จาก PC-A:

ping 192.168.20.100

จาก PC-B:

ping 192.168.10.100

หาก Ping ไม่สำเร็จ ให้ตรวจทั้ง Forward Route และ Return Route รวมถึง Host Firewall และ Endpoint Configuration

Lab: Default Route

เพิ่ม Router C:

LAN A
 |
Router A
 |
Router B
 |
Router C
 |
Upstream Network

หาก Router A ต้องส่ง Destination ที่ไม่รู้จักทั้งหมด ไป Router B:

RouterA(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.2

ตรวจ:

RouterA# show ip route

อาจพบ:

S* 0.0.0.0/0 via 10.0.0.2

เครื่องหมายและ Output จริง อาจแตกต่างตาม Platform/Release แต่แนวคิดคือ Router มี Candidate Default Route สำหรับ Destination ที่ไม่มี Route Specific กว่า

Verification หลังตั้ง Static Route

ไม่ควรหยุดเพียงเพราะ Configuration Command ถูก Accept

ควรตรวจอย่างน้อย:

1. Interface

show ip interface brief

2. Routing Table

show ip route

3. Static Routes

show ip route static

คำสั่งหรือ Output อาจแตกต่างตาม Platform

4. Next-Hop Reachability

ping 10.0.0.2

5. Destination

ping 192.168.20.100

6. Path

traceroute 192.168.20.100

7. Running Configuration

show running-config | include ^ip route

ภาค 6: Static Route Troubleshooting

Static Route ใช้งานไม่ได้ ตรวจอะไรบ้าง?

1. Destination Network ถูกต้องหรือไม่?

ip route 192.168.20.0 255.255.255.0 10.0.0.2

ตรวจ Network Address และ Subnet Mask ให้ตรงกับ Destination จริง

2. Next Hop ถูกต้องหรือไม่?

ping 10.0.0.2

หาก Next Hop ไม่สามารถ Resolve/Reach ตามที่ Routing Design ต้องการ Static Route อาจไม่ทำงานตามที่คาด

3. Interface Up หรือไม่?

show ip interface brief

4. Route อยู่ใน Routing Table หรือไม่?

show ip route 192.168.20.0

5. มี Route ที่ Specific กว่าหรือไม่?

ตรวจสอบ Longest Prefix Match เพราะ Packet อาจใช้ Route ที่ Specific กว่า แทน Route ที่กำลังตรวจสอบ

6. Return Route มีหรือไม่?

Router A
192.168.10.0/24
       |
       v
192.168.20.0/24
Router B

Forward Route ✓

Return Route ?

7. ACL หรือ Firewall Block หรือไม่?

show ip access-lists

อย่าสรุปว่า Routing ผิด เพียงเพราะ Ping ไม่ผ่าน

8. Endpoint Gateway ถูกต้องหรือไม่?

PC-A:

IP       192.168.10.100
Mask     255.255.255.0
Gateway  192.168.10.1

9. ARP ทำงานหรือไม่?

show ip arp

10. ใช้ Traceroute แยก Problem Domain

traceroute 192.168.20.100

Traceroute เป็นข้อมูลประกอบ แต่บาง Hop อาจไม่ตอบ Probe แม้ยัง Forward Traffic ได้

Static Routing กับ Dynamic Routing ต่างกันอย่างไร?

หัวข้อ Static Routing Dynamic Routing
การสร้าง Route ผู้ดูแลกำหนด Routing Protocol เรียนรู้/แลกเปลี่ยนข้อมูล
ความซับซ้อน ต่ำสำหรับ Network ขนาดเล็ก เพิ่มขึ้นตาม Protocol และ Design
Topology Change มักต้องอาศัย Configuration หรือกลไกเพิ่มเติม Protocol สามารถเรียนรู้การเปลี่ยนแปลงตามการทำงานของมัน
Control กำหนดเส้นทางได้โดยตรง เลือก Route ตาม Protocol Logic และ Policy
เหมาะกับ เส้นทางที่เรียบง่าย, Stub Network, Default/Backup ตาม Design Network ที่มีหลายเส้นทางหรือ Topology ซับซ้อน

ทั้งสองแบบสามารถใช้ร่วมกัน ใน Network เดียวกันได้ ขึ้นอยู่กับ Routing Design

คำสั่ง Cisco Routing ที่ควรรู้

Command หน้าที่
show ip route ดู IPv4 Routing Table
show ip route static ดู Static Routes ตามความสามารถของ Platform
show ip route x.x.x.x ตรวจ Routing Information สำหรับ Destination
show ip interface brief ตรวจ IP และ Interface Status
show interfaces ตรวจ Interface โดยละเอียด
show ip arp ตรวจ ARP Table
ip route ... สร้าง IPv4 Static Route
ip route 0.0.0.0 0.0.0.0 ... สร้าง IPv4 Default Static Route
ping ทดสอบ IP Reachability
traceroute ตรวจสอบเส้นทางในระดับหนึ่ง
show running-config ตรวจ Configuration ปัจจุบัน

คำถามที่พบบ่อย — FAQ

Static Route คืออะไร?

Static Route คือ Route ที่ผู้ดูแลระบบกำหนดใน Configuration เพื่อบอก Layer 3 Device ว่าจะส่ง Traffic ไปยัง Destination Network ผ่าน Next Hop หรือ Interface ใด ตามรูปแบบที่รองรับ

Default Route คืออะไร?

Default Route คือ Route สำหรับ Destination ที่ไม่มี Route Specific กว่า ใน Routing Table โดย IPv4 Default Prefix คือ 0.0.0.0/0

Next Hop คืออะไร?

Next Hop คือ Layer 3 Device ถัดไปที่ Router ใช้เป็นทางส่ง Packet ไปสู่ Destination ตาม Route ที่เลือก

Static Route กับ Connected Route ต่างกันอย่างไร?

Connected Route เกิดจาก Network ที่เชื่อมต่อโดยตรง กับ Layer 3 Interface ส่วน Static Route ถูกกำหนดผ่าน Configuration โดยผู้ดูแลระบบ

Default Route ใช้แทน Static Route ทั้งหมดได้หรือไม่?

Default Route สามารถใช้เป็น Catch-All Route เมื่อไม่มี Route Specific กว่า แต่ไม่ได้แทนความจำเป็น ของ Specific Route ในทุก Network Design

ทำไมมี Static Route แล้ว Ping ไม่ผ่าน?

ควรตรวจ Next Hop, Interface State, Return Route, Endpoint Gateway, ARP, ACL, Firewall และ Destination Host ไม่ใช่ตรวจเฉพาะ Forward Static Route

Static Route มี Administrative Distance เท่าไร?

บน Cisco IOS Static Route ปกติมักมี Administrative Distance เริ่มต้นเป็น 1 แต่สามารถกำหนดค่าอื่นได้ และรายละเอียดควรตรวจตาม Platform และ Routing Configuration ที่ใช้งาน

Floating Static Route คืออะไร?

เป็น Static Route ที่ตั้ง Administrative Distance ให้เหมาะกับบทบาทเส้นทางสำรอง เพื่อให้ Route อื่นถูกเลือกก่อน ใน Design ที่ต้องการ

Layer 3 Switch ใช้ Static Route ได้หรือไม่?

ได้บน Layer 3 Switch ที่รองรับ Routing Feature และมี Configuration/License ที่เหมาะสม

Static Route เหมาะกับ Network ขนาดใหญ่หรือไม่?

สามารถใช้ในบางส่วนของ Network ขนาดใหญ่ได้ แต่หากมีหลาย Router, หลายเส้นทาง และ Topology เปลี่ยนแปลงบ่อย การกำหนด Static Routes จำนวนมาก อาจเพิ่มภาระในการบริหาร จึงมักมีการใช้ Dynamic Routing ร่วมด้วยตาม Design

สรุป

Static Route เป็นพื้นฐานสำคัญของ Routing เพราะทำให้เห็นชัดว่า Router ต้องมีข้อมูลเกี่ยวกับ Destination ก่อนที่จะตัดสินใจ Forward Packet ไปยัง Network อื่น

Route พื้นฐานที่ควรรู้ในขั้นนี้คือ:

Connected Route
      |
      v
Local Route
      |
      v
Static Route
      |
      v
Default Route

และต้องเข้าใจว่า การสื่อสาร End-to-End ไม่ได้มีเพียง Forward Path

Source
  |
  | Forward Route
  v
Destination
  |
  | Return Route
  v
Source

อีกแนวคิดสำคัญคือ Longest Prefix Match ซึ่งทำให้ Router เลือก Route ที่ Specific กับ Destination มากกว่า เมื่อมีหลาย Prefix ที่ Match

หลังจากเข้าใจ Static Route และ Default Route แล้ว คำถามสำคัญถัดไปคือ:

ถ้า Router เรียนรู้
Destination เดียวกัน
จากหลายแหล่ง

Router จะเลือก Route ไหน?

ดังนั้นบทความลำดับต่อไปคือ Administrative Distance และ Metric บน Cisco: Router เลือกเส้นทางอย่างไร? ก่อนเข้าสู่ Dynamic Routing และ OSPF

Share this
Facebook Share X
TECHEREST COMMUNITY

Share your thoughts here

Join the conversation and share your perspective on this article.

Comments will load when you reach this section.