Firewall
π₯ What is Azure Firewall?¶
Azure Firewall is a cloud-native, stateful, Layer 4 and Layer 7 firewall service built for highly secure and scalable network traffic filtering in Azure.
It centrally controls and logs traffic across VNets and Azure services using rules for IPs, ports, protocols, and even FQDNs.
π Table of Contents¶
-
Overview of Azure Firewall
-
Features and Capabilities
-
Azure Firewall vs NSG vs WAF
-
Real-World Architecture Diagram
-
Types of Firewall Rules
-
How DNAT, SNAT Work
-
Hands-on Setup (Portal & CLI)
-
Monitoring & Logging
-
Best Practices
-
Interview Questions
1οΈβ£ Azure Firewall Overview¶
| Feature | Description |
|---|---|
| Type | Stateful, fully managed |
| Layers | L3 (IP), L4 (TCP/UDP), L7 (FQDN, HTTP/S) |
| High Availability | Built-in |
| Scale | Auto scales throughput |
| Logging | Full logging with Azure Monitor, Log Analytics |
| Deployment | Must be in a dedicated subnet named AzureFirewallSubnet |
2οΈβ£ Key Features¶
| Feature | Description |
|---|---|
| Network Rules | Filter by IPs, ports, protocols |
| Application Rules | Allow/Deny access by FQDN or domain |
| DNAT | Expose internal services to the internet |
| SNAT | Outbound internet access for private subnets |
| Threat Intelligence | Block traffic from known malicious IPs |
| Forced Tunneling | Route all traffic through Firewall (even to internet) |
3οΈβ£ Azure Firewall vs NSG vs WAF¶
| Feature | Azure Firewall | NSG | WAF |
|---|---|---|---|
| Layer | 3β7 | 3β4 | 7 |
| Stateful | β | β | β |
| Protocol Aware | TCP/UDP/FQDN/HTTP | TCP/UDP | HTTP/S only |
| Outbound Control | β | β | β |
| Threat Protection | β | β | β (only for web apps) |
| Use Case | Central security | Local subnet filtering | App-layer protection |
4οΈβ£ Architecture Diagram¶
Internet
β
βββββββΌββββββ
β Azure Firewall β
βββββββ¬ββββββ
β
ββββββΌβββββ
β Hub VNetβ β AzureFirewallSubnet
ββββββ¬βββββ
β
ββββββββββΌβββββββββ
β Spoke VNets (App, DB) β β Peered to Hub
βββββββββββββββββββββ
Use Hub-and-Spoke model for enterprise networks.
5οΈβ£ Firewall Rule Types¶
| Rule Type | Description | Use Case |
|---|---|---|
| Network Rule | IP, protocol, port | Allow RDP to VM |
| Application Rule | FQDN, HTTP/S | Allow *.microsoft.com |
| NAT Rule | Translate IP/port | Expose VM to internet |
6οΈβ£ DNAT & SNAT¶
π DNAT (Destination NAT)¶
-
Maps public IP β private IP
-
Use for publishing services to the internet
Example: Allow
20.50.50.1:3389β10.0.0.4:3389(RDP)
π SNAT (Source NAT)¶
-
Allows outbound internet access from private subnets
-
Uses Azure Firewallβs public IP
7οΈβ£ Hands-On Setup¶
β Azure Portal¶
-
Create Virtual Network
- Add subnet:
AzureFirewallSubnet
- Add subnet:
-
Create Azure Firewall
-
Choose public IP
-
Assign to
AzureFirewallSubnet
-
-
Create Route Table
-
Add route:
0.0.0.0/0 β Azure Firewall IP -
Associate with subnets
-
-
Create Rules
-
Network Rule: Allow TCP/UDP by IP/Port
-
Application Rule: Allow FQDNs
-
DNAT Rule: Map public IP β VM IP
-
π» Azure CLI Example¶
# Create resource group and VNet
az group create --name fw-rg --location eastus
az network vnet create \
--name fw-vnet \
--resource-group fw-rg \
--address-prefix 10.0.0.0/16 \
--subnet-name AzureFirewallSubnet \
--subnet-prefix 10.0.1.0/24
# Create public IP for firewall
az network public-ip create \
--name fw-pip \
--resource-group fw-rg \
--sku Standard \
--location eastus
# Create Azure Firewall
az network firewall create \
--name myFirewall \
--resource-group fw-rg \
--location eastus
# Attach public IP
az network firewall ip-config create \
--firewall-name myFirewall \
--name fw-config \
--public-ip-address fw-pip \
--resource-group fw-rg \
--vnet-name fw-vnet
# Create rule collection
az network firewall network-rule create \
--firewall-name myFirewall \
--resource-group fw-rg \
--collection-name allow-web \
--name allow-http \
--rule-type NetworkRule \
--priority 100 \
--action Allow \
--protocols TCP \
--source-addresses 10.0.0.0/24 \
--destination-addresses 20.50.50.1 \
--destination-ports 80
8οΈβ£ Monitoring & Logging¶
-
Enable Diagnostic Settings:
- Send logs to Log Analytics, Storage, or Event Hub
-
Log types:
-
AzureFirewallApplicationRule -
AzureFirewallNetworkRule -
AzureFirewallDnsProxy
-
Query example in Log Analytics:
9οΈβ£ Best Practices¶
| Practice | Reason |
|---|---|
| Use Standard SKU | Basic is deprecated |
| Use in Hub VNet | Enables central control |
| Use custom DNS with DNS proxy | For name-based outbound rules |
| Use route tables (UDR) | Force all traffic via Firewall |
| Use Threat Intelligence in Alert or Deny mode | Block malicious IPs |
| Always log and monitor | Audit traffic and detect misconfigurations |