LAB 08 ~3 giờ Module 5 VPN S2S · RRAS · IKEv2

VPN Site-to-Site — Azure + On-Premises RRAS

Giả lập kết nối hybrid cloud: Azure VNet đóng vai cloud site, một VM Windows Server 2022 + RRAS đóng vai on-premises site. Hai site kết nối qua VPN S2S với IKEv2 và pre-shared key — mô phỏng thực tế doanh nghiệp muốn extend mạng nội bộ lên Azure.

🎯 Mục Tiêu Lab

Xây dựng Azure side: VNet, GatewaySubnet, VPN Gateway VpnGw2AZ, Cloud VM

Xây dựng On-prem side: VM Windows Server 2022 với Public IP, cài RRAS làm VPN router

Tạo Local Network Gateway — đại diện cho on-premises trong Azure

Tạo VPN Connection IKEv2 với pre-shared key giữa Azure Gateway và RRAS

Cấu hình RRAS demand-dial interface và static routes trên Windows Server

Xác nhận kết nối: RDP từ on-prem VM sang Cloud VM bằng private IP

📋 Chuẩn Bị

Yêu cầu:
  • Hoàn thành Lab 07 (hiểu VPN Gateway, GatewaySubnet)
  • Azure CLI đã đăng nhập
  • Quota 2 VM (1 Windows Server B2s cho RRAS, 1 Windows Server B2s cho cloud)
Kiến trúc lab:
  • Cloud (Southeast Asia): 10.10.0.0/16 + VPN Gateway
  • On-prem sim (East Asia): 192.168.1.0/24 + RRAS VM
  • VPN Gateway tạo mất 25–45 phút, dự trù tổng ~3 giờ
Mô phỏng on-premises với Azure VM: Trong thực tế, on-premises là datacenter vật lý với router/firewall (Cisco, Fortinet...) hoặc Windows Server RRAS. Lab này dùng Azure VM Windows Server 2022 tại East Asia giả lập on-prem VPN device — cách tiếp cận tiết kiệm, dễ kiểm soát, đúng về cấu hình RRAS.
Basic Public IP đã bị retired 30/09/2025. Mọi Public IP trong lab này dùng --sku Standard. RRAS VM cần IP forwarding enabled trên NIC để làm router.

🏗️ Kịch Bản & Tài Nguyên

Azure Cloud Side (Southeast Asia)
RG: rg-lab08-cloud
VNet: cloud-vnet / 10.10.0.0/16
subnet-cloud: 10.10.0.0/24
GatewaySubnet: 10.10.255.0/27
VPN Gateway: vpn-gw-lab08 (VpnGw2AZ)
VM: cloud-vm (Windows Server 2022, no PIP)
Local Network GW: lng-onprem (rep on-prem)
On-Premises Simulation (East Asia)
RG: rg-lab08-onprem
VNet: onprem-vnet / 192.168.1.0/24
subnet-onprem: 192.168.1.0/25
VM: onprem-rras-vm (Win Server 2022)
Public IP: pip-rras (Standard, Static)
Role: Remote Access + Routing (RRAS)
IP Forwarding: Enabled trên NIC

🧪 Các Bước Thực Hiện

1

Xây Dựng Azure Cloud Side — VNet, Gateway, Cloud VM

Cách 1 — Azure Portal
  1. 1.1Tạo RG rg-lab08-cloud tại Southeast Asia
  2. 1.2VNet cloud-vnet: 10.10.0.0/16, subnet-cloud: 10.10.0.0/24, GatewaySubnet: 10.10.255.0/27
  3. 1.3Tạo VM cloud-vm: Windows Server 2022, B2s, subnet-cloud, không có Public IP
  4. 1.4Public IP Standard: pip-vpn-gw-lab08, Zone-redundant
  5. 1.5VPN Gateway: vpn-gw-lab08, SKU VpnGw2AZ, Route-based, Gen2 → Create (chờ 30 phút)
