
GRE Tunnel และ IPsec over GRE: เชื่อม Site-to-Site ผ่าน Internet
GRE (Generic Routing Encapsulation) เป็น tunneling protocol ที่ encapsulate packets ทุกประเภท (unicast, multicast, broadcast) ไว้ใน IP packet ทำให้สามารถส่ง traffic ข้าม network ที่แตกต่างกันได้ เมื่อรวมกับ IPsec จะได้ทั้ง flexibility ของ GRE และ encryption ของ IPsec เหมาะสำหรับ site-to-site VPN ที่ต้องรัน routing protocols
IPsec อย่างเดียว ไม่รองรับ multicast traffic ทำให้ไม่สามารถรัน dynamic routing protocols (OSPF, EIGRP) ข้าม tunnel ได้โดยตรง GRE แก้ปัญหานี้โดยสร้าง virtual point-to-point link ที่รองรับ multicast แต่ GRE อย่างเดียวไม่มี encryption IPsec over GRE จึงเป็นทางออกที่ดีที่สุด บทความนี้จะอธิบายทั้ง GRE และ IPsec over GRE พร้อม configuration
GRE vs IPsec vs IPsec over GRE
| คุณสมบัติ | GRE | IPsec | IPsec over GRE |
|---|---|---|---|
| Encryption | ไม่มี | มี (AES, 3DES) | มี |
| Multicast Support | รองรับ | ไม่รองรับ | รองรับ |
| Routing Protocols | รันได้ (OSPF, EIGRP, BGP) | ไม่ได้ (static routes เท่านั้น) | รันได้ |
| Overhead | 24 bytes | 50-57 bytes | 74-81 bytes |
| Use Case | Lab, internal tunnels | Site-to-site VPN (simple) | Site-to-site VPN (dynamic routing) |
GRE Tunnel Basics
How GRE Works
GRE Encapsulation: Original Packet → เพิ่ม GRE Header (4-8 bytes) → เพิ่ม New IP Header (20 bytes) Tunnel Source: IP ของ router ฝั่งนี้ (public IP) Tunnel Destination: IP ของ router ฝั่งโน้น (public IP) Tunnel Interface: virtual interface ที่มี IP subnet ของตัวเอง
GRE Configuration (Cisco IOS)
Router A (Site A): interface Tunnel0 → ip address 10.0.0.1 255.255.255.252 → tunnel source GigabitEthernet0/0 → tunnel destination 203.0.113.2
Router B (Site B): interface Tunnel0 → ip address 10.0.0.2 255.255.255.252 → tunnel source GigabitEthernet0/0 → tunnel destination 198.51.100.1
IPsec over GRE Configuration
Step-by-Step
Step 1: ISAKMP Policy (Phase 1): crypto isakmp policy 10 → encryption aes 256 → hash sha256 → authentication pre-share → group 14 → lifetime 86400 crypto isakmp key StrongKey123! address 203.0.113.2
Step 2: IPsec Transform Set (Phase 2): crypto ipsec transform-set TS-AES256 esp-aes 256 esp-sha256-hmac → mode transport (ใช้ transport mode เพราะ encrypt GRE packet)
Step 3: Crypto Map: crypto map CMAP 10 ipsec-isakmp → set peer 203.0.113.2 → set transform-set TS-AES256 → match address GRE-TRAFFIC ip access-list extended GRE-TRAFFIC → permit gre host 198.51.100.1 host 203.0.113.2
Step 4: Apply to Interface: interface GigabitEthernet0/0 → crypto map CMAP
Step 5: GRE Tunnel: interface Tunnel0 → ip address 10.0.0.1 255.255.255.252 → tunnel source GigabitEthernet0/0 → tunnel destination 203.0.113.2
GRE over IPsec vs IPsec over GRE
| แบบ | ลำดับ Encapsulation | IPsec Mode | ข้อดี |
|---|---|---|---|
| IPsec over GRE | Original → GRE → IPsec → IP | Transport mode | Overhead น้อยกว่า ใช้ทั่วไป |
| GRE over IPsec | Original → IPsec → GRE → IP | Tunnel mode | GRE header ไม่ถูก encrypt (ดู src/dst ได้) |
Dynamic Routing over GRE
OSPF ข้าม GRE Tunnel
Router A: router ospf 1 → network 10.0.0.0 0.0.0.3 area 0 → network 192.168.1.0 0.0.0.255 area 0
Router B: router ospf 1 → network 10.0.0.0 0.0.0.3 area 0 → network 192.168.2.0 0.0.0.255 area 0
ผลลัพธ์: OSPF adjacency form ข้าม Tunnel0 interface แต่ละ site เรียนรู้ routes ของอีก site อัตโนมัติ ถ้ามี link ใหม่เพิ่ม → OSPF advertise อัตโนมัติ (ไม่ต้อง static routes)
DMVPN: GRE + IPsec + NHRP
Hub-and-Spoke to Any-to-Any
DMVPN (Dynamic Multipoint VPN) ใช้ GRE + IPsec + NHRP สร้าง VPN ที่ scalable: Hub-and-Spoke topology (phase 1-2) Spoke-to-Spoke direct tunnels (phase 3) ไม่ต้อง config tunnel ทุกคู่ (dynamic) รองรับ routing protocols ข้าม DMVPN
Troubleshooting
| ปัญหา | สาเหตุ | วิธีแก้ |
|---|---|---|
| Tunnel interface down | Tunnel source/destination unreachable | ตรวจ routing ไป public IP ของ peer |
| Ping ผ่าน tunnel ไม่ได้ | MTU/MSS issue (GRE overhead) | ตั้ง ip mtu 1400 + ip tcp adjust-mss 1360 |
| IPsec ไม่ขึ้น | Key mismatch, NAT-T, firewall block | ตรวจ ISAKMP policy match, เปิด port 500/4500 |
| OSPF ไม่ form adjacency | Network statement ไม่ตรง, hello/dead timer mismatch | ตรวจ network statement + timers |
| Recursive routing | Tunnel destination อยู่ใน routing table ผ่าน tunnel เอง | ตั้ง static route ไป tunnel destination ผ่าน physical interface |
ทิ้งท้าย: GRE + IPsec = VPN ที่ Flexible และ Secure
GRE Tunnel ให้ flexibility (multicast, routing protocols) IPsec ให้ security (encryption) รวมกันได้ site-to-site VPN ที่ทั้ง flexible และ secure ใช้ transport mode สำหรับ IPsec over GRE (overhead น้อยกว่า) อย่าลืมปรับ MTU/MSS เพื่อป้องกัน fragmentation
อ่านเพิ่มเติมเกี่ยวกับ VPN Site-to-Site IPsec และ OSPF vs EIGRP vs BGP ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com