Techerest

Cisco Site-to-Site IPsec VPN ด้วย IKEv2 และ VTI พร้อม Lab

Site-to-Site IPsec VPN ช่วยเชื่อมเครือข่ายสำนักงานสองแห่งผ่าน Internet โดยปกป้องข้อมูลระหว่าง VPN Gateways บทนี้สร้าง Route-Based VPN ด้วย IKEv2 และ Static Virtual Tunnel Interface (SVTI) บน Cisco IOS XE ตั้งแต่ Topology, Full Configuration, Verification จนถึง Troubleshooting

ตัวอย่างเป็น Lab สำหรับอุปกรณ์ Cisco IOS XE ที่รองรับ IKEv2, IPsec Profile และ VTI คำสั่งและ Feature Support อาจแตกต่างตามรุ่นและ Release จึงต้องตรวจเอกสารของ Platform ก่อนใช้ Production

1. Route-Based IPsec VPN และ VTI คืออะไร?

Route-Based VPN ใช้ Routing Table เลือก Traffic ที่จะส่งผ่าน Tunnel Interface แทนการใช้ Crypto ACL เป็นหลักเหมือน Policy-Based Crypto Map แบบดั้งเดิม

HQ LAN -- HQ-R1 == IPsec VTI == BR-R2 -- Branch LAN
                \___ Internet ___/

VTI เป็น Logical Layer 3 Interface ที่สามารถกำหนด IP Address และ Static Route ได้ โดย tunnel protection ipsec profile ใช้ผูก IPsec Profile กับ Tunnel

ข้อจำกัดสำคัญ: VTI ไม่ใช่การรับประกันว่า Traffic ทุกชนิดถูกเข้ารหัส ต้องตรวจ Route, Tunnel State, IPsec SA และ Traffic ที่วิ่งผ่าน Interface จริง

2. Lab Topology และ IP Addressing

HQ LAN 192.168.10.0/24                    Branch LAN 192.168.20.0/24
          |                                           |
     Gi0/1 .1                                   Gi0/1 .1
       HQ-R1                                       BR-R2
 Gi0/0 203.0.113.10/30                     Gi0/0 198.51.100.10/30
          |                                           |
  ISP GW 203.0.113.9                         ISP GW 198.51.100.9
          +--------------- INTERNET ------------------+

        Tunnel10: 10.255.0.1/30 <==> 10.255.0.2/30
               IKEv2 + ESP AES-256-GCM
รายการHQ-R1BR-R2
WAN IP203.0.113.10/30198.51.100.10/30
ISP Gateway203.0.113.9198.51.100.9
LAN Gateway192.168.10.1/24192.168.20.1/24
Tunnel1010.255.0.1/3010.255.0.2/30

ช่วง 203.0.113.0/24 และ 198.51.100.0/24 เป็น Documentation Addresses สำหรับ Lab เท่านั้น ไม่ใช่ Public IP สำหรับนำไปใช้งานจริง

3. Prerequisites และ Security Design

  • ตรวจว่า Cisco IOS XE Image/License รองรับ IKEv2, IPsec และ SVTI
  • WAN ทั้งสองฝั่งต้องเข้าถึง Public IP ของอีกฝั่งได้
  • อนุญาต UDP 500 และ UDP 4500 เมื่อใช้ NAT-T; หาก ESP ส่งตรง ต้องรองรับ IP Protocol 50
  • ใช้ IKEv2, AES-GCM และ Diffie-Hellman Group ที่เหมาะสมกับนโยบายองค์กร
  • ใน Lab ใช้ Pre-Shared Key (PSK) เพื่อให้เห็น Workflow; Production ควรพิจารณา Certificate/PKI
  • ตรวจว่าช่วง LAN ไม่ซ้ำกัน และมี Return Route จาก Hosts
ความปลอดภัย: เปลี่ยน REPLACE_WITH_STRONG_UNIQUE_PSK เป็น Secret ที่ยาว สุ่ม และไม่ใช้ซ้ำ อย่าเก็บ Secret จริงในบทความ, Git Repository หรือ Log

ลำดับการทำงาน

WAN Reachability
    -> IKEv2 SA (Peer Authentication)
    -> IPsec CHILD SA (ESP)
    -> Tunnel10
    -> Static Routes
    -> Encrypted LAN-to-LAN Traffic

4. อธิบายส่วนประกอบ IKEv2/IPsec Configuration

IKEv2 Proposal และ Policy

crypto ikev2 proposal ระบุ Encryption, PRF และ DH Group ส่วน crypto ikev2 policy ใช้เลือก Proposal ระหว่างการเจรจา

IKEv2 Keyring และ Profile

Keyring เก็บ PSK ของ Peer; Profile กำหนดการ Match Remote Identity, Authentication และ Keyring ที่ใช้