Cách 2 — Azure CLI
Azure CLI
RG_CLOUD="rg-lab08-cloud"
az group create --name $RG_CLOUD --location southeastasia

# VNet + subnets
az network vnet create \
  --resource-group $RG_CLOUD --name cloud-vnet \
  --address-prefix 10.10.0.0/16 \
  --subnet-name subnet-cloud \
  --subnet-prefix 10.10.0.0/24 \
  --location southeastasia

az network vnet subnet create \
  --resource-group $RG_CLOUD --vnet-name cloud-vnet \
  --name GatewaySubnet --address-prefix 10.10.255.0/27

# Cloud VM (no Public IP)
az vm create \
  --resource-group $RG_CLOUD --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"

# Public IP Zone-redundant cho VPN Gateway
az network public-ip create \
  --resource-group $RG_CLOUD --name pip-vpn-gw-lab08 \
  --sku Standard --allocation-method Static \
  --zone 1 2 3 --location southeastasia

# Tạo VPN Gateway VpnGw2AZ (--no-wait để không bị timeout)
az network vnet-gateway create \
  --resource-group $RG_CLOUD --name vpn-gw-lab08 \
  --vnet cloud-vnet --gateway-type Vpn \
  --vpn-type RouteBased --sku VpnGw2AZ \
  --generation Generation2 \
  --public-ip-addresses pip-vpn-gw-lab08 \
  --location southeastasia --no-wait

echo "VPN Gateway đang tạo — tiếp tục Bước 2 trong lúc chờ"
2

Xây Dựng On-Premises Side — VM Windows Server + RRAS

VM này đóng vai thiết bị VPN on-premises (như router/firewall). Cần Public IP để Azure VPN Gateway kết nối tới, và phải bật IP Forwarding trên NIC để VM hoạt động như router chuyển tiếp gói tin.

Cách 1 — Azure Portal
  1. 2.1Tạo RG rg-lab08-onprem tại East Asia
  2. 2.2VNet onprem-vnet: 192.168.1.0/24, subnet-onprem: 192.168.1.0/25
  3. 2.3Tạo VM onprem-rras-vm: Windows Server 2022, B2s, subnet-onprem, Public IP Standard: pip-rras
  4. 2.4NSG của onprem-rras-vm: Allow IKE UDP 500, NAT-T UDP 4500 inbound (cần cho VPN IKEv2)
  5. 2.5NIC của onprem-rras-vm → IP configurations → bật IP forwarding: Enabled
  6. 2.6Ghi lại Public IP của pip-rras — sẽ dùng trong Bước 3 (Local Network Gateway)
Cách 2 — Azure CLI
Azure CLI
RG_ONPREM="rg-lab08-onprem"
az group create --name $RG_ONPREM --location eastasia

# VNet on-prem simulation
az network vnet create \
  --resource-group $RG_ONPREM --name onprem-vnet \
  --address-prefix 192.168.1.0/24 \
  --subnet-name subnet-onprem \
  --subnet-prefix 192.168.1.0/25 \
  --location eastasia

# Public IP Standard cho RRAS VM
az network public-ip create \
  --resource-group $RG_ONPREM --name pip-rras \
  --sku Standard --allocation-method Static \
  --location eastasia

# NSG cho RRAS: allow IKE và NAT-T
az network nsg create \
  --resource-group $RG_ONPREM --name nsg-rras

az network nsg rule create \
  --resource-group $RG_ONPREM --nsg-name nsg-rras \
  --name Allow-IKE --priority 100 \
  --protocol Udp --destination-port-ranges 500 \
  --access Allow --direction Inbound

az network nsg rule create \
  --resource-group $RG_ONPREM --nsg-name nsg-rras \
  --name Allow-NATT --priority 110 \
  --protocol Udp --destination-port-ranges 4500 \
  --access Allow --direction Inbound

az network nsg rule create \
  --resource-group $RG_ONPREM --nsg-name nsg-rras \
  --name Allow-RDP --priority 120 \
  --protocol Tcp --destination-port-ranges 3389 \
  --access Allow --direction Inbound

