Filter inbound Internet or intranet traffic with Azure Firewall DNAT using the Azure portal
You can configure Azure Firewall Destination Network Address Translation (DNAT) to translate and filter inbound Internet traffic to your subnets or intranet traffic between private networks (preview). When you configure DNAT, the NAT rule collection action is set to Dnat. Each rule in the NAT rule collection can then be used to translate your firewall public or private IP address and port to a private IP address and port. DNAT rules implicitly add a corresponding network rule to allow the translated traffic. For security reasons, the recommended approach is to add a specific source to allow DNAT access to the network and avoid using wildcards. To learn more about Azure Firewall rule processing logic, see Azure Firewall rule processing logic.
Note
This article uses classic Firewall rules to manage the firewall. The preferred method is to use Firewall Policy. To complete this procedure using Firewall Policy, see Tutorial: Filter inbound Internet traffic with Azure Firewall policy DNAT using the Azure portal
Prerequisites
If you don't have an Azure subscription, create a free account before you begin.
Create a resource group
- Sign in to the Azure portal.
- On the Azure portal home page, select Resource groups, then select Create.
- For Subscription, select your subscription.
- For Resource group, type RG-DNAT-Test.
- For Region, select a region. All other resources that you create must be in the same region.
- Select Review + create.
- Select Create.
Set up the network environment
For this article, you create a two peered VNets:
- VN-Hub - the firewall is in this VNet.
- VN-Spoke - the workload server is in this VNet.
First, create the VNets and then peer them.
Create the Hub VNet
From the Azure portal home page, select All services.
Under Networking, select Virtual networks.
Select Create.
For Resource group, select RG-DNAT-Test.
For Name, type VN-Hub.
For Region, select the same region that you used before.
Select Next.
On the Security tab, select Next.
For IPv4 Address space, accept the default 10.0.0.0/16.
Under Subnets, select default.
For Subnet template, select Azure Firewall.
The firewall will be in this subnet, and the subnet name must be AzureFirewallSubnet.
Note
The size of the AzureFirewallSubnet subnet is /26. For more information about the subnet size, see Azure Firewall FAQ.
Select Save.
Select Review + create.
Select Create.
Create a spoke VNet
- From the Azure portal home page, select All services.
- Under Networking, select Virtual networks.
- Select Create.
- For Resource group, select RG-DNAT-Test.
- For Name, type VN-Spoke.
- For Region, select the same region that you used before.
- Select Next.
- On the Security tab, select Next.
- For IPv4 Address space, edit the default and type 192.168.0.0/16.
- Under Subnets, select default.
- For the subnet Name type SN-Workload.
- For Starting address, type 192.168.1.0.
- For Subnet size, select /24.
- Select Save.
- Select Review + create.
- Select Create.
Peer the VNets
Now peer the two VNets.
- Select the VN-Hub virtual network.
- Under Settings, select Peerings.
- Select Add.
- Under This virtual network, for the Peering link name, type Peer-HubSpoke.
- Under Remote virtual network, for Peering link name, type Peer-SpokeHub.
- Select VN-Spoke for the virtual network.
- Accept all the other defaults, and then select Add.
Create a virtual machine
Create a workload virtual machine, and place it in the SN-Workload subnet.
- From the Azure portal menu, select Create a resource.
- Under Popular Marketplace products, select Windows Server 2019 Datacenter.
Basics
- For Subscription, select your subscription.
- For Resource group, select RG-DNAT-Test.
- For Virtual machine name, type Srv-Workload.
- For Region, select the same location that you used previously.
- Type a username and password.
- Select Next: Disks.
Disks
- Select Next: Networking.
Networking
- For Virtual network, select VN-Spoke.
- For Subnet, select SN-Workload.
- For Public IP, select None.
- For Public inbound ports, select None.
- Leave the other default settings and select Next: Management.
Management
- Select Next: Monitoring.
Monitoring
- For Boot diagnostics, select Disable.
- Select Review + Create.
Review + Create
Review the summary, and then select Create. This takes a few minutes to complete.
After deployment finishes, note the private IP address for the virtual machine. It is used later when you configure the firewall. Select the virtual machine name. Select Overview, and under Networking note the private IP address.
Note
Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the backend pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.
The default outbound access IP is disabled when one of the following events happens:
- A public IP address is assigned to the VM.
- The VM is placed in the backend pool of a standard load balancer, with or without outbound rules.
- An Azure NAT Gateway resource is assigned to the subnet of the VM.
VMs that you create by using virtual machine scale sets in flexible orchestration mode don't have default outbound access.
For more information about outbound connections in Azure, see Default outbound access in Azure and Use Source Network Address Translation (SNAT) for outbound connections.
Deploy the firewall
From the portal home page, select Create a resource.
Search for Firewall, and then select Firewall.
Select Create.
On the Create a Firewall page, use the following table to configure the firewall:
Setting Value Subscription <your subscription> Resource group Select RG-DNAT-Test Name FW-DNAT-test Region Select the same location that you used previously Firewall SKU Standard Firewall management Use Firewall rules (classic) to manage this firewall Choose a virtual network Use existing: VN-Hub Public IP address Add new, Name: fw-pip. Accept the other defaults, and then select Review + create.
Review the summary, and then select Create to create the firewall.
This takes a few minutes to deploy.
After deployment completes, go to the RG-DNAT-Test resource group, and select the FW-DNAT-test firewall.
Note the firewall's private and public IP addresses. You'll use them later when you create the default route and NAT rule.
Create a default route
For the SN-Workload subnet, you configure the outbound default route to go through the firewall.
Important
You do not need to configure an explicit route back to the firewall at the destination subnet. Azure Firewall is a stateful service and handles the packets and sessions automatically. If you create this route, you'll create an asymmetrical routing environment that interrupts the stateful session logic and results in dropped packets and connections.
From the Azure portal home page, select Create a resource.
Search for Route table and select it.
Select Create.
For Subscription, select your subscription.
For Resource group, select RG-DNAT-Test.
For Region, select the same region that you used previously.
For Name, type RT-FWroute.
Select Review + create.
Select Create.
Select Go to resource.
Select Subnets, and then select Associate.
For Virtual network, select VN-Spoke.
For Subnet, select SN-Workload.
Select OK.
Select Routes, and then select Add.
For Route name, type FW-DG.
For Destination type, select IP Addresses.
For Destination IP addresses/CIDR ranges, type 0.0.0.0/0.
For Next hop type, select Virtual appliance.
Azure Firewall is actually a managed service, but virtual appliance works in this situation.
For Next hop address, type the private IP address for the firewall that you noted previously.
Select Add.
Configure a NAT rule
- Open the RG-DNAT-Test resource group, and select the FW-DNAT-test firewall.
- On the FW-DNAT-test page, under Settings, select Rules (classic).
- Select Add NAT rule collection.
- For Name, type RC-DNAT-01.
- For Priority, type 200.
- Under Rules, for Name, type RL-01.
- For Protocol, select TCP.
- For Source type, select IP address.
- For Source, type *.
- For Destination Addresses, type the firewall's public or private IP address.
- For Destination ports, type 3389.
- For Translated Address type the private IP address for the Srv-Workload virtual machine.
- For Translated port, type 3389.
- Select Add.
This takes a few minutes to complete.
Test the firewall
- Connect a remote desktop to firewall public IP address. You should be connected to the Srv-Workload virtual machine.
- Close the remote desktop.
Clean up resources
You can keep your firewall resources for further testing, or if no longer needed, delete the RG-DNAT-Test resource group to delete all firewall-related resources.
Next steps
Next, you can monitor the Azure Firewall logs.