IPsec Transform-Set และ Profile

Transform-Set กำหนด ESP Protection; IPsec Profile ผูก Transform-Set และ IKEv2 Profile เพื่อใช้กับ VTI

ทำไมเลือก AES-GCM?

AES-GCM เป็น Authenticated Encryption (AEAD) จึงไม่ต้องกำหนด HMAC แยกสำหรับ ESP Transform-Set ที่ใช้ GCM การรองรับ AES-256-GCM และ DH Group 14 ในตัวอย่างนี้ต้องตรวจตามอุปกรณ์; Production อาจเลือก Group ที่แข็งแรงกว่าตามความสามารถและนโยบาย

5. Full Configuration — HQ-R1

คำสั่งต่อไปนี้เป็น Lab Baseline สำหรับ Router ที่รองรับ Syntax ดังกล่าว โดยสมมติว่า Interface ยังไม่ถูกใช้งานกับ Configuration อื่น

configure terminal
hostname HQ-R1
!
interface GigabitEthernet0/0
 description WAN-TO-ISP
 ip address 203.0.113.10 255.255.255.252
 no shutdown
!
interface GigabitEthernet0/1
 description HQ-LAN
 ip address 192.168.10.1 255.255.255.0
 no shutdown
!
ip route 0.0.0.0 0.0.0.0 203.0.113.9
!
crypto ikev2 proposal IKEV2-PROP
 encryption aes-gcm-256
 prf sha256
 group 14
!
crypto ikev2 policy IKEV2-POL
 proposal IKEV2-PROP
!
crypto ikev2 keyring VPN-KEYRING
 peer BR-R2
  address 198.51.100.10
  pre-shared-key local REPLACE_WITH_STRONG_UNIQUE_PSK
  pre-shared-key remote REPLACE_WITH_STRONG_UNIQUE_PSK
!
crypto ikev2 profile IKEV2-BR
 match identity remote address 198.51.100.10 255.255.255.255
 identity local address 203.0.113.10
 authentication remote pre-share
 authentication local pre-share
 keyring local VPN-KEYRING
!
crypto ipsec transform-set ESP-GCM esp-gcm 256
 mode tunnel
!
crypto ipsec profile IPSEC-BR
 set transform-set ESP-GCM
 set ikev2-profile IKEV2-BR
!
interface Tunnel10
 description IPSEC-VTI-TO-BRANCH
 ip address 10.255.0.1 255.255.255.252
 tunnel source GigabitEthernet0/0
 tunnel mode ipsec ipv4
 tunnel destination 198.51.100.10
 tunnel protection ipsec profile IPSEC-BR
 no shutdown
!
ip route 192.168.20.0 255.255.255.0 Tunnel10
end

สิ่งที่ต้องตรวจ: WAN Route ต้องนำ Traffic ไปหา Peer ผ่าน ISP ไม่ใช่ย้อนเข้า Tunnel และ Static Route ไป Branch LAN ต้องชี้ที่ Tunnel10

6. Full Configuration — BR-R2

configure terminal
hostname BR-R2
!
interface GigabitEthernet0/0
 description WAN-TO-ISP
 ip address 198.51.100.10 255.255.255.252
 no shutdown
!
interface GigabitEthernet0/1
 description BRANCH-LAN
 ip address 192.168.20.1 255.255.255.0
 no shutdown
!
ip route 0.0.0.0 0.0.0.0 198.51.100.9
!
crypto ikev2 proposal IKEV2-PROP
 encryption aes-gcm-256
 prf sha256
 group 14
!
crypto ikev2 policy IKEV2-POL
 proposal IKEV2-PROP
!
crypto ikev2 keyring VPN-KEYRING
 peer HQ-R1
  address 203.0.113.10
  pre-shared-key local REPLACE_WITH_STRONG_UNIQUE_PSK
  pre-shared-key remote REPLACE_WITH_STRONG_UNIQUE_PSK
!
crypto ikev2 profile IKEV2-HQ
 match identity remote address 203.0.113.10 255.255.255.255
 identity local address 198.51.100.10
 authentication remote pre-share
 authentication local pre-share
 keyring local VPN-KEYRING
!
crypto ipsec transform-set ESP-GCM esp-gcm 256
 mode tunnel
!
crypto ipsec profile IPSEC-HQ
 set transform-set ESP-GCM
 set ikev2-profile IKEV2-HQ
!
interface Tunnel10
 description IPSEC-VTI-TO-HQ
 ip address 10.255.0.2 255.255.255.252
 tunnel source GigabitEthernet0/0
 tunnel mode ipsec ipv4
 tunnel destination 203.0.113.10
 tunnel protection ipsec profile IPSEC-HQ
 no shutdown