# NIC với IP forwarding enabled
az network nic create \
  --resource-group $RG_ONPREM --name nic-rras \
  --vnet-name onprem-vnet --subnet subnet-onprem \
  --public-ip-address pip-rras \
  --network-security-group nsg-rras \
  --ip-forwarding true

# Tạo RRAS VM
az vm create \
  --resource-group $RG_ONPREM --name onprem-rras-vm \
  --nics nic-rras \
  --image Win2022Datacenter --size Standard_B2s \
  --admin-username AdminOnPrem \
  --admin-password "P@ssw0rd2026!Lab"

# Lấy Public IP của pip-rras
RRAS_PIP=$(az network public-ip show \
  -g $RG_ONPREM -n pip-rras \
  --query ipAddress -o tsv)
echo "RRAS Public IP: $RRAS_PIP"
3

Tạo Local Network Gateway và VPN Connection

Local Network Gateway (LNG) là đối tượng trong Azure đại diện cho VPN device on-premises — chứa Public IP của RRAS và address space của mạng on-prem. Sau khi tạo LNG, tạo Connection nối VPN Gateway với LNG bằng IKEv2 và shared key.

Cách 1 — Azure Portal
  1. 3.1Portal → Local Network Gateways → + Create → RG: rg-lab08-cloud
  2. 3.2Name: lng-onprem, IP: Public IP của pip-rras, Address space: 192.168.1.0/24
  3. 3.3Portal → vpn-gw-lab08 → Connections → + Add
  4. 3.4Name: conn-azure-to-onprem, Connection type: Site-to-Site (IPsec)
  5. 3.5Local network gateway: lng-onprem, Shared key (PSK): AzureLabPSK2026!
  6. 3.6IKE Protocol: IKEv2 → OK → chờ Connection chuyển sang Connected (sau khi RRAS được cấu hình)
Cách 2 — Azure CLI
Azure CLI
RG_CLOUD="rg-lab08-cloud"

# Lấy Public IP của RRAS (chạy lệnh này hoặc dùng giá trị đã ghi)
RRAS_PIP=$(az network public-ip show \
  -g rg-lab08-onprem -n pip-rras \
  --query ipAddress -o tsv)

# Tạo Local Network Gateway (đại diện cho on-prem trong Azure)
az network local-gateway create \
  --resource-group $RG_CLOUD \
  --name lng-onprem \
  --gateway-ip-address $RRAS_PIP \
  --local-address-prefixes 192.168.1.0/24 \
  --location southeastasia

# Tạo VPN Connection S2S với IKEv2
az network vpn-connection create \
  --resource-group $RG_CLOUD \
  --name conn-azure-to-onprem \
  --vnet-gateway1 vpn-gw-lab08 \
  --local-gateway2 lng-onprem \
  --connection-type IPsec \
  --shared-key "AzureLabPSK2026!" \
  --connection-protocol IKEv2 \
  --location southeastasia

# Kiểm tra trạng thái connection (sẽ Unknown cho đến khi RRAS cấu hình xong)
az network vpn-connection show \
  --resource-group $RG_CLOUD \
  --name conn-azure-to-onprem \
  --query "connectionStatus" -o tsv
4

Cấu Hình RRAS trên Windows Server 2022

RDP vào onprem-rras-vm qua Public IP. Cài Remote Access role với Routing service, cấu hình demand-dial interface kết nối tới Azure VPN Gateway, và thêm static route tới VNet cloud.

Lấy Public IP Azure VPN Gateway: Cần IP này để cấu hình RRAS destination.
Azure CLI — lấy Public IP của VPN Gateway
# Lấy Public IP của Azure VPN Gateway
az network public-ip show \
  -g rg-lab08-cloud -n pip-vpn-gw-lab08 \
  --query ipAddress -o tsv
