VPN & TunnelingVPN & Tunneling
Thuộc bộ kiến thức Network Engineer Roadmap.
Tổng quan
Một tunnel là kỹ thuật mang một network protocol này làm payload của một protocol khác. Packet gốc — với header và data riêng của nó — được bọc lại (“encapsulation”) bên trong một packet mới, gửi qua một mạng trung gian, rồi được gỡ ra (“decapsulation”) ở đầu bên kia. Với hai đầu cuối, tunnel trông như một hop logic duy nhất dù thực tế có rất nhiều hop vật lý nằm giữa. Cách hình dung kinh điển là một lá thư (inner packet) niêm phong trong một phong bì chuyển phát (outer packet): hệ thống bưu chính chỉ đọc phong bì bên ngoài; lá thư bên trong được giao nguyên vẹn.
Một VPN (Virtual Private Network) là một tunnel có thêm bảo mật — confidentiality (encryption), integrity (phát hiện giả mạo), và authentication (chứng minh danh tính các peer) — nhờ đó một mạng public không tin cậy như Internet có thể được dùng như thể nó là một đường private. Không phải tunnel nào cũng là VPN (một GRE tunnel thuần chỉ encapsulate chứ không encrypt), và không phải VPN nào cũng dùng một encapsulation header riêng, nhưng trong thực tế hai khái niệm này thường đi cùng nhau.
Tunnel và VPN tồn tại để giải quyết ba (bốn) vấn đề lặp đi lặp lại:
- Privacy trên mạng public — một nhân viên làm việc từ xa qua Wi-Fi quán cà phê sẽ encrypt toàn bộ traffic để không ai trên segment cục bộ hay dọc đường truyền có thể đọc hoặc sửa đổi.
- Kết nối các site — hai văn phòng ở hai thành phố khác nhau hoạt động như một mạng private duy nhất qua Internet, mà không phải thuê một private circuit đắt đỏ.
- Remote access — một laptop hay điện thoại cá nhân truy cập vào mạng công ty hoặc cloud từ bất cứ đâu, như thể đang cắm trực tiếp vào LAN.
- Vận chuyển các protocol mà mạng bên dưới không mang được natively — ví dụ mang một routing protocol, multicast, hay một protocol không phải IP qua một backbone chỉ có IP, hoặc mang IPv6 qua một đường chỉ có IPv4.
Note này trình bày cơ chế của tunneling và các công nghệ VPN chính mà một network engineer sẽ gặp: IPsec, SSL/TLS VPN, GRE, MPLS L3VPN, SD-WAN, cloud VPN, và các protocol hiện đại như WireGuard và OpenVPN. Về bối cảnh bảo mật rộng hơn, xem ./11-network-security.md; về routing qua tunnel, xem ./07-routing.md; về kết nối tới các cloud provider, xem ./16-cloud-networking.md.
Kiến thức nền tảng
Encapsulation: một protocol nằm trong một protocol khác
Encapsulation là trái tim của mọi tunnel. Khi một packet đi vào tunnel, tunneling protocol thêm header vào đầu (và đôi khi vào cuối), tạo ra các lớp lồng nhau:
Packet gốc:
[ IP header | TCP/UDP | application data ]
Sau khi tunneling (ví dụ GRE over IP):
[ Outer IP | GRE | IP header | TCP/UDP | application data ]
^ header giao vận ^ packet gốc, giờ là payload
Sau IPsec ESP tunnel mode:
[ Outer IP | ESP hdr | (đã encrypt){ IP header | TCP/UDP | data } | ESP trailer | ESP auth ]
Việc bọc packet trong header phụ dẫn tới hai hệ quả:
- Overhead — mỗi header thêm vào tiêu tốn thêm byte. GRE thêm 24 byte, IPsec ESP thêm khoảng 50–60 byte tùy cipher. Payload dùng được (MTU) của tunnel bị thu hẹp tương ứng.
- Vấn đề fragmentation / MTU — nếu packet kết quả vượt quá path MTU (thường là 1500 byte trên Ethernet), nó phải bị fragment hoặc bị drop. Đây là nguyên nhân phổ biến nhất của lỗi “tunnel thì up nhưng truyền file lớn thì treo”, và thường được khắc phục bằng cách giảm MTU của tunnel hoặc clamp TCP MSS (ví dụ
ip tcp adjust-mss 1360).
Vị trí của tunnel trong stack
| Tunnel / VPN | Encapsulate ở | Có encrypt? | Dùng điển hình |
|---|---|---|---|
| GRE | Layer 3 (kiểu IP-in-IP) | Không | Mang routing/multicast, nối các mạng |
| IPsec | Layer 3 (IP) | Có | Site-to-site, remote access an toàn |
| SSL/TLS VPN | Layer 4+ (trên TCP/UDP) | Có | Remote access, xuyên firewall tốt |
| WireGuard | Layer 3 (trên UDP) | Có | Site-to-site & remote access hiện đại |
| MPLS L3VPN | Label switching L3 của provider | Không (tin cậy provider) | WAN của nhà mạng giữa các site |
| VXLAN | Layer 2 trên UDP | Không (thường vậy) | Overlay trong data-center |
Tunnel endpoint và khái niệm overlay
Một tunnel được xác định bởi hai endpoint (các thiết bị encapsulate và decapsulate). Mạng mà tunnel chạy trên đó gọi là underlay; mạng ảo hình thành bởi các tunnel gọi là overlay. Sự tách biệt overlay/underlay này là nền tảng của SD-WAN, data-center fabric (VXLAN), và cloud networking: overlay có thể có addressing và routing riêng, hoàn toàn độc lập với transport vật lý bên dưới.
Khái niệm chính
IPsec
IPsec là một bộ chuẩn mở (RFC 4301 là kiến trúc) bảo vệ IP traffic ở Layer 3. Vì hoạt động ở lớp IP, nó bảo vệ mọi thứ nằm trên nó (TCP, UDP, và tất cả application) một cách trong suốt — application không cần thay đổi gì. Đây là “con ngựa thồ” của các site-to-site VPN.
IPsec có hai security protocol và hai mode, cùng với một protocol trao đổi khóa (IKE) để thiết lập mọi thứ.
AH vs ESP
| AH (Authentication Header) | ESP (Encapsulating Security Payload) | |
|---|---|---|
| RFC | 4302 | 4303 |
| Confidentiality (encryption) | Không | Có |
| Integrity & authentication | Có | Có |
| Bảo vệ outer IP header | Có (một phần) | Không (chỉ phần payload nó bọc) |
| Hoạt động qua NAT | Không (hỏng vì nó cover IP header) | Có (với NAT-Traversal / UDP 4500) |
| Trên thực tế | Hiếm khi dùng ngày nay | Lựa chọn mặc định, dùng gần như ở mọi nơi |
AH cung cấp integrity và authentication nhưng không encryption, và vì nó authenticate một phần outer IP header nên bị NAT làm hỏng. ESP cung cấp cả encryption lẫn integrity và sống sót qua NAT nhờ NAT-T. Trong triển khai hiện đại bạn gần như luôn dùng ESP; AH về cơ bản là legacy.
Transport mode vs tunnel mode
- Transport mode — chỉ payload của IP packet gốc được bảo vệ; IP header gốc được giữ nguyên. Dùng host-to-host (ví dụ hai server nói chuyện trực tiếp, hoặc để bảo vệ một GRE tunnel giữa hai router).
- Tunnel mode — toàn bộ IP packet gốc được encapsulate bên trong một IP packet mới với outer header mới. Điều này che giấu source/destination gốc và là mode mà các site-to-site gateway dùng, vì endpoint làm encryption (các gateway) khác với endpoint của traffic (các host phía sau chúng).
Transport mode: [ IP gốc | ESP | (encrypt) TCP+data | ESP trl/auth ]
Tunnel mode: [ IP MỚI | ESP | (encrypt){ IP gốc | TCP+data } | ESP trl/auth ]
IKE, IKEv2, các phase, và Security Association
Trước khi bất kỳ data nào được bảo vệ, hai peer phải thống nhất về khóa và tham số. Việc này do IKE (Internet Key Exchange) đảm nhiệm, ngày nay gần như luôn là IKEv2 (RFC 7296), vốn đơn giản hơn, nhanh hơn và bền bỉ hơn IKEv1.
Một Security Association (SA) là một thỏa thuận một chiều mô tả cách traffic được bảo vệ: protocol (ESP), cipher và hash, khóa, và một Security Parameter Index (SPI) để nhận diện nó. Vì SA là một chiều, một tunnel hai chiều bình thường có ít nhất hai IPsec SA.
Quá trình đàm phán IKE diễn ra theo hai phase:
| Phase | Tên IKEv1 | Exchange IKEv2 | Làm gì |
|---|---|---|---|
| Phase 1 | Main/Aggressive Mode | IKE_SA_INIT + IKE_AUTH | Authenticate các peer, thiết lập kênh điều khiển an toàn (IKE SA) qua Diffie-Hellman |
| Phase 2 | Quick Mode | CREATE_CHILD_SA | Đàm phán các IPsec (ESP) SA thực sự bảo vệ data — các “child SA” |
Phase 1 dựng nên một kênh an toàn, đã được authenticate (dùng pre-shared key hoặc certificate). Phase 2 dùng kênh đó để đàm phán các khóa ESP nhanh, theo từng luồng traffic. Khóa được rekey định kỳ theo lifetime (giây) hoặc theo dung lượng (byte) để một khóa bị lộ chỉ bảo vệ một khoảng nhỏ; dùng một Diffie-Hellman exchange mới khi rekey sẽ đem lại Perfect Forward Secrecy (PFS).
Một cấu hình site-to-site IPsec điển hình (Cisco IOS, IKEv2)
! Phase 1 (IKEv2 proposal + policy)
crypto ikev2 proposal PROP
encryption aes-cbc-256
integrity sha256
group 14
crypto ikev2 policy POL
proposal PROP
crypto ikev2 keyring KR
peer BRANCH
address 203.0.113.2
pre-shared-key MySecretKey123
crypto ikev2 profile PROF
match identity remote address 203.0.113.2 255.255.255.255
authentication local pre-share
authentication remote pre-share
keyring local KR
! Phase 2 (ESP transform set) + policy về những gì cần bảo vệ
crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
mode tunnel
crypto ipsec profile IPSEC-PROF
set transform-set TS
set ikev2-profile PROF
! Gắn vào một tunnel interface (kiểu VTI)
interface Tunnel0
ip address 10.255.255.1 255.255.255.252
tunnel source GigabitEthernet0/0
tunnel destination 203.0.113.2
tunnel mode ipsec ipv4
tunnel protection ipsec profile IPSEC-PROF
Lệnh kiểm tra hữu ích: show crypto ikev2 sa (Phase 1 đã up chưa?), show crypto ipsec sa (Phase 2, có packet được encrypt/decrypt không?).
SSL/TLS VPN
Một SSL/TLS VPN bảo vệ remote access bằng chính protocol TLS vốn dùng để bảo vệ HTTPS. Vì TLS chạy trên TCP (thường là port 443) hoặc DTLS trên UDP, một SSL VPN xuyên qua firewall, proxy và NAT gần như không cần cấu hình đặc biệt — bất cứ nơi nào cho phép lướt web thì cho phép VPN. Đây là ưu thế thực tế lớn nhất của nó so với IPsec, vốn cần UDP 500/4500 và ESP được cho phép end-to-end.
Hai dạng phổ biến:
- Clientless (portal) SSL VPN — người dùng đăng nhập vào một web portal trong một browser bình thường và truy cập các web app nội bộ, file share, hoặc phiên RDP/SSH được proxy qua gateway. Không cần cài phần mềm; giới hạn ở những gì portal expose.
- Full-tunnel client SSL VPN — một client nhẹ (ví dụ Cisco AnyConnect/Secure Client, OpenVPN, GlobalProtect) tạo một virtual network adapter và route traffic qua tunnel, cho phép truy cập đầy đủ ở network layer như IPsec nhưng trên TLS/DTLS.
IPsec VPN vs SSL VPN
| Khía cạnh | IPsec VPN | SSL/TLS VPN |
|---|---|---|
| Lớp OSI | Network (Layer 3) | Transport/Session (Layer 4+) |
| Port/protocol điển hình | UDP 500 & 4500, ESP (proto 50) | TCP 443 / DTLS UDP 443 |
| Thân thiện với firewall/NAT | Có thể bị chặn; cần NAT-T | Xuất sắc — trông như HTTPS |
| Phần mềm client | Client hoặc hỗ trợ native của OS | Browser (clientless) hoặc client nhẹ |
| Độ chi tiết | Truy cập toàn mạng | Cấp app (portal) hoặc toàn mạng |
| Phù hợp nhất cho | Site-to-site; network access luôn bật | Người dùng remote, BYOD, mạng bị hạn chế |
| Hiệu năng | Rất hiệu quả, ở kernel-level | Có chút overhead TCP-over-TCP (mode TCP) |
Quy tắc ngón tay cái: dùng IPsec cho site-to-site và các thiết bị được quản lý, kiểm soát; dùng SSL VPN cho người dùng remote, thiết bị unmanaged/BYOD, và bất cứ nơi nào firewall khắt khe khiến IPsec khó triển khai.
VPN topology
Site-to-site vs remote-access
- Site-to-site — hai (hoặc nhiều) gateway dựng một tunnel thường trực; mọi host phía sau mỗi gateway truy cập site kia một cách trong suốt. Người dùng không bao giờ phải chạy phần mềm VPN. Gần như luôn là IPsec tunnel mode (hoặc GRE-over-IPsec, hoặc overlay của SD-WAN).
- Remote-access — một endpoint cá nhân (laptop, điện thoại) dựng một tunnel tới một VPN concentrator để vào mạng công ty/cloud. Thường là SSL VPN hoặc IKEv2/IPsec client, hoặc WireGuard.
Hub-and-spoke vs full mesh
- Hub-and-spoke — mỗi chi nhánh (spoke) tunnel về một site trung tâm (hub); traffic spoke-to-spoke đi qua hub. Đơn giản để cấu hình và quản lý (N tunnel cho N spoke) nhưng hub là điểm nghẽn và làm tăng latency cho traffic spoke-to-spoke.
- Full mesh — mỗi site tunnel trực tiếp tới mọi site khác (N×(N−1)/2 tunnel). Hiệu năng tốt nhất, không bị hairpin, nhưng cấu hình và quản lý khóa bùng nổ khi N tăng.
- DMVPN (Dynamic Multipoint VPN) — một thiết kế của Cisco giữ control plane kiểu hub-and-spoke nhưng cho phép các spoke dựng tunnel trực tiếp theo yêu cầu tới nhau (qua NHRP + mGRE + IPsec), đạt được hiệu năng của mesh với khả năng quản lý của hub-and-spoke. SD-WAN tổng quát hóa ý tưởng này.
Full tunnel vs split tunneling
| Full tunnel | Split tunneling | |
|---|---|---|
| Cái gì đi qua VPN | Toàn bộ traffic, kể cả duyệt Internet | Chỉ các subnet công ty/được định nghĩa; Internet đi thẳng |
| Bảo mật/khả năng quan sát | Tối đa — mọi traffic được kiểm soát của công ty inspect | Ít hơn — traffic Internet trực tiếp bỏ qua inspection của công ty |
| Hiệu năng / băng thông | Backhaul mọi thứ về HQ (có thể chậm, dùng băng thông HQ) | Hiệu quả; latency thấp tới Internet/SaaS |
| Dùng điển hình | Môi trường bảo mật cao, tuân thủ | Người dùng bị giới hạn băng thông, dùng nhiều SaaS/O365 |
Split tunneling giảm tải và cải thiện trải nghiệm người dùng nhưng mở rộng attack surface (một laptop bị compromise có một chân trên mạng công ty và một chân trên Internet mở). Nhiều tổ chức dùng phương án lai: tunnel các subnet công ty, cho phép SaaS tin cậy đi thẳng.
GRE và GRE-over-IPsec
GRE (Generic Routing Encapsulation), định nghĩa trong RFC 2784, là một tunneling protocol đơn giản, stateless, bọc gần như mọi payload Layer 3 trong một header GRE + IP. Điểm mạnh của nó: nó có thể mang multicast, broadcast, và routing protocol (OSPF, EIGRP) và cả các protocol không phải IP — những thứ mà IPsec tunnel mode thuần không mang được natively.
Điểm yếu chí mạng: GRE không cung cấp encryption, không confidentiality, và không authentication. Bất cứ ai trên đường truyền đều có thể đọc nội dung một GRE tunnel. GRE thuần ổn trên một mạng tin cậy nhưng tuyệt đối không được tin dùng để bảo vệ data qua Internet.
Giải pháp tiêu chuẩn là GRE over IPsec: dựng một GRE tunnel (để có thể chạy routing protocol và mang multicast), rồi bảo vệ GRE tunnel đó bằng IPsec (thường là transport mode, vì header GRE đã cung cấp phần tunnel encapsulation rồi). Bạn có được sự linh hoạt của GRE cùng với sự bảo mật của IPsec.
interface Tunnel0
ip address 10.0.0.1 255.255.255.252
tunnel source GigabitEthernet0/0
tunnel destination 198.51.100.2
tunnel protection ipsec profile IPSEC-PROF ! bọc GRE tunnel trong IPsec
!
router ospf 1
network 10.0.0.0 0.0.0.3 area 0 ! OSPF giờ chạy qua tunnel đã encrypt
Encapsulation kết quả: [ Outer IP | ESP | GRE | inner IP | data | ESP trl ].
MPLS VPN (L3VPN) vs Internet VPN
MPLS L3VPN là một dịch vụ do nhà mạng cung cấp: backbone MPLS của provider giữ route của mỗi khách hàng trong các VRF riêng biệt và forward traffic bằng label thay vì qua Internet public. Từ góc nhìn của khách hàng, mọi site cùng gia nhập một mạng private có định tuyến mà khách hàng không phải chạy tunnel nào.
| MPLS L3VPN | Internet VPN (IPsec/SSL) | |
|---|---|---|
| Ai vận hành | Nhà mạng | Bạn, trên bất kỳ đường Internet nào |
| Encryption | Mặc định không có (dựa vào isolation của provider) | Có (bạn kiểm soát) |
| Hiệu năng / SLA | Có thể dự đoán, QoS & SLA đảm bảo | Best-effort của Internet |
| Chi phí | Cao (dịch vụ thuê) | Thấp (dùng Internet phổ thông) |
| Tốc độ cung cấp | Nhiều tuần (lead time của nhà mạng) | Vài phút/giờ |
| Phạm vi | Giới hạn trong vùng phủ của provider | Bất cứ đâu có Internet |
MPLS cho hiệu năng và QoS có thể dự đoán nhưng đắt và chậm cung cấp; Internet VPN rẻ và triển khai nhanh nhưng chạy trên Internet best-effort. SD-WAN (bên dưới) phần lớn tồn tại để lấy được cái tốt nhất của cả hai. Chi tiết routing cho cả hai nằm ở ./07-routing.md.
SD-WAN
WAN truyền thống backhaul traffic của chi nhánh qua một MPLS circuit đắt đỏ duy nhất về một hub trung tâm, điều này tốn kém và kém hiệu quả trong thế giới cloud/SaaS nơi phần lớn traffic hướng tới Internet chứ không phải HQ. SD-WAN (Software-Defined WAN) giải quyết vấn đề này bằng cách tách WAN khỏi transport bên dưới.
Các ý tưởng cốt lõi:
- Transport independence — một chi nhánh có thể dùng bất kỳ tổ hợp đường nào (MPLS, broadband, LTE/5G) cùng lúc. SD-WAN dựng một overlay đã encrypt (IPsec/GRE tunnel) trên tất cả và coi chúng như một pool.
- Control plane / policy tập trung — một controller (và orchestrator) đẩy policy định tuyến theo application xuống tất cả các edge từ một chỗ, thay vì cấu hình tay từng router.
- Chọn đường động, nhận biết application — edge đo loss/latency/jitter theo từng đường theo thời gian thực và điều hướng mỗi application qua đường tốt nhất (ví dụ VoIP qua đường jitter thấp, backup khối lượng lớn qua broadband), với failover dưới một giây.
- Local Internet breakout — SaaS tin cậy (Office 365, Zoom) đi ra thẳng tại chi nhánh thay vì backhaul về HQ.
| WAN truyền thống / MPLS | SD-WAN | |
|---|---|---|
| Transport | Một circuit của một provider | Nhiều/bất kỳ đường (MPLS + broadband + LTE) |
| Cấu hình | CLI theo từng thiết bị | Tập trung, theo policy |
| Chọn đường | Static routing | Động, nhận biết application |
| Traffic cloud/SaaS | Backhaul về hub | Breakout tại chỗ |
| Chi phí | Cao | Thấp hơn (Internet phổ thông) |
| Failover | Chậm (routing convergence) | Dưới một giây, tự động |
SD-WAN không nhất thiết thay thế MPLS — nhiều nơi giữ MPLS cho các app quan trọng và thêm broadband cho phần còn lại, với SD-WAN kết hợp thông minh cả hai.
Cloud VPN
Kết nối một mạng on-premises tới VPC/VNet của một cloud provider là công việc hằng ngày. Có hai họ kết nối:
- VPN gateway (qua Internet) — một tunnel IPsec (thường là IKEv2) giữa thiết bị on-prem của bạn và VPN gateway được quản lý của cloud provider. Thiết lập nhanh, được encrypt, nhưng chạy trên Internet best-effort. Để đảm bảo độ bền bạn dựng redundant tunnel (hai tunnel mỗi kết nối) và thường dùng BGP trên các tunnel để failover động.
- AWS: Site-to-Site VPN (Virtual Private Gateway / Transit Gateway)
- Azure: VPN Gateway
- GCP: Cloud VPN (HA VPN cho SLA với hai tunnel)
- Private dedicated circuit (bỏ qua Internet) — một kết nối vật lý, private cho băng thông cao hơn, latency thấp/ổn định hơn, và (thường) chi phí egress thấp hơn. Mặc định không được provider encrypt, nên hãy ghép với IPsec/MACsec nếu cần.
- AWS: Direct Connect
- Azure: ExpressRoute
- GCP: Cloud Interconnect (Dedicated/Partner)
Một pattern phổ biến là dùng dedicated circuit cho phần lớn traffic với một IPsec VPN làm backup đã encrypt. Xem ./16-cloud-networking.md về thiết kế VPC, transit gateway, và cloud routing.
Các VPN protocol hiện đại: WireGuard và OpenVPN
- WireGuard — một VPN L3 hiện đại, tối giản (~4.000 dòng) chạy trên UDP, dùng một tập cryptography hiện đại cố định, có chủ đích (Curve25519, ChaCha20-Poly1305, BLAKE2s), và được tích hợp sẵn trong Linux kernel. Nó cực nhanh, dễ cấu hình (peer được nhận diện bằng public key, giống SSH), và có attack surface rất nhỏ. Nó thân thiện với roaming và ngày càng được dùng cho cả remote access lẫn site-to-site. Nhược điểm: policy/logging cấp doanh nghiệp kém chi tiết hơn các gateway IPsec/SSL thương mại (dù đã có sản phẩm xây trên nền nó).
# /etc/wireguard/wg0.conf (một peer)
[Interface]
PrivateKey = <private-key-cua-peer-nay>
Address = 10.10.0.2/24
ListenPort = 51820
[Peer]
PublicKey = <public-key-cua-peer-kia>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.10.0.0/24, 192.168.1.0/24 # route nào đi qua tunnel
PersistentKeepalive = 25 # giữ NAT mapping còn sống
- OpenVPN — một SSL/TLS VPN trưởng thành, được triển khai rộng rãi, chạy trên UDP hoặc TCP (TCP/443 để lách qua firewall khắt khe). Nó có khả năng cấu hình cao, đa nền tảng, và dùng TLS certificate để authentication. Nhiều overhead và phức tạp hơn WireGuard, nhưng đã được kiểm chứng qua thực tế và linh hoạt.
Bảng so sánh tổng hợp các loại VPN
| Loại VPN | Lớp | Encrypt | Encapsulation | Dùng chính | Ghi chú |
|---|---|---|---|---|---|
| IPsec (tunnel mode) | L3 | Có | ESP / IP mới | Site-to-site, remote access | Chuẩn, trong suốt với app, NAT qua NAT-T |
| SSL/TLS VPN (OpenVPN, AnyConnect) | L4+ | Có | TLS/DTLS trên TCP/UDP 443 | Remote access, BYOD | Thân thiện firewall, có tùy chọn clientless |
| GRE | L3 | Không | GRE / IP | Mang routing/multicast | Ghép với IPsec để bảo mật |
| GRE-over-IPsec / DMVPN | L3 | Có | GRE trong ESP | Site-to-site mesh động | Routing + encryption cùng lúc |
| WireGuard | L3 | Có | UDP | S2S & remote hiện đại | Nhanh, đơn giản, native trong kernel |
| MPLS L3VPN | L3 của provider | Không (isolation của provider) | MPLS label | WAN của nhà mạng | QoS/SLA dự đoán được, tốn kém |
| SD-WAN | Overlay (L3) | Có | Overlay IPsec/GRE | WAN nhiều site | Transport-independent, nhận biết app |
| Cloud VPN | L3 | Có | IPsec/IKEv2 | On-prem ↔ cloud VPC | Ghép với Direct Connect/ExpressRoute/Interconnect |
Best Practices
- Ưu tiên ESP với IKEv2 hơn AH và IKEv1. AH là legacy và không thân thiện với NAT; IKEv1 chậm hơn và kém bền bỉ hơn.
- Dùng crypto hiện đại, mạnh và bỏ cái cũ. Ưu tiên AES-GCM (hoặc ChaCha20-Poly1305), SHA-256 trở lên, và Diffie-Hellman group 14 trở lên (hoặc ECDH). Tắt DES/3DES, MD5, SHA-1, và DH group 1/2/5.
- Bật Perfect Forward Secrecy (PFS) để mỗi lần rekey dùng một Diffie-Hellman exchange mới; một khóa bị lộ chỉ phơi bày một khoảng thời gian ngắn.
- Authenticate bằng certificate thay vì pre-shared key khi khả thi, đặc biệt với nhiều peer hoặc người dùng remote-access; PSK không scale và dễ bị lộ.
- Lên kế hoạch MTU/MSS ngay từ đầu. Tính đến overhead của tunnel: giảm MTU của tunnel interface và clamp TCP MSS (
ip tcp adjust-mss ~1360) để tránh lỗi fragmentation kinh điển “ping nhỏ thì được, truyền lớn thì treo”. - Xây redundancy. Dùng dual tunnel / dual gateway và chạy một routing protocol (BGP là chuẩn cho cloud VPN, OSPF/EIGRP qua GRE-IPsec) để failover tự động thay vì static route.
- Quyết định split hay full tunnel một cách có chủ đích. Split tunneling cải thiện hiệu năng cho SaaS nhưng làm yếu inspection; full tunnel tối đa hóa kiểm soát nhưng tốn băng thông. Ghi lại lựa chọn theo security posture của bạn.
- Kết hợp GRE và IPsec cho đúng khi cần routing protocol hoặc multicast qua một đường đã encrypt — đừng bao giờ chạy GRE thuần qua Internet.
- Rekey và rotate. Đặt SA lifetime hợp lý (theo thời gian và dung lượng), rotate PSK/certificate, và giám sát certificate sắp hết hạn.
- Giám sát và log tunnel. Cảnh báo khi tunnel down/flap, theo dõi counter encrypt/decrypt (
show crypto ipsec sa), và bám sát lỗi đàm phán Phase 1/Phase 2 — hầu hết sự cố VPN xuất hiện ở đó đầu tiên. - Áp dụng tư duy Zero Trust. VPN cấp quyền tiếp cận mạng; hãy ghép nó với segmentation least-privilege và access nhận biết identity để một thiết bị đã kết nối không thể chạm tới mọi thứ (xem
./11-network-security.md). - Với cloud, ghép một dedicated circuit với một VPN backup khi workload xứng đáng — Direct Connect/ExpressRoute/Interconnect cho hiệu năng, IPsec VPN làm failover đã encrypt.
Tài liệu tham khảo
- RFC 4301 — Security Architecture for the Internet Protocol (IPsec)
- RFC 4303 — IP Encapsulating Security Payload (ESP)
- RFC 7296 — Internet Key Exchange Protocol Version 2 (IKEv2)
- RFC 2784 — Generic Routing Encapsulation (GRE)
- Cloudflare Learning — What is a VPN?
- Cloudflare Learning — What is SD-WAN?
- WireGuard — Official documentation
- Cisco — IPsec and IKEv2 configuration guides
Part of the Network Engineer Roadmap knowledge base.
Overview
A tunnel is a technique that carries one network protocol as the payload of another. The original packet — with its own headers and data — is wrapped (“encapsulated”) inside a new outer packet, shipped across an intermediate network, and unwrapped (“decapsulated”) at the far end. To the endpoints, the tunnel looks like a single logical hop even though many physical hops sit in between. The classic mental model is a letter (the inner packet) sealed inside a shipping envelope (the outer packet): the postal system only reads the outer envelope; the letter inside is delivered untouched.
A VPN (Virtual Private Network) is a tunnel that adds security — confidentiality (encryption), integrity (tamper detection), and authentication (proving who the peers are) — so that a public, untrusted network like the Internet can be used as if it were a private link. Not every tunnel is a VPN (a plain GRE tunnel encapsulates but does not encrypt), and not every VPN uses a separate encapsulation header, but in practice the two ideas travel together.
Tunnels and VPNs exist to solve three recurring problems:
- Privacy over a public network — a remote worker on café Wi-Fi encrypts all traffic so no one on the local segment or along the path can read or modify it.
- Connecting sites — two offices in different cities behave as one private network over the Internet, without leasing an expensive private circuit.
- Remote access — an individual laptop or phone reaches into a corporate or cloud network from anywhere, as if physically plugged into the LAN.
- Transporting protocols the underlying network cannot carry natively — e.g. carrying a routing protocol, multicast, or a non-IP protocol across an IP-only backbone, or carrying IPv6 across an IPv4-only path.
This note covers the mechanics of tunneling and the main VPN technologies a network engineer meets: IPsec, SSL/TLS VPNs, GRE, MPLS L3VPN, SD-WAN, cloud VPN, and modern protocols like WireGuard and OpenVPN. For the broader security context see ./11-network-security.md; for routing over tunnels see ./07-routing.md; for connecting to cloud providers see ./16-cloud-networking.md.
Fundamentals
Encapsulation: a protocol inside another protocol
Encapsulation is the heart of every tunnel. When a packet enters a tunnel, the tunneling protocol prepends (and sometimes appends) headers, producing nested layers:
Original packet:
[ IP header | TCP/UDP | application data ]
After tunneling (e.g. GRE over IP):
[ Outer IP | GRE | IP header | TCP/UDP | application data ]
^ delivery header ^ the original packet, now payload
After IPsec ESP tunnel mode:
[ Outer IP | ESP hdr | (encrypted){ IP header | TCP/UDP | data } | ESP trailer | ESP auth ]
Two consequences follow from wrapping a packet in extra headers:
- Overhead — each added header consumes bytes. GRE adds 24 bytes, IPsec ESP adds roughly 50–60 bytes depending on cipher. The tunnel’s usable payload (MTU) shrinks accordingly.
- Fragmentation / MTU issues — if the resulting packet exceeds the path MTU (usually 1500 bytes on Ethernet), it must be fragmented or dropped. This is the single most common source of “the tunnel is up but large transfers hang” problems, and is usually fixed by lowering the tunnel MTU or clamping TCP MSS (e.g.
ip tcp adjust-mss 1360).
Where tunnels sit in the stack
| Tunnel / VPN | Encapsulates at | Encrypts? | Typical use |
|---|---|---|---|
| GRE | Layer 3 (IP-in-IP-ish) | No | Carry routing/multicast, connect networks |
| IPsec | Layer 3 (IP) | Yes | Site-to-site, secure remote access |
| SSL/TLS VPN | Layer 4+ (over TCP/UDP) | Yes | Remote access, works through firewalls |
| WireGuard | Layer 3 (over UDP) | Yes | Modern site-to-site & remote access |
| MPLS L3VPN | Provider Layer 3 label switching | No (provider-trusted) | Carrier WAN between sites |
| VXLAN | Layer 2 over UDP | No (usually) | Data-center overlays |
Tunnel endpoints and the overlay concept
A tunnel is defined by its two endpoints (the devices that encapsulate and decapsulate). The network the tunnel rides over is the underlay; the virtual network formed by the tunnels is the overlay. This overlay/underlay separation is fundamental to SD-WAN, data-center fabrics (VXLAN), and cloud networking: the overlay can have its own addressing and routing that is completely independent of the physical transport underneath.
Key Concepts
IPsec
IPsec is a suite of open standards (RFC 4301 is the architecture) that secures IP traffic at Layer 3. Because it operates at the IP layer, it protects everything above it (TCP, UDP, and all applications) transparently — the applications need no changes. It is the workhorse of site-to-site VPNs.
IPsec has two security protocols and two modes, and it uses a key-exchange protocol (IKE) to set everything up.
AH vs ESP
| AH (Authentication Header) | ESP (Encapsulating Security Payload) | |
|---|---|---|
| RFC | 4302 | 4303 |
| Confidentiality (encryption) | No | Yes |
| Integrity & authentication | Yes | Yes |
| Protects outer IP header | Yes (parts of it) | No (only the payload it encapsulates) |
| Works through NAT | No (breaks because it covers the IP header) | Yes (with NAT-Traversal / UDP 4500) |
| In practice | Rarely used today | The default choice, used almost everywhere |
AH provides integrity and authentication but no encryption, and because it authenticates parts of the outer IP header it is broken by NAT. ESP provides encryption and integrity and survives NAT via NAT-T. In modern deployments you almost always use ESP; AH is effectively legacy.
Transport mode vs tunnel mode
- Transport mode — only the payload of the original IP packet is protected; the original IP header is kept. Used host-to-host (e.g. two servers talking directly, or securing a GRE tunnel between two routers).
- Tunnel mode — the entire original IP packet is encapsulated inside a new IP packet with a new outer header. This hides the original source/destination and is what site-to-site gateways use, because the endpoints doing encryption (the gateways) are different from the endpoints of the traffic (the hosts behind them).
Transport mode: [ orig IP | ESP | (encrypted) TCP+data | ESP trl/auth ]
Tunnel mode: [ NEW IP | ESP | (encrypted){ orig IP | TCP+data } | ESP trl/auth ]
IKE, IKEv2, phases, and Security Associations
Before any data is protected, the two peers must agree on keys and parameters. This is done by IKE (Internet Key Exchange), today almost always IKEv2 (RFC 7296), which is simpler, faster, and more robust than IKEv1.
A Security Association (SA) is a one-way agreement describing how traffic is protected: the protocol (ESP), the cipher and hash, the keys, and a Security Parameter Index (SPI) that identifies it. Because SAs are unidirectional, a normal bidirectional tunnel has at least two IPsec SAs.
IKE negotiation happens in two phases:
| Phase | IKEv1 name | IKEv2 exchange | What it does |
|---|---|---|---|
| Phase 1 | Main/Aggressive Mode | IKE_SA_INIT + IKE_AUTH | Authenticate the peers, establish a secure control channel (the IKE SA) via Diffie-Hellman |
| Phase 2 | Quick Mode | CREATE_CHILD_SA | Negotiate the IPsec (ESP) SAs that actually protect the data — the “child SAs” |
Phase 1 builds a secure, authenticated channel (using pre-shared keys or certificates). Phase 2 uses that channel to negotiate the fast, per-traffic ESP keys. Keys are periodically rekeyed based on lifetime (seconds) or volume (bytes) so a compromised key protects only a small window; using a fresh Diffie-Hellman exchange at rekey gives Perfect Forward Secrecy (PFS).
A typical site-to-site IPsec config (Cisco IOS, IKEv2)
! Phase 1 (IKEv2 proposal + policy)
crypto ikev2 proposal PROP
encryption aes-cbc-256
integrity sha256
group 14
crypto ikev2 policy POL
proposal PROP
crypto ikev2 keyring KR
peer BRANCH
address 203.0.113.2
pre-shared-key MySecretKey123
crypto ikev2 profile PROF
match identity remote address 203.0.113.2 255.255.255.255
authentication local pre-share
authentication remote pre-share
keyring local KR
! Phase 2 (ESP transform set) + policy of what to protect
crypto ipsec transform-set TS esp-aes 256 esp-sha256-hmac
mode tunnel
crypto ipsec profile IPSEC-PROF
set transform-set TS
set ikev2-profile PROF
! Bind to a tunnel interface (VTI style)
interface Tunnel0
ip address 10.255.255.1 255.255.255.252
tunnel source GigabitEthernet0/0
tunnel destination 203.0.113.2
tunnel mode ipsec ipv4
tunnel protection ipsec profile IPSEC-PROF
Useful verification: show crypto ikev2 sa (Phase 1 up?), show crypto ipsec sa (Phase 2, packets encrypted/decrypted?).
SSL/TLS VPN
An SSL/TLS VPN secures remote access using the same TLS protocol that protects HTTPS. Because TLS runs over TCP (usually port 443) or DTLS over UDP, an SSL VPN traverses firewalls, proxies, and NAT with almost no special configuration — anything that allows web browsing allows the VPN. This is its biggest practical advantage over IPsec, which needs UDP 500/4500 and ESP to be permitted end to end.
Two common flavours:
- Clientless (portal) SSL VPN — the user logs into a web portal in a normal browser and reaches specific internal web apps, file shares, or RDP/SSH sessions proxied through the gateway. No software to install; limited to what the portal exposes.
- Full-tunnel client SSL VPN — a lightweight client (e.g. Cisco AnyConnect/Secure Client, OpenVPN, GlobalProtect) creates a virtual network adapter and routes traffic through the tunnel, giving full network-layer access like IPsec but over TLS/DTLS.
IPsec VPN vs SSL VPN
| Aspect | IPsec VPN | SSL/TLS VPN |
|---|---|---|
| OSI layer | Network (Layer 3) | Transport/Session (Layer 4+) |
| Typical port/protocol | UDP 500 & 4500, ESP (proto 50) | TCP 443 / DTLS UDP 443 |
| Firewall/NAT friendliness | Can be blocked; needs NAT-T | Excellent — looks like HTTPS |
| Client software | Client or native OS support | Browser (clientless) or light client |
| Granularity | Whole-network access | App-level (portal) or full network |
| Best for | Site-to-site; always-on network access | Remote users, BYOD, restrictive networks |
| Performance | Very efficient, kernel-level | Slight TCP-over-TCP overhead (TCP mode) |
Rule of thumb: use IPsec for site-to-site and controlled, managed devices; use SSL VPN for remote users, unmanaged/BYOD devices, and anywhere restrictive firewalls make IPsec painful.
VPN topologies
Site-to-site vs remote-access
- Site-to-site — two (or more) gateways build a permanent tunnel; all hosts behind each gateway reach the other site transparently. Users never run VPN software. Almost always IPsec tunnel mode (or GRE-over-IPsec, or SD-WAN overlays).
- Remote-access — an individual endpoint (laptop, phone) builds a tunnel to a VPN concentrator to reach the corporate/cloud network. Usually SSL VPN or IKEv2/IPsec client, or WireGuard.
Hub-and-spoke vs full mesh
- Hub-and-spoke — every branch (spoke) tunnels to a central site (hub); spoke-to-spoke traffic transits the hub. Simple to configure and manage (N tunnels for N spokes) but the hub is a bottleneck and adds latency for spoke-to-spoke traffic.
- Full mesh — every site tunnels directly to every other site (N×(N−1)/2 tunnels). Best performance, no hairpinning, but configuration and key management explode as N grows.
- DMVPN (Dynamic Multipoint VPN) — a Cisco design that keeps a hub-and-spoke control plane but lets spokes build on-demand direct tunnels to each other (via NHRP + mGRE + IPsec), getting mesh performance with hub-and-spoke manageability. SD-WAN generalizes this idea.
Full tunnel vs split tunneling
| Full tunnel | Split tunneling | |
|---|---|---|
| What goes through the VPN | All traffic, including Internet browsing | Only corporate/defined subnets; Internet goes direct |
| Security/visibility | Maximum — all traffic inspected by corporate controls | Less — direct Internet traffic bypasses corporate inspection |
| Performance / bandwidth | Backhauls everything to HQ (can be slow, uses HQ bandwidth) | Efficient; low latency to Internet/SaaS |
| Typical use | High-security environments, compliance | Bandwidth-constrained users, heavy SaaS/O365 use |
Split tunneling reduces load and improves user experience but widens the attack surface (a compromised laptop has one foot on the corporate net and one on the open Internet). Many orgs use a hybrid: tunnel corporate subnets, allow trusted SaaS directly.
GRE and GRE-over-IPsec
GRE (Generic Routing Encapsulation), defined in RFC 2784, is a simple, stateless tunneling protocol that wraps almost any Layer 3 payload in a GRE + IP header. Its strengths: it can carry multicast, broadcast, and routing protocols (OSPF, EIGRP) and non-IP protocols — things plain IPsec tunnel mode cannot carry natively.
Its critical weakness: GRE provides no encryption, no confidentiality, and no authentication. Anyone on the path can read a GRE tunnel’s contents. GRE alone is fine on a trusted network but must never be trusted to protect data over the Internet.
The standard solution is GRE over IPsec: build a GRE tunnel (so you can run a routing protocol and carry multicast), then protect that GRE tunnel with IPsec (usually transport mode, since the GRE header already provides the tunnel encapsulation). You get GRE’s flexibility and IPsec’s security.
interface Tunnel0
ip address 10.0.0.1 255.255.255.252
tunnel source GigabitEthernet0/0
tunnel destination 198.51.100.2
tunnel protection ipsec profile IPSEC-PROF ! wraps the GRE tunnel in IPsec
!
router ospf 1
network 10.0.0.0 0.0.0.3 area 0 ! OSPF now runs across the encrypted tunnel
Resulting encapsulation: [ Outer IP | ESP | GRE | inner IP | data | ESP trl ].
MPLS VPN (L3VPN) vs Internet VPN
MPLS L3VPN is a service delivered by a carrier: the provider’s MPLS backbone keeps each customer’s routes in separate VRFs and forwards traffic using labels rather than the public Internet. From the customer’s view, all sites join one private routed network without the customer running any tunnels.
| MPLS L3VPN | Internet VPN (IPsec/SSL) | |
|---|---|---|
| Who operates it | The carrier | You, over any Internet link |
| Encryption | None by default (relies on provider isolation) | Yes (you control it) |
| Performance / SLA | Predictable, guaranteed QoS & SLA | Best-effort Internet |
| Cost | High (leased service) | Low (uses commodity Internet) |
| Provisioning speed | Weeks (carrier lead time) | Minutes/hours |
| Reach | Limited to provider footprint | Anywhere with Internet |
MPLS gives predictable performance and QoS but is expensive and slow to provision; Internet VPNs are cheap and fast to deploy but ride best-effort Internet. SD-WAN (below) largely exists to get the best of both. Routing details for both live in ./07-routing.md.
SD-WAN
Traditional WANs backhaul branch traffic over a single expensive MPLS circuit to a central hub, which is costly and inefficient in a cloud/SaaS world where most traffic is destined for the Internet, not HQ. SD-WAN (Software-Defined WAN) solves this by decoupling the WAN from the underlying transport.
Key ideas:
- Transport independence — a branch can use any mix of links (MPLS, broadband, LTE/5G) simultaneously. SD-WAN builds an encrypted overlay (IPsec/GRE tunnels) across all of them and treats them as a pool.
- Centralized policy / control plane — a controller (and orchestrator) pushes application-aware routing policy to all edges from one place, instead of hand-configuring each router.
- Application-aware, dynamic path selection — the edge measures loss/latency/jitter per link in real time and steers each application over the best path (e.g. VoIP over the low-jitter link, bulk backup over broadband), with sub-second failover.
- Local Internet breakout — trusted SaaS (Office 365, Zoom) exits directly at the branch instead of backhauling to HQ.
| Traditional WAN / MPLS | SD-WAN | |
|---|---|---|
| Transport | Single provider circuit | Any/multiple links (MPLS + broadband + LTE) |
| Configuration | Per-device CLI | Centralized, policy-driven |
| Path selection | Static routing | Dynamic, application-aware |
| Cloud/SaaS traffic | Backhauled to hub | Local breakout |
| Cost | High | Lower (commodity Internet) |
| Failover | Slow (routing convergence) | Sub-second, automatic |
SD-WAN doesn’t necessarily replace MPLS — many keep MPLS for critical apps and add broadband for the rest, with SD-WAN intelligently blending both.
Cloud VPN
Connecting an on-premises network to a cloud provider’s VPC/VNet is a daily task. Two families of connectivity exist:
- VPN gateway (over the Internet) — an IPsec (usually IKEv2) tunnel between your on-prem device and the cloud provider’s managed VPN gateway. Fast to set up, encrypted, but rides the best-effort Internet. For resilience you build redundant tunnels (two per connection) and often use BGP over the tunnels for dynamic failover.
- AWS: Site-to-Site VPN (Virtual Private Gateway / Transit Gateway)
- Azure: VPN Gateway
- GCP: Cloud VPN (HA VPN gives an SLA with two tunnels)
- Private dedicated circuit (bypasses the Internet) — a physical, private connection for higher bandwidth, lower/consistent latency, and (usually) lower egress cost. Not encrypted by the provider by default, so pair with IPsec/MACsec if needed.
- AWS: Direct Connect
- Azure: ExpressRoute
- GCP: Cloud Interconnect (Dedicated/Partner)
A common pattern is a dedicated circuit for the bulk of traffic with an IPsec VPN as an encrypted backup. See ./16-cloud-networking.md for VPC design, transit gateways, and cloud routing.
Modern VPN protocols: WireGuard and OpenVPN
- WireGuard — a modern, minimal (~4,000 lines) L3 VPN that runs over UDP, uses a fixed, opinionated set of modern cryptography (Curve25519, ChaCha20-Poly1305, BLAKE2s), and is built into the Linux kernel. It is extremely fast, simple to configure (peers are identified by public keys, like SSH), and has a tiny attack surface. It is roaming-friendly and increasingly used for both remote access and site-to-site. Downside: less granular enterprise policy/logging than commercial IPsec/SSL gateways (though products build on top of it).
# /etc/wireguard/wg0.conf (a peer)
[Interface]
PrivateKey = <this-peer-private-key>
Address = 10.10.0.2/24
ListenPort = 51820
[Peer]
PublicKey = <remote-peer-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.10.0.0/24, 192.168.1.0/24 # what routes through the tunnel
PersistentKeepalive = 25 # keeps NAT mappings alive
- OpenVPN — a mature, widely deployed SSL/TLS VPN that runs over UDP or TCP (TCP/443 to slip through restrictive firewalls). It is highly configurable, cross-platform, and uses TLS certificates for authentication. More overhead and complexity than WireGuard, but battle-tested and flexible.
Summary comparison of VPN types
| VPN type | Layer | Encrypted | Encapsulation | Primary use | Notes |
|---|---|---|---|---|---|
| IPsec (tunnel mode) | L3 | Yes | ESP / new IP | Site-to-site, remote access | Standard, transparent to apps, NAT via NAT-T |
| SSL/TLS VPN (OpenVPN, AnyConnect) | L4+ | Yes | TLS/DTLS over TCP/UDP 443 | Remote access, BYOD | Firewall-friendly, clientless option |
| GRE | L3 | No | GRE / IP | Carry routing/multicast | Combine with IPsec for security |
| GRE-over-IPsec / DMVPN | L3 | Yes | GRE inside ESP | Dynamic site-to-site mesh | Routing + encryption together |
| WireGuard | L3 | Yes | UDP | Modern S2S & remote | Fast, simple, kernel-native |
| MPLS L3VPN | Provider L3 | No (provider isolation) | MPLS labels | Carrier WAN | Predictable QoS/SLA, costly |
| SD-WAN | Overlay (L3) | Yes | IPsec/GRE overlay | Multi-site WAN | Transport-independent, app-aware |
| Cloud VPN | L3 | Yes | IPsec/IKEv2 | On-prem ↔ cloud VPC | Pair with Direct Connect/ExpressRoute/Interconnect |
Best Practices
- Prefer ESP with IKEv2 over AH and IKEv1. AH is legacy and NAT-hostile; IKEv1 is slower and less robust.
- Use strong, modern crypto and drop the old. Prefer AES-GCM (or ChaCha20-Poly1305), SHA-256+, and Diffie-Hellman group 14 or higher (or ECDH). Disable DES/3DES, MD5, SHA-1, and DH groups 1/2/5.
- Enable Perfect Forward Secrecy (PFS) so each rekey uses a fresh Diffie-Hellman exchange; a compromised key exposes only one short interval.
- Authenticate with certificates over pre-shared keys where feasible, especially for many peers or remote-access users; PSKs don’t scale and are easily leaked.
- Plan MTU/MSS from the start. Account for tunnel overhead: lower the tunnel interface MTU and clamp TCP MSS (
ip tcp adjust-mss ~1360) to avoid the classic “small pings work, large transfers hang” fragmentation problem. - Build redundancy. Use dual tunnels / dual gateways and run a routing protocol (BGP is standard for cloud VPNs, OSPF/EIGRP over GRE-IPsec) for automatic failover rather than static routes.
- Decide split vs full tunnel deliberately. Split tunneling improves performance for SaaS but weakens inspection; full tunnel maximizes control at a bandwidth cost. Document the choice against your security posture.
- Combine GRE and IPsec correctly when you need routing protocols or multicast across an encrypted path — never run GRE alone across the Internet.
- Rekey and rotate. Set sensible SA lifetimes (time and volume), rotate PSKs/certs, and monitor for expiring certificates.
- Monitor and log tunnels. Alert on tunnel down/flap, watch encrypt/decrypt counters (
show crypto ipsec sa), and track Phase 1/Phase 2 negotiation failures — most VPN outages show up there first. - Apply Zero Trust thinking. A VPN grants network reach; pair it with least-privilege segmentation and identity-aware access so a single connected device can’t reach everything (see
./11-network-security.md). - For cloud, pair a dedicated circuit with a VPN backup where the workload justifies it — Direct Connect/ExpressRoute/Interconnect for performance, IPsec VPN as encrypted failover.
References
- RFC 4301 — Security Architecture for the Internet Protocol (IPsec)
- RFC 4303 — IP Encapsulating Security Payload (ESP)
- RFC 7296 — Internet Key Exchange Protocol Version 2 (IKEv2)
- RFC 2784 — Generic Routing Encapsulation (GRE)
- Cloudflare Learning — What is a VPN?
- Cloudflare Learning — What is SD-WAN?
- WireGuard — Official documentation
- Cisco — IPsec and IKEv2 configuration guides