🎯 Mục Tiêu Lab
Tạo VNet với AzureFirewallSubnet (/26) và SubnetServer cho VM
Triển khai Azure Firewall Standard với Public IP (Standard SKU)
Tạo Firewall Policy và cấu hình 3 loại rule collections: DNAT, Network, Application
DNAT rule: forward RDP từ firewall public IP → VM private IP
Tạo User Defined Route (UDR) buộc mọi outbound traffic qua firewall
Xác minh Application rule: allow HTTPS đến microsoft.com, block bing.com
📋 Chuẩn Bị
- Azure subscription (Azure Firewall tốn ~$1/giờ — xóa ngay sau lab)
- Azure CLI hoặc Cloud Shell
- VM Windows Server 2022 không có public IP (truy cập qua DNAT)
- Hiểu cơ bản VNet, subnet, routing
- VNet: 10.1.0.0/16
- AzureFirewallSubnet: 10.1.1.0/26 (tên bắt buộc, minimum /26)
- SubnetServer: 10.1.2.0/24 (VM không có public IP)
- UDR: mọi traffic 0.0.0.0/0 → private IP firewall
🏗️ Kịch Bản & Tài Nguyên
HoaTranLab triển khai VM production không có public IP. Mọi traffic vào/ra đều qua Azure Firewall: RDP đến VM dùng DNAT, outbound internet qua Application rules whitelist, DNS qua Network rules.
Internet/Admin
|
| RDP :3389 → pip-fw-lab16 (public IP)
v
┌─────────────────────────────────┐
│ Azure Firewall (fw-lab16) │ AzureFirewallSubnet: 10.1.1.0/26
│ Private IP: 10.1.1.4 │
│ Public IP: pip-fw-lab16 │
│ │
│ DNAT Rule: :3389 → 10.1.2.4:3389 (RDP to VM)
│ Network Rule: DNS UDP/53 allowed (8.8.8.8)
│ App Rule: *.microsoft.com allow (HTTPS)
│ *.bing.com deny (HTTPS)
└─────────────────────────────────┘
|
| UDR: 0.0.0.0/0 → 10.1.1.4 (firewall private IP)
v
┌─────────────────────────────────┐
│ vm-lab16-server (10.1.2.4) │ SubnetServer: 10.1.2.0/24
│ Windows Server 2022 │ NO public IP
│ DNS: 8.8.8.8 │
└─────────────────────────────────┘
🧪 Các Bước Thực Hiện
Tạo VNet, Subnet & VM
- 1.1Virtual Networks → Create → Name:
vnet-fw→ 10.1.0.0/16 → Southeast Asia - 1.2Subnets → Add subnet → Name:
AzureFirewallSubnet(tên bắt buộc chính xác) → 10.1.1.0/26 - 1.3Add subnet → Name:
SubnetServer→ 10.1.2.0/24 → Review + Create - 1.4Tạo VM: Windows Server 2022 →
vm-lab16-server→ SubnetServer → No public IP → Standard_B2s - 1.5Ghi lại private IP của VM (thường 10.1.2.4) → cần cho DNAT rule
# Tạo resource group
az group create \
--name rg-lab16-firewall \
--location southeastasia
# Tạo VNet + AzureFirewallSubnet
az network vnet create \
--resource-group rg-lab16-firewall \
--name vnet-fw \
--address-prefix 10.1.0.0/16 \
--subnet-name AzureFirewallSubnet \
--subnet-prefix 10.1.1.0/26
# Tạo SubnetServer
az network vnet subnet create \
--resource-group rg-lab16-firewall \
--vnet-name vnet-fw \
--name SubnetServer \
--address-prefix 10.1.2.0/24
# Tạo VM không có public IP
az vm create \
--resource-group rg-lab16-firewall \
--name vm-lab16-server \
--image Win2022AzureEditionCore \
--size Standard_B2s \
--vnet-name vnet-fw \
--subnet SubnetServer \
--admin-username azureadmin \
--admin-password "P@ssw0rd2026!" \
--public-ip-address ""
# Lấy private IP của VM
az vm show \
--resource-group rg-lab16-firewall \
--name vm-lab16-server \
--show-details \
--query privateIps --output tsv
Triển Khai Azure Firewall & Tạo Public IP
Azure Firewall yêu cầu Standard tier Public IP. Thời gian deploy ~10 phút. Ghi lại cả private IP và public IP của firewall — cần cho UDR và DNAT.
- 2.1Public IP addresses → Create → Name:
pip-fw-lab16→ SKU: Standard → Static → Southeast Asia - 2.2Search "Firewalls" → Create → Name:
fw-lab16→ Tier: Standard → Firewall management: Use Firewall rules (classic) - 2.3VNet: vnet-fw → Public IP: pip-fw-lab16 → Review + Create → chờ deploy (~10 phút)
- 2.4Sau deploy → vào fw-lab16 → ghi: Private IP (thường 10.1.1.4) và Public IP
# Tạo Standard Public IP (bắt buộc cho Azure Firewall)
az network public-ip create \
--resource-group rg-lab16-firewall \
--name pip-fw-lab16 \
--sku Standard \
--allocation-method Static \
--location southeastasia
# Triển khai Azure Firewall Standard (~10 phút)
az network firewall create \
--resource-group rg-lab16-firewall \
--name fw-lab16 \
--location southeastasia \
--sku AZFW_VNet \
--tier Standard
# Gắn IP vào firewall
az network firewall ip-config create \
--resource-group rg-lab16-firewall \
--firewall-name fw-lab16 \
--name fw-ipconfig \
--public-ip-address pip-fw-lab16 \
--vnet-name vnet-fw
# Lấy private IP và public IP của firewall
FW_PRIVATE_IP=$(az network firewall show \
--resource-group rg-lab16-firewall \
--name fw-lab16 \
--query "ipConfigurations[0].privateIPAddress" \
--output tsv)
FW_PUBLIC_IP=$(az network public-ip show \
--resource-group rg-lab16-firewall \
--name pip-fw-lab16 \
--query ipAddress --output tsv)
echo "Firewall Private IP: $FW_PRIVATE_IP"
echo "Firewall Public IP: $FW_PUBLIC_IP"
Cấu Hình Firewall Rules (DNAT + Network + Application)
DNAT Rules (RDP forwarding):
- 3.1fw-lab16 → Rules → NAT rule collection → Add → Name:
dnat-rdp→ Priority: 200 - 3.2Rules: Name=Allow-RDP, Protocol=TCP, Source=*, Destination=FW_PUBLIC_IP, DestPort=3389, Translated addr=10.1.2.4, Translated port=3389 → Add
Network Rules (DNS):
- 3.3Network rule collection → Add → Name:
net-allow-dns→ Priority: 200 → Action: Allow - 3.4Rule: Protocol=UDP, Source=10.1.2.0/24, Dest=8.8.8.8 8.8.4.4, Port=53 → Add
Application Rules (FQDN whitelist):
- 3.5Application rule collection → Add → Name:
app-allow-web→ Priority: 200 → Action: Allow - 3.6Rule: Source=10.1.2.0/24, Protocol=Https:443, FQDN=
*.microsoft.com→ Add - 3.7Add rule collection → Name:
app-deny-web→ Priority: 300 → Action: Deny → FQDN=*.bing.com
# --- DNAT Rules: RDP forwarding ---
az network firewall nat-rule create \
--resource-group rg-lab16-firewall \
--firewall-name fw-lab16 \
--collection-name dnat-rdp \
--priority 200 \
--name Allow-RDP \
--protocols TCP \
--source-addresses '*' \
--dest-addr $FW_PUBLIC_IP \
--destination-ports 3389 \
--translated-address 10.1.2.4 \
--translated-port 3389
# --- Network Rules: Allow DNS ---
az network firewall network-rule create \
--resource-group rg-lab16-firewall \
--firewall-name fw-lab16 \
--collection-name net-allow-dns \
--priority 200 \
--action Allow \
--name Allow-DNS \
--protocols UDP \
--source-addresses 10.1.2.0/24 \
--destination-addresses 8.8.8.8 8.8.4.4 \
--destination-ports 53
# --- Application Rules: Allow microsoft.com ---
az network firewall application-rule create \
--resource-group rg-lab16-firewall \
--firewall-name fw-lab16 \
--collection-name app-allow-web \
--priority 200 \
--action Allow \
--name Allow-Microsoft \
--source-addresses 10.1.2.0/24 \
--protocols Https=443 \
--fqdn-tags WindowsUpdate \
--target-fqdns "*.microsoft.com" "*.windowsupdate.com"
# --- Application Rules: Deny bing.com ---
az network firewall application-rule create \
--resource-group rg-lab16-firewall \
--firewall-name fw-lab16 \
--collection-name app-deny-web \
--priority 300 \
--action Deny \
--name Deny-Bing \
--source-addresses 10.1.2.0/24 \
--protocols Https=443 \
--target-fqdns "*.bing.com"
Tạo User Defined Route (UDR) & Cấu Hình DNS VM
UDR buộc tất cả traffic outbound từ SubnetServer đi qua firewall. Nếu không có UDR, traffic sẽ bypass firewall và đi thẳng ra internet.
- 4.1Route tables → Create → Name:
rt-lab16→ Southeast Asia → Propagate gateway routes: Yes - 4.2rt-lab16 → Routes → Add → Route name:
route-to-firewall→ Destination: 0.0.0.0/0 → Next hop type: Virtual appliance → Next hop address:10.1.1.4(FW private IP) - 4.3rt-lab16 → Subnets → Associate → VNet: vnet-fw → Subnet: SubnetServer
- 4.4VM Network Interface → DNS servers → Custom → 8.8.8.8 → Save (cần restart VM để áp dụng)
# Tạo Route Table
az network route-table create \
--resource-group rg-lab16-firewall \
--name rt-lab16 \
--location southeastasia \
--disable-bgp-route-propagation false
# Thêm default route → firewall private IP
az network route-table route create \
--resource-group rg-lab16-firewall \
--route-table-name rt-lab16 \
--name route-to-firewall \
--address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance \
--next-hop-ip-address $FW_PRIVATE_IP
# Gắn Route Table vào SubnetServer
az network vnet subnet update \
--resource-group rg-lab16-firewall \
--vnet-name vnet-fw \
--name SubnetServer \
--route-table rt-lab16
# Cấu hình custom DNS cho VM NIC
NIC_ID=$(az vm show \
--resource-group rg-lab16-firewall \
--name vm-lab16-server \
--query "networkProfile.networkInterfaces[0].id" \
--output tsv)
az network nic update \
--ids $NIC_ID \
--dns-servers 8.8.8.8 8.8.4.4
# Restart VM để áp dụng DNS
az vm restart \
--resource-group rg-lab16-firewall \
--name vm-lab16-server
Xác Minh Firewall Rules
RDP vào VM bằng public IP của firewall (DNAT). Sau khi vào, test Application rules từ browser trong VM.
# Test 1: Kiểm tra DNS hoạt động qua firewall (Network rule UDP/53)
nslookup microsoft.com 8.8.8.8
# Kết quả mong đợi: trả về IP của microsoft.com
# Test 2: HTTPS đến microsoft.com (Application rule Allow)
Invoke-WebRequest -Uri "https://www.microsoft.com" `
-UseBasicParsing | Select-Object StatusCode
# Kết quả mong đợi: StatusCode 200
# Test 3: HTTPS đến bing.com (Application rule Deny)
try {
Invoke-WebRequest -Uri "https://www.bing.com" `
-UseBasicParsing -TimeoutSec 10
} catch {
Write-Host "BLOCKED by firewall: $($_.Exception.Message)" `
-ForegroundColor Red
}
# Kết quả mong đợi: Connection timed out / refused
# Test 4: Kiểm tra IP public thực sự (qua firewall)
Invoke-RestMethod -Uri "https://api.ipify.org"
# Kết quả mong đợi: địa chỉ IP = FW_PUBLIC_IP (không phải VM IP)
# Test 1 - DNS:
Server: dns.google / Address: 8.8.8.8
Name: microsoft.com / Address: 20.112.52.29 ✓
# Test 2 - microsoft.com:
StatusCode: 200 ✓ (Application Allow rule matched)
# Test 3 - bing.com:
BLOCKED by firewall: The operation has timed out ✓ (Deny rule)
# Test 4 - Public IP check:
✓ (traffic NAT qua firewall, không trực tiếp)
# Portal → fw-lab16 → Logs → xem Firewall logs để audit toàn bộ traffic
📊 Kết Quả Đầu Ra Lab 16
fw-lab16 → Provisioning State: Succeeded, có Private + Public IP
mstsc /v:FW_PUBLIC_IP → đăng nhập được vào vm-lab16-server
nslookup 8.8.8.8 trả về kết quả → Network rule Allow-DNS hoạt động
microsoft.com: 200 OK; bing.com: timeout/blocked — đúng như policy
Public IP check = FW_PUBLIC_IP → traffic đi qua firewall, không bypass
Portal → fw-lab16 → Diagnostic settings → Logs hiển thị rule matches
🧹 Dọn Dẹp Tài Nguyên
# Xóa toàn bộ resource group (Firewall, VM, VNet, Public IP, Route Table)
az group delete \
--name rg-lab16-firewall \
--yes \
--no-wait
# Xác nhận không còn tính phí
az network firewall list --output table
# Kết quả mong đợi: (empty table)
❓ Câu Hỏi Ôn Tập
1. Tại sao AzureFirewallSubnet bắt buộc phải là /26 hoặc lớn hơn?
Gợi ý: Azure Firewall là managed service, Microsoft cần dự phòng IP cho internal infrastructure. /26 = 64 IPs, sau khi trừ Azure reserved (5 IPs) còn 59 — đủ cho HA instances và management
2. Ba loại rule collections trong Azure Firewall được xử lý theo thứ tự nào?
Gợi ý: DNAT → Network → Application (trong mỗi loại: priority thấp hơn = xử lý trước); nếu DNAT rule match thì không check Network/Application nữa
3. Tại sao cần User Defined Route (UDR)? Không có UDR thì traffic chạy như thế nào?
Gợi ý: Không có UDR → Azure default routing gửi traffic thẳng ra internet qua system route — bypass firewall hoàn toàn. UDR ghi đè route 0.0.0.0/0 → Virtual Appliance (firewall private IP)
4. Azure Firewall Standard và Premium khác nhau như thế nào?
Gợi ý: Premium thêm: TLS inspection (decrypt/inspect HTTPS), IDPS (Intrusion Detection & Prevention System), URL filtering (path-level, không chỉ FQDN), Web categories — dùng cho compliance cao (PCI-DSS, HIPAA)
5. Firewall Policy khác Classic Firewall Rules ở điểm nào? Khi nào nên dùng Policy?
Gợi ý: Policy = ARM resource riêng, tái sử dụng được, hỗ trợ Firewall Manager (multi-hub management), rule inheritance; Classic rules gắn liền vào 1 firewall — dùng Policy cho production/enterprise với nhiều firewall cần consistent policy