Cách 1 — Azure Portal (RDP vào RRAS VM)
  1. 4.1RDP vào onprem-rras-vm bằng Public IP của pip-rras, user: AdminOnPrem
  2. 4.2Server Manager → Add Roles → Remote Access → DirectAccess and VPN (RAS) + Routing → Install
  3. 4.3Sau cài xong: Tools → Routing and Remote Access → chuột phải server → Configure and Enable Routing and Remote Access
  4. 4.4Wizard: chọn Custom configuration → tích VPN accessLAN routing → Finish → Start service
  5. 4.5Network Interfaces → New Demand-dial Interface → Name: AzureVPN → VPN → IKEv2 → Destination: Public IP của Azure VPN Gateway
  6. 4.6Credentials: Preshared key = AzureLabPSK2026! (phải khớp với Azure Connection)
  7. 4.7Static Routes → Add route tới mạng Azure: Destination 10.10.0.0, Mask 255.255.0.0, Interface: AzureVPN, Metric: 1
  8. 4.8Chuột phải AzureVPN interface → Connect → chờ Status chuyển thành Connected
PowerShell-CMD (Windows) — chạy trong onprem-rras-vm (Administrator)
# Cài Remote Access role với Routing (chạy trong onprem-rras-vm)
Install-WindowsFeature RemoteAccess -IncludeManagementTools
Install-WindowsFeature RSAT-RemoteAccess-PowerShell
Install-WindowsFeature Routing -IncludeManagementTools

# Kích hoạt Remote Access và LAN Routing
Install-RemoteAccess -VpnType VpnS2S

# Thay AZURE_GW_IP bằng Public IP thực của Azure VPN Gateway
$AzureGWIP = "AZURE_GW_IP"
$PSK = "AzureLabPSK2026!"

# Thêm S2S VPN interface kết nối tới Azure
Add-VpnS2SInterface `
  -Name "AzureVPN" `
  -Destination $AzureGWIP `
  -Protocol IKEv2 `
  -AuthenticationMethod PSKOnly `
  -SharedSecret $PSK `
  -IPv4Subnet @("10.10.0.0/16:100")

# Kết nối tunnel
Connect-VpnS2SInterface -Name "AzureVPN"

# Kiểm tra trạng thái interface
Get-VpnS2SInterface -Name "AzureVPN" | `
  Select-Object Name, ConnectionState, Destination

# Thêm static route tới Azure VNet
New-NetRoute `
  -DestinationPrefix "10.10.0.0/16" `
  -InterfaceAlias "AzureVPN" `
  -RouteMetric 1
Kết quả (Output) — Get-VpnS2SInterface sau kết nối
Name       ConnectionState  Destination
----       ---------------  -----------
AzureVPN   Connected        20.x.x.x
5

Xác Nhận Kết Nối S2S End-to-End

Cách 1 — Azure Portal
  1. 5.1Portal → vpn-gw-lab08 → Connections → conn-azure-to-onprem → Status phải là Connected
  2. 5.2Network Watcher → Connection Troubleshoot → Source: cloud-vm, Dest: 192.168.1.4 (RRAS VM private IP), Port 3389 → Reachable
  3. 5.3Từ onprem-rras-vm: mở CMD → ping 10.10.0.4 (cloud-vm private IP) → phải reply
  4. 5.4Thử RDP từ onprem-rras-vm tới cloud-vm: mstsc /v:10.10.0.4 → đăng nhập thành công
Cách 2 — Azure CLI
Azure CLI
RG_CLOUD="rg-lab08-cloud"

# Kiểm tra trạng thái VPN Connection
az network vpn-connection show \
  --resource-group $RG_CLOUD \
  --name conn-azure-to-onprem \
  --query "{status:connectionStatus,ingress:ingressBytesTransferred,egress:egressBytesTransferred}" \
  --output json

# Xem thống kê traffic
az network vpn-connection list \
  --resource-group $RG_CLOUD \
  --output table

# Connection Troubleshoot từ cloud-vm tới RRAS VM private IP
az network watcher test-connectivity \
  --resource-group $RG_CLOUD \
  --source-resource cloud-vm \
  --dest-address 192.168.1.4 \
  --dest-port 3389