!
ip route 192.168.10.0 255.255.255.0 Tunnel10
end
หมายเหตุ: PSK ฝั่ง Local/Remote ในตัวอย่างใช้ค่าเดียวกันทั้งสองด้าน และต้องแทนที่ด้วย Secret จริงก่อนทดสอบ การใช้ Secret ต่างกันตามทิศทางต้องจับคู่ให้ตรงกันระหว่าง Peers

7. Verification — ตรวจว่า VPN ใช้งานได้จริง

Step 1: ตรวจ WAN Reachability

HQ-R1# ping 198.51.100.10 source 203.0.113.10
BR-R2# ping 203.0.113.10 source 198.51.100.10

การ Ping ไม่สำเร็จไม่ได้พิสูจน์ว่า Peer ใช้งานไม่ได้เสมอไป เพราะ Firewall อาจ Block ICMP ให้ตรวจ Underlay Route และ UDP Connectivity เพิ่มเติม

Step 2: ตรวจ IKEv2 SA

show crypto ikev2 sa
show crypto ikev2 sa detailed

ตรวจ Peer Address, State, Authentication และ Negotiated Parameters ตาม Output ที่ Platform รองรับ

Step 3: ตรวจ IPsec SA

show crypto ipsec sa

ตรวจ encaps/encrypt และ decaps/decrypt Counters ก่อนและหลังสร้าง Traffic

Step 4: ตรวจ Tunnel และ Route

show interfaces Tunnel10
show ip route 192.168.20.0
show ip route 192.168.10.0

ใช้คำสั่ง Route ให้ตรงกับฝั่งที่ตรวจ เช่น HQ ตรวจ Route ไป Branch และ Branch ตรวจ Route ไป HQ

Step 5: สร้าง Traffic ผ่าน VPN

HQ-R1# ping 192.168.20.1 source 192.168.10.1
BR-R2# ping 192.168.10.1 source 192.168.20.1

จากนั้นตรวจ show crypto ipsec sa อีกครั้ง หาก Counter เพิ่มในทิศทางที่เหมาะสม แสดงว่า Traffic กำลังใช้ IPsec Data Plane

Acceptance Criteria: IKEv2 SA พร้อมใช้งาน, IPsec SA สร้างสำเร็จ, Route ถูกต้อง, ทดสอบ LAN-to-LAN ผ่าน และ Counters เพิ่มทั้งสองทิศทางโดยไม่มี Error/Drop ผิดปกติ

8. Troubleshooting: VPN Tunnel ไม่ขึ้นหรือส่งข้อมูลไม่ได้

Underlay Reachable?
       |
       v
UDP 500/4500 or ESP Allowed?
       |
       v
IKEv2 SA Established?
       |
       v
Authentication / Proposal Match?
       |
       v
IPsec CHILD SA Present?
       |
       v
Tunnel10 and Routing Correct?
       |
       v
Firewall / NAT / Return Path?
       |
       v
MTU / MSS / Application Test

Case 1 — IKEv2 SA ไม่ขึ้น

ตรวจ WAN IP, Peer Address, IKE Proposal, PRF, DH Group, PSK, Identity Match, NAT และ Firewall Rules

Case 2 — IKEv2 SA ขึ้น แต่ IPsec SA ไม่สมบูรณ์

ตรวจ ESP Transform-Set, IPsec Profile, CHILD SA Negotiation, PFS Policy และความเข้ากันได้ของ Security Parameters

Case 3 — Tunnel Up แต่ Ping ไม่ผ่าน

ตรวจ Static Route, Source IP, LAN Firewall, NAT และ Return Route หากทดสอบจาก PC ต้องตรวจ Default Gateway ของ PC ด้วย

Case 4 — Encrypt Counter เพิ่ม แต่ Decrypt ไม่เพิ่ม

ตรวจ Remote Peer ว่ารับ ESP/NAT-T ได้หรือไม่, Remote Security Policy, Return Route และ Counters ที่อีกฝั่ง

Case 5 — Traffic ผ่านได้เฉพาะ Packet ขนาดเล็ก

ตรวจ MTU, TCP MSS, Fragmentation และ PMTUD เพราะ IPsec เพิ่ม Encapsulation Overhead และอาจทำให้ Packet ใหญ่เกิน Path MTU

Case 6 — VPN หลุดเป็นระยะ

ตรวจ ISP Packet Loss, IKE Rekey, Dead Peer Detection, NAT Timeouts, CPU และ Log โดยใช้ Monitoring ต่อเนื่อง

Production Caution: อย่าเปิด Debug แบบกว้างโดยไม่จำกัดเวลาและขอบเขต เพราะอาจกระทบ CPU หรือเปิดเผยข้อมูล Security Negotiation ต้องเตรียม Rollback และ Change Window ก่อนแก้ไข

