🎯 Mục Tiêu Lab
Tạo VNet với GatewaySubnet chuyên dụng — bắt buộc cho VPN Gateway
Triển khai VPN Gateway SKU VpnGw2AZ hỗ trợ Availability Zone
Cấu hình Point-to-Site với tunnel OpenVPN (SSL) và auth Microsoft Entra ID
Download VPN client profile và cài Azure VPN Client trên máy tính
Đăng nhập bằng tài khoản Entra ID để kết nối VPN và test ping VM trong VNet
Hiểu cấu trúc: VNet, GatewaySubnet, Public IP (Zone-redundant), VPN Gateway
📋 Chuẩn Bị
- Azure subscription với Microsoft Entra ID tenant
- Quyền Global Administrator hoặc Application Administrator trên Entra ID
- Máy tính Windows 10/11 hoặc macOS để cài Azure VPN Client
- Azure CLI đã đăng nhập, Tenant ID của mình
- VPN Gateway tạo mất 25–45 phút — hãy kiên nhẫn
- P2S address pool phải khác address space VNet
- Chi phí VpnGw2AZ ~$0.40/giờ — xóa ngay sau lab
VpnGw2AZ — SKU hỗ trợ Availability Zone, phù hợp production. Tránh dùng VpnGw1 (không hỗ trợ AZ) hoặc Basic SKU (deprecated). Public IP phải dùng Standard SKU + Zone-redundant.
🏗️ Kịch Bản & Tài Nguyên
Nhân viên làm việc từ xa cần truy cập vào VM nội bộ trong Azure VNet qua VPN bảo mật. Thay vì quản lý certificate phức tạp, dùng Microsoft Entra ID authentication — nhân viên đăng nhập bằng tài khoản công ty (Entra ID) để xác thực VPN. Tunnel type: OpenVPN (SSL) — hoạt động qua port 443, vượt qua được nhiều firewall doanh nghiệp.
10.10.0.0/16
Southeast Asia
(dành riêng)
không deploy VM
Route-based
Gen2
OpenVPN (SSL)
Entra ID Auth
🧪 Các Bước Thực Hiện
Tạo VNet, GatewaySubnet và VM Test
GatewaySubnet là subnet đặc biệt — tên phải là chính xác GatewaySubnet, không đặt NSG hoặc UDR vào subnet này. Khuyến nghị /27 hoặc lớn hơn.
- 1.1Tạo RG
rg-lab07-vpn-p2s, region: Southeast Asia - 1.2Tạo VNet
cloud-vnet, address: 10.10.0.0/16, thêm subnet subnet-cloud: 10.10.0.0/24 - 1.3Vào cloud-vnet → Subnets → + Gateway Subnet → address: 10.10.255.0/27 (Azure tự đặt tên GatewaySubnet)
- 1.4Tạo VM
cloud-vm: Windows Server 2022, B2s, Subnet: subnet-cloud, không cần Public IP
RG="rg-lab07-vpn-p2s"
az group create --name $RG --location southeastasia
# VNet + subnet-cloud
az network vnet create \
--resource-group $RG \
--name cloud-vnet \
--address-prefix 10.10.0.0/16 \
--subnet-name subnet-cloud \
--subnet-prefix 10.10.0.0/24 \
--location southeastasia
# GatewaySubnet (tên bắt buộc là GatewaySubnet)
az network vnet subnet create \
--resource-group $RG \
--vnet-name cloud-vnet \
--name GatewaySubnet \
--address-prefix 10.10.255.0/27
# VM test (Windows Server 2022, không có Public IP)
az vm create \
--resource-group $RG \
--name cloud-vm \
--image Win2022Datacenter \
--size Standard_B2s \
--vnet-name cloud-vnet \
--subnet subnet-cloud \
--public-ip-address "" \
--admin-username AdminCloud \
--admin-password "P@ssw0rd2026!Lab"
# Ghi lại private IP của cloud-vm
az vm show -g $RG -n cloud-vm \
-d --query privateIps -o tsv
Tạo Public IP và VPN Gateway
VPN Gateway cần Public IP Standard với Zone-redundant allocation. Gateway tạo xong mất 25–45 phút — có thể làm bước 3 trong khi chờ.
- 2.1Portal → Virtual Network Gateways → + Create
- 2.2Name:
vpn-gateway-lab07, Gateway type: VPN, VPN type: Route-based - 2.3SKU: VpnGw2AZ, Generation: Generation2, VNet: cloud-vnet
- 2.4Public IP: tạo mới
pip-vpn-lab07, SKU: Standard, Availability zone: Zone-redundant - 2.5Review + Create → chờ 25–45 phút
RG="rg-lab07-vpn-p2s"
# Public IP Standard Zone-redundant cho VPN Gateway
az network public-ip create \
--resource-group $RG \
--name pip-vpn-lab07 \
--sku Standard \
--allocation-method Static \
--zone 1 2 3 \
--location southeastasia
# Tạo VPN Gateway VpnGw2AZ (chờ 25-45 phút)
az network vnet-gateway create \
--resource-group $RG \
--name vpn-gateway-lab07 \
--vnet cloud-vnet \
--gateway-type Vpn \
--vpn-type RouteBased \
--sku VpnGw2AZ \
--generation Generation2 \
--public-ip-addresses pip-vpn-lab07 \
--location southeastasia \
--no-wait
echo "Gateway đang tạo... kiểm tra sau 30 phút"
# Kiểm tra trạng thái (chạy sau 30 phút)
az network vnet-gateway show \
--resource-group $RG \
--name vpn-gateway-lab07 \
--query "provisioningState" -o tsv
Lấy Tenant ID từ Microsoft Entra ID
P2S configuration với Entra ID auth cần 3 giá trị: Tenant URL, Audience (Application ID cố định của Azure VPN), và Issuer URL. Chỉ cần thay {TenantID} bằng Tenant ID thực của bạn.
- 3.1Portal → Microsoft Entra ID → Overview → ghi lại Tenant ID (dạng GUID)
- 3.2Ví dụ Tenant ID:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - 3.3Audience (Application ID của Azure VPN App — cố định không đổi):
41b23e61-6c1e-4545-b367-cd054e0ed4b4
# Lấy Tenant ID
TENANT_ID=$(az account show \
--query tenantId -o tsv)
echo "Tenant ID: $TENANT_ID"
# Các giá trị P2S Entra ID auth (thay TENANT_ID)
echo "Tenant URL:"
echo "https://login.microsoftonline.com/$TENANT_ID"
echo "Audience (App ID cố định - không thay):"
echo "41b23e61-6c1e-4545-b367-cd054e0ed4b4"
echo "Issuer:"
echo "https://sts.windows.net/$TENANT_ID/"
Cấu Hình Point-to-Site trên VPN Gateway
Sau khi Gateway ở trạng thái Succeeded, cấu hình P2S: address pool cho VPN clients, tunnel type OpenVPN, và thông tin Entra ID auth.
- 4.1Portal → vpn-gateway-lab07 → Point-to-site configuration → Configure now
- 4.2Address pool:
172.16.0.0/16(pool IP cấp cho VPN clients) - 4.3Tunnel type: OpenVPN (SSL)
- 4.4Authentication type: Azure Active Directory (Microsoft Entra ID)
- 4.5Tenant:
https://login.microsoftonline.com/{TenantID} - 4.6Audience:
41b23e61-6c1e-4545-b367-cd054e0ed4b4 - 4.7Issuer:
https://sts.windows.net/{TenantID}/ - 4.8Save → sau đó click Download VPN client → lưu file .zip
RG="rg-lab07-vpn-p2s"
TENANT_ID=$(az account show --query tenantId -o tsv)
# Cấu hình P2S với Entra ID auth
az network vnet-gateway update \
--resource-group $RG \
--name vpn-gateway-lab07 \
--client-protocol OpenVPN \
--address-prefixes 172.16.0.0/16 \
--aad-tenant "https://login.microsoftonline.com/$TENANT_ID" \
--aad-audience "41b23e61-6c1e-4545-b367-cd054e0ed4b4" \
--aad-issuer "https://sts.windows.net/$TENANT_ID/"
# Download VPN client profile package
az network vnet-gateway vpn-client generate \
--resource-group $RG \
--name vpn-gateway-lab07 \
--processor-architecture Amd64 \
--output tsv
# Lệnh trả về URL download file .zip — tải về và giải nén
<AzureVPN>
<ClientAuth>
<AuthType>AAD</AuthType>
<AAD>
<AadTenant>https://login.microsoftonline.com/{TenantID}</AadTenant>
<AadAudience>41b23e61-6c1e-4545-b367-...</AadAudience>
<AadIssuer>https://sts.windows.net/{TenantID}/</AadIssuer>
</AAD>
</ClientAuth>
</AzureVPN>
Cài Azure VPN Client và Kết Nối
- 5.1Windows: cài Azure VPN Client từ Microsoft Store (tìm "Azure VPN Client")
- 5.2Giải nén file .zip vừa download → tìm file
AzureVPN\azurevpnconfig.xml - 5.3Azure VPN Client → + → Import → chọn file azurevpnconfig.xml → Save
- 5.4Click Connect → trình duyệt mở → đăng nhập tài khoản Microsoft Entra ID của bạn
- 5.5Sau kết nối → mở CMD:
ping 10.10.0.4(private IP cloud-vm) → thành công
# Kiểm tra IP được cấp bởi VPN (phải thuộc 172.16.0.0/16)
ipconfig /all | findstr "172.16"
# Xem route table — phải có route tới 10.10.0.0/16
route print | findstr "10.10"
# Ping private IP của cloud-vm (thay bằng IP thực)
ping 10.10.0.4
# Nếu muốn RDP vào cloud-vm qua VPN:
mstsc /v:10.10.0.4
Pinging 10.10.0.4 with 32 bytes of data:
Reply from 10.10.0.4: bytes=32 time=18ms TTL=127
Reply from 10.10.0.4: bytes=32 time=17ms TTL=127
Ping statistics for 10.10.0.4:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
📊 Kết Quả Đầu Ra Lab 07
provisioningState: Succeeded, Zone-redundant Public IP Standard
Tunnel: OpenVPN, Auth: AAD, Address pool: 172.16.0.0/16
Azure VPN Client import azurevpnconfig.xml, đăng nhập Entra ID thành công
Từ máy tính cá nhân ping được private IP 10.10.0.4, latency ~15-25ms
🧹 Dọn Dẹp Tài Nguyên
az group delete \
--name rg-lab07-vpn-p2s \
--yes \
--no-wait
# Ngắt kết nối VPN Client trên máy tính trước khi xóa Gateway
❓ Câu Hỏi Ôn Tập
1. GatewaySubnet có những đặc điểm gì? Tại sao không được gắn NSG hoặc UDR vào GatewaySubnet?
Gợi ý: Tên phải là "GatewaySubnet", Azure tự quản lý các NIC trong subnet này. NSG có thể block traffic VPN Gateway gây mất kết nối. Khuyến nghị /27 hoặc lớn hơn.
2. Tại sao nên dùng VpnGw2AZ thay vì VpnGw1 hoặc Basic SKU cho môi trường production?
Gợi ý: AZ = Availability Zone — gateway được deploy trên nhiều zone, tránh single point of failure. Basic SKU không hỗ trợ Entra ID auth và đã deprecated.
3. So sánh 3 phương thức authentication cho VPN Point-to-Site: Certificate, RADIUS, và Microsoft Entra ID?
Gợi ý: Certificate — không cần username/password, phù hợp automated. RADIUS — tích hợp với NPS, AD on-prem. Entra ID — SSO, MFA, Conditional Access, phù hợp cloud-native nhất.
4. P2S address pool (172.16.0.0/16) và VNet address space (10.10.0.0/16) cần thỏa mãn điều kiện gì?
Gợi ý: Không được chồng lấp nhau. Pool IP cấp cho VPN clients phải khác hoàn toàn với VNet space và on-prem space nếu có.
5. OpenVPN (SSL) khác gì với IKEv2 trong P2S VPN? Khi nào nên chọn mỗi loại?
Gợi ý: OpenVPN dùng port 443 TCP/UDP — vượt qua firewall dễ hơn, hỗ trợ Entra ID auth, cross-platform. IKEv2 — nhanh hơn, native trên Windows/macOS/iOS, dùng certificate auth.