Kết quả (Output) — connection status
{
  "status": "Connected",
  "ingress": 12456,
  "egress": 8932
}
PowerShell-CMD (Windows) — test từ onprem-rras-vm
# Chạy trong onprem-rras-vm (sau khi RRAS Connected)

# Ping cloud-vm qua tunnel VPN S2S
ping 10.10.0.4

# Xem route table — phải có 10.10.0.0/16 qua AzureVPN interface
route print | findstr "10.10"

# RDP tới cloud-vm qua private IP (xác nhận kết nối hybrid)
mstsc /v:10.10.0.4

# Test ngược: tracert để xem traffic đi qua tunnel
tracert 10.10.0.4

📊 Kết Quả Đầu Ra Lab 08

VPN Connection: Connected

conn-azure-to-onprem status = Connected, ingress/egress bytes > 0

RRAS interface AzureVPN Connected

Get-VpnS2SInterface trả về ConnectionState = Connected

Ping cross-site thành công

onprem-rras-vm ping 10.10.0.4 (cloud-vm) — reply nhận được qua encrypted tunnel

RDP cross-site hoạt động

mstsc /v:10.10.0.4 từ on-prem VM → login cloud-vm bằng private IP qua VPN tunnel

🧹 Dọn Dẹp Tài Nguyên

Chi phí: VpnGw2AZ ~$0.40/giờ + 2 VM Windows Server B2s ~$0.10/giờ mỗi VM. Xóa ngay sau lab để tránh phát sinh chi phí.
Azure CLI
# Xóa cả 2 resource groups
az group delete --name rg-lab08-cloud --yes --no-wait
az group delete --name rg-lab08-onprem --yes --no-wait

# Xác nhận xóa (sau vài phút)
az group exists --name rg-lab08-cloud
az group exists --name rg-lab08-onprem

❓ Câu Hỏi Ôn Tập

1. Local Network Gateway đại diện cho điều gì trong kiến trúc VPN S2S? Thông tin gì cần điền vào LNG?

Gợi ý: LNG đại diện cho VPN device on-premises trong Azure. Cần: Public IP của VPN device on-prem và address space của mạng on-prem (để Azure biết route traffic nào qua tunnel).

2. Tại sao phải bật "IP Forwarding" trên NIC của RRAS VM? Điều gì xảy ra nếu không bật?

Gợi ý: IP Forwarding cho phép VM nhận packet không phải địa chỉ của chính nó và forward tiếp. Không bật → VM drop tất cả packet routing giữa subnet on-prem và Azure — tunnel kết nối nhưng traffic không đi qua được.

3. IKEv2 cần các port UDP nào? Tại sao phải mở port 500 và 4500 trong NSG của RRAS VM?

Gợi ý: UDP 500 cho IKE (Internet Key Exchange) — đàm phán SA (Security Association). UDP 4500 cho NAT-T (NAT Traversal) — dùng khi có NAT giữa 2 endpoint. Cả 2 đều bắt buộc cho IKEv2.

4. So sánh VPN Site-to-Site với Azure ExpressRoute về bảo mật, băng thông, latency, và use case?

Gợi ý: VPN S2S — internet-based, encrypted, setup nhanh, giới hạn ~10 Gbps, latency phụ thuộc internet. ExpressRoute — private circuit (không qua internet), không encrypt (nhưng private), băng thông đến 100 Gbps, SLA 99.95%, phù hợp tài chính/healthcare.

5. Trong kịch bản thực tế, thay thế RRAS VM bằng thiết bị nào? Azure hỗ trợ những VPN device vendor nào?

Gợi ý: Cisco ASA/IOS, Fortinet FortiGate, Palo Alto, Juniper SRX, pfSense, Check Point, v.v. Microsoft duy trì danh sách VPN devices đã được validated tại docs.microsoft.com. Yêu cầu: hỗ trợ IKEv1 hoặc IKEv2, BGP optional.

Lab 07: VPN Point-to-Site Thư viện Labs Lab 09: Azure Backup
Zalo