Implement Azure Firewall in Virtual Networks
This tutorial guides you through the process of deploying and configuring Azure Firewall to secure your virtual network traffic. Azure Firewall is a cloud-native and intelligent network security service that protects your virtual network resources. It's a fully stateful firewall as a service with built-in high availability and unrestricted cloud scalability.
What You'll Learn
- Deploying Azure Firewall.
- Configuring Network and Application Rules.
- Testing firewall rules.
- Best practices for Azure Firewall.
Step 1: Create a Virtual Network and Firewall Subnet
First, you need a virtual network (VNet) to deploy the firewall into. It's best practice to place Azure Firewall in its own dedicated subnet, named AzureFirewallSubnet.
To create the VNet and subnet:
- Sign in to the Azure portal.
- Search for and select "Virtual networks".
- Click "+ Create".
- Configure the basic settings: Subscription, Resource group, Name, and Region.
- Under "IP addresses", define an address space for your VNet (e.g., 10.1.0.0/16).
- Click "Next: Security >" and then "Next: IP addresses >".
- Under "Subnets", click "+ Add subnet".
- For "Subnet name", enter
AzureFirewallSubnet. - For "Address range", specify a range for this subnet (e.g., 10.1.1.0/24). This subnet is mandatory for Azure Firewall.
- Click "Add".
- Complete the VNet creation.
Step 2: Deploy Azure Firewall
Now, deploy the Azure Firewall instance into the VNet you just created.
To deploy the firewall:
- In the Azure portal, search for and select "Azure Firewall".
- Click "+ Create".
- Select your Subscription and Resource group.
- For "Name", enter a name for your firewall (e.g.,
fw-centralus). - For "Region", select the same region as your VNet.
- For "Firewall policy", you can choose to create a new policy or use an existing one. For this tutorial, let's create a new one. Click "Create new".
- Give your firewall policy a name (e.g.,
fw-policy-main) and click "OK". - For "SKU", choose "Standard" or "Premium" (Standard is sufficient for this tutorial).
- For "Virtual network", select the VNet you created earlier. The
AzureFirewallSubnetwill be automatically selected. - For "Public IP address", select "Create new" and provide a name for the public IP (e.g.,
fw-publicip). - Click "Review + create", then "Create".
Deployment can take several minutes.
Step 3: Configure Network Rules
Network rules allow you to filter traffic to and from resources within your VNet based on IP address, port, and protocol.
To add a network rule collection:
- Navigate to your deployed Azure Firewall resource in the Azure portal.
- Under "Settings", click "Network rules".
- Click "+ Add network rule collection".
- Rule collection name: Enter a name (e.g.,
Allow-HTTPS). - Priority: Enter a priority number (lower numbers are processed first, e.g.,
200). - Rule type: Select "Network".
- Rules: Click "+ Add a rule".
- Name:
Allow-Web-Servers - Source type: "IP Address"
- Source: Specify the IP address range of your internal network (e.g.,
10.1.0.0/16). - Protocol: "TCP"
- Destination type: "IP Address"
- Destination: Enter the IP address of the web server you want to allow access to (e.g.,
10.1.2.4). - Destination port:
443 - Click "Add".
- Name:
- Click "Add" to save the rule collection.
Step 4: Configure Application Rules
Application rules allow you to filter traffic based on Fully Qualified Domain Names (FQDNs).
To add an application rule collection:
- Navigate to your Azure Firewall resource and click "Application rules".
- Click "+ Add application rule collection".
- Rule collection name: Enter a name (e.g.,
Allow-External-Sites). - Priority: Enter a priority number (e.g.,
300). - Rule type: Select "Application".
- Rules: Click "+ Add a rule".
- Name:
Allow-Azure-Docs - Source type: "IP Address"
- Source: Specify your internal network range (e.g.,
10.1.0.0/16). - Protocol:
http,https - Target FQDNs: Enter
www.azure.com - Click "Add".
- Name:
- Click "Add" to save the rule collection.
Step 5: Configure Default Route Table
To route traffic from your subnets through the firewall, you need to update the route table associated with your VNet's subnets (excluding the AzureFirewallSubnet itself).
To create and associate a route table:
- In the Azure portal, search for and select "Route tables".
- Click "+ Create".
- Configure Subscription, Resource group, and Region.
- For "Name", enter a name (e.g.,
rt-firewall-traffic). - Leave "Propagate gateway routes" as "Yes".
- Click "Review + create", then "Create".
- Once created, navigate to the route table.
- Under "Settings", click "Routes" and then "+ Add".
- Route name:
DefaultRoute - Address prefix:
0.0.0.0/0 - Next hop type: "Virtual appliance"
- Next hop address: Enter the private IP address of your Azure Firewall. You can find this on the firewall's overview page.
- Click "Add".
- Now, navigate back to your Virtual Network. Under "Settings", click "Subnets".
- Click on each subnet (except
AzureFirewallSubnet) and select the route table you just created (rt-firewall-traffic) from the "Route table" dropdown. - Click "Save".
Step 6: Test Firewall Rules
Deploy a virtual machine in a subnet other than AzureFirewallSubnet and test connectivity.
To test:
- Deploy a VM into one of your subnets.
- Connect to the VM (e.g., via RDP or SSH).
- From the VM, try to access an external website like
www.azure.comusing a web browser. This should be allowed by your application rule. - Try to access a resource on the internet on port 80 (HTTP). This should be allowed by your network rule if configured for HTTP.
- Attempt to access a forbidden website or service to verify that your deny rules (if configured) or default deny policy is working.
Conclusion
You have successfully deployed Azure Firewall, configured network and application rules, and set up routing to direct traffic through the firewall. This provides a robust layer of security for your Azure virtual networks.