Giao thức: L2TP (Layer 2 Tunneling Protocol)
L2TP (Layer 2 Tunneling Protocol) là giao thức an ninh mạng **dựa trên PPP để xác thực** và **được thiết kế chuyên biệt để tunneling (đường hầm) lưu lượng PPP** qua mạng IP (Internet, LAN, WAN).
Cơ chế hoạt động của L2TP
- Encapsulation (Đóng gói): L2TP gói tin PPP (IP, IPX, AppleTalk...) vào frame L2TP → Gói tin L2TP được đóng gói vào **UDP port 1701** → Đóng gói vào IP packet để truyền qua mạng IP.
- Tunnel & Session: Thiết lập **L2TP Tunnel** (Control Connection) giữa LAC (L2TP Access Concentrator) và LNS (L2TP Network Server). Bên trong Tunnel có nhiều **L2TP Sessions** (mỗi Session = 1 PPP connection).
- PPP inside L2TP: Toàn bộ quá trình PPP (LCP, Authentication - PAP/CHAP/EAP, NCP/IPCP) diễn ra **bên trong** L2TP Tunnel. L2TP **không tự làm xác thực**, nó **chuyển tunneling (proxy) các gói PPP Authentication** giữa Client (hoặc LAC) và LNS.
- L2TP bản thân KHÔNG MÃ HÓA. Nó chỉ tunneling. Dữ liệu PPP (kể cả credential PAP/CHAP) đi trong cleartext trong L2TP/UDP/IP.
- IPsec (ESP - Encapsulating Security Payload) cung cấp: **Confidentiality (AES-GCM/ChaCha20-Poly1305), Integrity, Authentication, Anti-replay** cho toàn bộ gói L2TP/UDP/IP.
- Cấu trúc: **PPP → L2TP → IPsec ESP → IP (Tunnel Mode hoặc Transport Mode)**.
- Xác thực IPsec: **IKEv1 (Main/Aggressive Mode) với Pre-Shared Key (PSK) hoặc Certificate (RSA/ECDSA)**. IKEv2 tốt hơn (MOBIKE, ít message hơn).
- PAP (Password Authentication Protocol): Cleartext username/password. **Cấm dùng**.
- CHAP (Challenge-Handshake Authentication Protocol): Challenge-Response (MD5). Yếu hơn EAP. Dùng 1 chiều.
- MS-CHAPv2: Microsoft CHAP v2. Mutual Auth. Yếu (có thể crack offline). Dùng trong VPN Windows cũ.
- EAP (Extensible Authentication Protocol) - Khuyên dùng: Framework hỗ trợ nhiều method:
- EAP-TLS: Certificate-based (Client + Server Cert). **Mạnh nhất**. Cần PKI.
- EAP-PEAP (PEAP-MSCHAPv2 / PEAP-EAP-TLS): Tunnel TLS bảo vệ EAP bên trong. Phổ biến Enterprise (Windows NPS, Cisco ISE, Aruba ClearPass, FreeRADIUS).
- EAP-TTLS: Tương tự PEAP, hỗ trợ nhiều inner method hơn (PAP, CHAP, MS-CHAPv2, EAP-GTC).
- EAP-FAST: Cisco. PAC (Protected Access Credential) thay Cert. Nhanh hơn PEAP.
- Cài Role: **Remote Access** → **DirectAccess and VPN (RAS)** → **Routing**.
- Configure: **VPN** → **Custom Configuration** → **VPN Access** → **L2TP**.
- IPsec: **Properties → Security → IPsec Settings** → **Use pre-shared key for authentication** (nhập PSK mạnh) hoặc **Certificate**.
- IPv4: **Static Address Pool** (cho client VPN).
- Authentication: **Network Policy Server (NPS / RADIUS)** → Policy: **EAP-TLS / PEAP-MSCHAPv2**.
- Firewall: Mở UDP 500, 4500, ESP (Protocol 50).
- L2TP là câu trả lời chính xác: Giao thức **tunneling PPP** qua IP, **sử dụng PPP để xác thực** (PAP/CHAP/EAP bên trong tunnel).
- **BẮT BUỘC** dùng với **IPsec (L2TP/IPsec)** để mã hóa. Không bao giờ dùng L2TP đơn lẻ.
- Hiện nay **WireGuard, IKEv2/IPsec, SSL VPN (OpenVPN)** ưu tiên hơn do hiệu năng, đơn giản, bảo mật tốt hơn, NAT traversal tốt hơn.
- PPP Authentication (PAP/CHAP/EAP) vẫn cốt lõi trong VPN, Wi-Fi Enterprise (802.1X), Dial-up, DSL (PPPoE).
Tại sao L2TP thường đi kèm IPsec (L2TP/IPsec)?
So sánh: PPTP vs L2TP/IPsec vs SSL VPN vs WireGuard
| Giao thức | Cơ sở | Mã hóa | Xác thực PPP | Port | NAT Traversal | Hiệu năng | Trạng thái |
|---|---|---|---|---|---|---|---|
| PPTP | PPP + GRE (47) | MPPE (RC4 - Yếu, Broken) | PAP/CHAP/MS-CHAPv2 (Yếu) | TCP 1723 + GRE | Kém (GRE không qua NAT tốt) | Cao (nhưng không an toàn) | Deprecated / Cấm dùng |
| L2TP/IPsec | PPP + L2TP + IPsec ESP | AES-GCM/ChaCha20-Poly1305 (Mạnh) | PAP/CHAP/EAP (Trong Tunnel IPsec) | UDP 500/4500 (IKE) + ESP (50) | Tốt (NAT-T - UDP Encapsulation) | Trung bình (Double Encapsulation Overhead) | Vẫn dùng (Legacy, Native OS Support) |
| SSL VPN (OpenVPN, AnyConnect, Pulse/Secure) | TLS/SSL over TCP/UDP | AES-GCM/ChaCha20-Poly1305 | Cert/Username+Pass/Token (TLS Auth) | TCP 443 / UDP 1194 | Rất tốt (HTTPS-like) | Tốt | Phổ biến Enterprise/Remote Access |
| WireGuard | Modern Kernel Module (Layer 3) | ChaCha20-Poly1305, Curve25519, BLAKE2s, HKDF | Static Public Key (No PPP) | UDP (Configurable) | Tuyệt vời (Roaming, NAT) | Cao nhất (Kernel space, Crypto hiện đại) | Tiêu chuẩn mới (Linux Kernel 5.6+, Cross-platform) |
PPP Authentication Protocols (Trong L2TP/IPsec)
Triển khai L2TP/IPsec trên Windows Server (RRAS) / Linux (xl2tpd + strongSwan/Libreswan)
Windows Server (Routing and Remote Access Service - RRAS)
Linux (strongSwan + xl2tpd)
/etc/ipsec.conf (strongSwan):
conn l2tp-ipsec
keyexchange=ikev1/ikev2
ike=aes256-sha256-modp2048,aes128-sha256-modp2048!
esp=aes256gcm16-ecp384,aes128gcm16-ecp256!
left=%defaultroute
leftid=@vpn.example.com
leftsubnet=0.0.0.0/0
leftauth=psk / pubkey
leftfirewall=yes
right=%any
rightauth=psk / eap-mschapv2 / eap-tls
rightsourceip=10.10.10.0/24
rightdns=1.1.1.1,8.8.8.8
auto=add
/etc/xl2tpd/xl2tpd.conf:
[global]
ipsec saref = yes
listen-addr = 0.0.0.0
[lns default]
ip range = 10.10.10.10-10.10.10.250
local ip = 10.10.10.1
require chap = yes
refuse pap = yes
require authentication = yes
name = L2TPServer
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
/etc/ppp/options.xl2tpd:
ipcp-accept-local
ipcp-accept-remote
ms-dns 1.1.1.1
ms-dns 8.8.8.8
noccp
auth
mtu 1410
mru 1410
lcp-echo-interval 30
lcp-echo-failure 4
nodefaultroute
lock
proxyarp
connect-delay 5000