GRE Tunnel: วิธีสร้าง Tunnel เชื่อมต่อ Network ข้าม Internet

GRE Tunnel: วิธีสร้าง Tunnel เชื่อมต่อ Network ข้าม Internet

GRE (Generic Routing Encapsulation) เป็น tunneling protocol ที่ encapsulate packets ของ protocol หนึ่งภายใน protocol อื่น ทำให้สามารถส่ง traffic ข้าม network ที่ไม่รองรับ protocol นั้นได้ ตัวอย่างเช่น ส่ง multicast traffic ข้าม internet (internet ไม่รองรับ multicast แต่ GRE tunnel รองรับ)

GRE tunnel ใช้กันมากสำหรับ เชื่อมต่อ 2 sites ข้าม internet เป็น point-to-point tunnel ที่ง่ายที่สุด แต่ GRE ไม่มี encryption ดังนั้นมักใช้ร่วมกับ IPsec (GRE over IPsec) เพื่อเพิ่มความปลอดภัย บทความนี้จะอธิบาย GRE tunnel วิธี configure และเมื่อไหร่ควรใช้

GRE ทำงานอย่างไร

Encapsulation

Original packet (เช่น IP packet จาก LAN) ถูกห่อด้วย GRE header แล้วห่ออีกชั้นด้วย outer IP header (source = tunnel source IP, destination = tunnel destination IP) outer IP header ใช้ routing บน internet เพื่อส่ง packet ไปยังปลายทาง เมื่อถึงปลายทาง outer IP + GRE header ถูกถอดออก original packet ถูกส่งต่อเข้า LAN ปลายทาง

โครงสร้าง Packet

Layer Header ทำหน้าที่
Outer IP Header (WAN IPs) Routing บน internet
Middle GRE Header (4 bytes) Encapsulation protocol info
Inner Original Packet (IP, multicast, etc.) Payload จริง

GRE vs IPsec vs GRE over IPsec

คุณสมบัติ GRE IPsec GRE over IPsec
Encryption ไม่มี มี (AES) มี (AES)
Multicast รองรับ ไม่รองรับ (tunnel mode) รองรับ
Routing Protocols รองรับ (OSPF, EIGRP) ไม่รองรับ (ตรงๆ) รองรับ
Overhead ต่ำ (24 bytes) สูง (50-70 bytes) สูงมาก (74-94 bytes)
Use Case Lab, trusted network Site-to-site VPN Site-to-site VPN + routing protocols

ตัวอย่าง Topology

Site WAN IP LAN Subnet Tunnel IP
HQ (Router A) 203.0.113.1 10.0.1.0/24 172.16.0.1/30
Branch (Router B) 198.51.100.1 10.0.2.0/24 172.16.0.2/30

Configure GRE Tunnel (Cisco)

Router A (HQ)

สร้าง Tunnel Interface: interface Tunnel0 ip address 172.16.0.1 255.255.255.252 tunnel source 203.0.113.1 tunnel destination 198.51.100.1 tunnel mode gre ip เพิ่ม static route สำหรับ remote LAN: ip route 10.0.2.0 255.255.255.0 172.16.0.2

Router B (Branch)

Mirror configuration: interface Tunnel0 ip address 172.16.0.2 255.255.255.252 tunnel source 198.51.100.1 tunnel destination 203.0.113.1 tunnel mode gre ip เพิ่ม static route: ip route 10.0.1.0 255.255.255.0 172.16.0.1

Routing Protocols บน GRE

OSPF over GRE

ข้อดีของ GRE: รัน OSPF (หรือ EIGRP) บน tunnel interface ได้ ไม่ต้อง maintain static routes ถ้ามีหลาย subnets OSPF จะ advertise routes อัตโนมัติ ถ้า tunnel down OSPF จะ reconverge ใช้ routes อื่น (ถ้ามี) configure OSPF network statement ให้รวม tunnel subnet (172.16.0.0/30) + LAN subnets

GRE over IPsec

เพิ่ม Encryption

GRE อย่างเดียวไม่ encrypt traffic ถ้าต้องการ security ต้องใช้ GRE over IPsec: สร้าง IPsec crypto map หรือ IPsec profile apply IPsec profile บน Tunnel interface ทุก packet ที่ผ่าน GRE tunnel จะถูก encrypt ด้วย IPsec ได้ทั้ง encryption + multicast + routing protocols

MTU และ Fragmentation

ปัญหา MTU

GRE เพิ่ม overhead 24 bytes (GRE header 4 bytes + outer IP header 20 bytes) Ethernet MTU = 1500 bytes GRE tunnel MTU = 1500 – 24 = 1476 bytes GRE over IPsec MTU = 1500 – 24 – 50~70 = 1406-1426 bytes ถ้าไม่ปรับ MTU อาจเกิด fragmentation (ช้า) หรือ black hole (packets ถูก drop)

แก้ไข

ตั้ง MTU บน Tunnel interface: ip mtu 1400 (safe value สำหรับ GRE over IPsec) เปิด MSS clamping: ip tcp adjust-mss 1360 (ลด TCP MSS ให้ไม่เกิน tunnel MTU)

Troubleshooting

ปัญหา สาเหตุ แก้ไข
Tunnel up แต่ ping ไม่ผ่าน Routing ผิด, ACL block ตรวจ routing table, ตรวจ ACL
Tunnel down WAN IP ไม่ถึงกัน, ISP block GRE (protocol 47) Ping WAN IP, ตรวจ ISP policy
Performance ช้า MTU/fragmentation issues ลด MTU, เปิด MSS clamping
Recursive routing Tunnel destination อยู่ใน route ที่เรียนจาก tunnel ใช้ static route สำหรับ tunnel destination ผ่าน physical interface

ทิ้งท้าย: GRE เป็นพื้นฐานของ Network Tunneling

GRE Tunnel เป็น tunneling ที่ง่ายที่สุด เหมาะสำหรับเชื่อมต่อ sites ที่ต้องการ routing protocols หรือ multicast ใช้ร่วมกับ IPsec เพื่อ encryption ระวัง MTU issues ตั้ง ip mtu และ tcp adjust-mss

อ่านเพิ่มเติมเกี่ยวกับ VPN Site-to-Site IPsec และ SD-WAN ที่ 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