9. Production Hardening และ Design Checklist

  • Identity: พิจารณา Certificate/PKI แทน PSK เมื่อมีหลาย Sites และต้องการบริหาร Credential เป็นระบบ
  • Cryptography: เลือก Encryption/PRF/DH/PFS ตาม Security Standard และ Feature Support; Group 14 ใน Lab ไม่ใช่คำแนะนำสูงสุดสำหรับทุก Production
  • Firewall: จำกัด VPN Peer Addresses และเปิดเฉพาะ Protocol ที่จำเป็น
  • Segmentation: อนุญาต LAN-to-LAN เฉพาะ Application/Ports ที่มี Business Need
  • Routing: ป้องกัน Recursive Routing และตรวจ Return Path
  • NAT: ตรวจ NAT Exemption หรือ NAT Policy ตาม Traffic Flow และ Platform
  • Monitoring: ติดตาม Tunnel Availability, SA Rekey, Packet Drops และ Unexpected Peers
  • Resilience: วางแผน Dual ISP/Redundant VPN Gateway และทดสอบ Failover
  • Change Control: เก็บ Backup Configuration โดยไม่เผยแพร่ Secret และมีขั้นตอน Rollback

ทำไมไม่ควรใช้ PSK เดียวกันกับทุกสาขา?

หาก Secret ของสาขาหนึ่งรั่วไหล อาจกระทบหลาย Tunnel การใช้ Credential แยก Peer และการจัดการ Key Lifecycle จะลด Blast Radius ได้

ทำไม VTI เหมาะกับการขยายระบบ?

VTI สามารถใช้ Routing และ Interface-Based Policy ได้สะดวกกว่า Crypto ACL ในหลาย Use Cases แต่ต้องตรวจข้อจำกัดเรื่อง Routing Protocol, QoS, VRF และ Hardware Offload ของ Platform จริง

10. คำถามที่พบบ่อย

Route-Based VPN กับ Policy-Based VPN ต่างกันอย่างไร?

Route-Based ใช้ Routing/Virtual Tunnel Interface เป็นหลัก ส่วน Policy-Based ใช้ Traffic Selectors หรือ Crypto ACL เพื่อเลือก Traffic ที่ปกป้อง ทั้งสองแบบมี Use Case และข้อจำกัดต่างกัน

ต้องใช้ GRE ร่วมกับ IPsec VTI หรือไม่?

ไม่จำเป็น สำหรับการเชื่อมต่อ IP แบบ Point-to-Point ที่ VTI รองรับ GRE อาจจำเป็นในบาง Design ที่ต้องการคุณสมบัติ Encapsulation เพิ่มเติม

ทำไมใช้ UDP 500 และ 4500?

UDP 500 ใช้กับ IKE และ UDP 4500 ใช้กับ NAT Traversal สำหรับ IKE/ESP Encapsulation ตามสถานการณ์

VPN Up หมายความว่าข้อมูลเข้ารหัสแล้วหรือไม่?

ต้องตรวจ IPsec SA และ Encrypt/Decrypt Counters พร้อมทดสอบ Traffic จริง เพราะสถานะ Tunnel เพียงอย่างเดียวไม่เพียงพอ

สามารถใช้ OSPF ผ่าน VTI ได้หรือไม่?

ได้ใน Platform และ Design ที่รองรับ แต่ต้องกำหนด OSPF Adjacency, Authentication, MTU และ Route Filtering ให้เหมาะสม

ต้องใช้ Public IP จริงหรือไม่?

Production ต้องมี Underlay Reachability ระหว่าง Peers ผ่าน Public Network หรือ NAT/Private WAN ตาม Architecture ตัวอย่าง IP ในบทนี้สงวนไว้สำหรับ Documentation

11. บทสรุป

Site-to-Site IPsec VPN บน Cisco ด้วย IKEv2 และ VTI ช่วยสร้าง Secure Connectivity ระหว่างสำนักงานใหญ่กับสาขา โดยแบ่งการทำงานเป็น Underlay, IKEv2 Control Plane, IPsec Data Plane, Tunnel Interface และ Routing

Underlay Connectivity
        |
        v
IKEv2 Authentication
        |
        v
IPsec ESP Protection
        |
        v
Tunnel10 (VTI)
        |
        v
Static Routing
        |
        v
Verified LAN-to-LAN Traffic

หัวใจของการทำงานระดับ Network Engineer คือ Configure ให้ถูกต้อง, Verify ด้วย SA และ Packet Counters, ทดสอบ End-to-End และ Troubleshoot ตาม Layer ไม่ใช่ดูเพียงข้อความ Tunnel Up

บทความถัดไป: GRE Tunnel และ GRE over IPsec บน Cisco: Encapsulation, Routing, Configuration และ Troubleshooting

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.