Proposed Pull Request Change

title description services author ms.service ms.custom ms.date ms.author ms.topic
Deploy and configure Azure Firewall using Azure CLI In this article, you learn how to deploy and configure Azure Firewall using the Azure CLI. firewall duongau azure-firewall devx-track-azurecli 10/31/2022 duau how-to
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: Deploy and configure Azure Firewall using Azure CLI description: In this article, you learn how to deploy and configure Azure Firewall using the Azure CLI. services: firewall author: duongau ms.service: azure-firewall ms.custom: devx-track-azurecli ms.date: 10/31/2022 ms.author: duau ms.topic: how-to #Customer intent: As an administrator new to this service, I want to control outbound network access from resources located in an Azure subnet. # Customer intent: As an administrator deploying network security solutions, I want to configure Azure Firewall using the command-line interface, so that I can control outbound access and manage network traffic effectively within my Azure environment. --- # Deploy and configure Azure Firewall using Azure CLI Controlling outbound network access is an important part of an overall network security plan. For example, you may want to limit access to web sites. Or, you may want to limit the outbound IP addresses and ports that can be accessed. One way you can control outbound network access from an Azure subnet is with Azure Firewall. With Azure Firewall, you can configure: * Application rules that define fully qualified domain names (FQDNs) that can be accessed from a subnet. The FQDN can also [include SQL instances](sql-fqdn-filtering.md). * Network rules that define source address, protocol, destination port, and destination address. Network traffic is subjected to the configured firewall rules when you route your network traffic to the firewall as the subnet default gateway. For this article, you create a simplified single VNet with three subnets for easy deployment. For production deployments, a [hub and spoke model](/azure/architecture/reference-architectures/hybrid-networking/hub-spoke) is recommended. The firewall is in its own VNet. The workload servers are in peered VNets in the same region with one or more subnets. * **AzureFirewallSubnet** - the firewall is in this subnet. * **Workload-SN** - the workload server is in this subnet. This subnet's network traffic goes through the firewall. * **Jump-SN** - The "jump" server is in this subnet. The jump server has a public IP address that you can connect to using Remote Desktop. From there, you can then connect to (using another Remote Desktop) the workload server. :::image type="content" source="media/tutorial-firewall-rules-portal/Tutorial_network.png" alt-text="Diagram of network infrastructure." lightbox="media/tutorial-firewall-rules-portal/Tutorial_network.png"::: In this article, you learn how to: * Set up a test network environment * Deploy a firewall * Create a default route * Configure an application rule to allow access to www.microsoft.com * Configure a network rule to allow access to external DNS servers * Test the firewall If you prefer, you can complete this procedure using the [Azure portal](tutorial-firewall-deploy-portal.md) or [Azure PowerShell](deploy-ps.md). [!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)] [!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment.md)] - This article requires version 2.55.0 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed. ## Set up the network First, create a resource group to contain the resources needed to deploy the firewall. Then create a VNet, subnets, and test servers. ### Create a resource group The resource group contains all the resources for the deployment. ```azurecli-interactive az group create --name Test-FW-RG --location eastus ``` ### Create a VNet This virtual network has three subnets. > [!NOTE] > The size of the AzureFirewallSubnet subnet is /26. For more information about the subnet size, see [Azure Firewall FAQ](firewall-faq.yml#why-does-azure-firewall-need-a--26-subnet-size). ```azurecli-interactive az network vnet create \ --name Test-FW-VN \ --resource-group Test-FW-RG \ --location eastus \ --address-prefix 10.0.0.0/16 \ --subnet-name AzureFirewallSubnet \ --subnet-prefix 10.0.1.0/26 az network vnet subnet create \ --name Workload-SN \ --resource-group Test-FW-RG \ --vnet-name Test-FW-VN \ --address-prefix 10.0.2.0/24 az network vnet subnet create \ --name Jump-SN \ --resource-group Test-FW-RG \ --vnet-name Test-FW-VN \ --address-prefix 10.0.3.0/24 ``` ### Create virtual machines Now create the jump and workload virtual machines, and place them in the appropriate subnets. When prompted, type a password for the virtual machine. Create the Srv-Jump virtual machine. ```azurecli-interactive az vm create \ --resource-group Test-FW-RG \ --name Srv-Jump \ --location eastus \ --image win2016datacenter \ --vnet-name Test-FW-VN \ --subnet Jump-SN \ --admin-username azureadmin az vm open-port --port 3389 --resource-group Test-FW-RG --name Srv-Jump ``` Create a NIC for Srv-Work with specific DNS server IP addresses and no public IP address to test with. ```azurecli-interactive az network nic create \ -g Test-FW-RG \ -n Srv-Work-NIC \ --vnet-name Test-FW-VN \ --subnet Workload-SN \ --public-ip-address "" \ --dns-servers <replace with External DNS ip #1> <replace with External DNS ip #2> ``` Now create the workload virtual machine. When prompted, type a password for the virtual machine. ```azurecli-interactive az vm create \ --resource-group Test-FW-RG \ --name Srv-Work \ --location eastus \ --image win2016datacenter \ --nics Srv-Work-NIC \ --admin-username azureadmin ``` [!INCLUDE [ephemeral-ip-note.md](~/reusable-content/ce-skilling/azure/includes/ephemeral-ip-note.md)] ## Deploy the firewall Now deploy the firewall into the virtual network. ```azurecli-interactive az network firewall create \ --name Test-FW01 \ --resource-group Test-FW-RG \ --location eastus az network public-ip create \ --name fw-pip \ --resource-group Test-FW-RG \ --location eastus \ --allocation-method static \ --sku standard az network firewall ip-config create \ --firewall-name Test-FW01 \ --name FW-config \ --public-ip-address fw-pip \ --resource-group Test-FW-RG \ --vnet-name Test-FW-VN az network firewall update \ --name Test-FW01 \ --resource-group Test-FW-RG az network public-ip show \ --name fw-pip \ --resource-group Test-FW-RG fwprivaddr="$(az network firewall ip-config list -g Test-FW-RG -f Test-FW01 --query "[?name=='FW-config'].privateIpAddress" --output tsv)" ``` Note the private IP address. You'll use it later when you create the default route. ## Create a default route Create a route table, with BGP route propagation disabled ```azurecli-interactive az network route-table create \ --name Firewall-rt-table \ --resource-group Test-FW-RG \ --location eastus \ --disable-bgp-route-propagation true ``` Create the route. ```azurecli-interactive az network route-table route create \ --resource-group Test-FW-RG \ --name DG-Route \ --route-table-name Firewall-rt-table \ --address-prefix 0.0.0.0/0 \ --next-hop-type VirtualAppliance \ --next-hop-ip-address $fwprivaddr ``` Associate the route table to the subnet ```azurecli-interactive az network vnet subnet update \ -n Workload-SN \ -g Test-FW-RG \ --vnet-name Test-FW-VN \ --address-prefixes 10.0.2.0/24 \ --route-table Firewall-rt-table ``` ## Configure an application rule The application rule allows outbound access to www.microsoft.com. ```azurecli-interactive az network firewall application-rule create \ --collection-name App-Coll01 \ --firewall-name Test-FW01 \ --name Allow-Microsoft \ --protocols Http=80 Https=443 \ --resource-group Test-FW-RG \ --target-fqdns www.microsoft.com \ --source-addresses 10.0.2.0/24 \ --priority 200 \ --action Allow ``` Azure Firewall includes a built-in rule collection for infrastructure FQDNs that are allowed by default. These FQDNs are specific for the platform and can't be used for other purposes. For more information, see [Infrastructure FQDNs](infrastructure-fqdns.md). ## Configure a network rule The network rule allows outbound access to two public DNS IP addresses of your choosing at port 53 (DNS). ```azurecli-interactive az network firewall network-rule create \ --collection-name Net-Coll01 \ --destination-addresses <replace with DNS ip #1> <replace with DNS ip #2> \ --destination-ports 53 \ --firewall-name Test-FW01 \ --name Allow-DNS \ --protocols UDP \ --resource-group Test-FW-RG \ --priority 200 \ --source-addresses 10.0.2.0/24 \ --action Allow ``` ## Test the firewall Now, test the firewall to confirm that it works as expected. 1. Note the private IP address for the **Srv-Work** virtual machine: ```azurecli-interactive az vm list-ip-addresses \ -g Test-FW-RG \ -n Srv-Work ``` 1. Connect a remote desktop to **Srv-Jump** virtual machine, and sign in. From there, open a remote desktop connection to the **Srv-Work** private IP address and sign in. 3. On **SRV-Work**, open a PowerShell window and run the following commands: ``` nslookup www.google.com nslookup www.microsoft.com ``` Both commands should return answers, showing that your DNS queries are getting through the firewall. 1. Run the following commands: ``` Invoke-WebRequest -Uri https://www.microsoft.com Invoke-WebRequest -Uri https://www.microsoft.com Invoke-WebRequest -Uri <Replace with external website> Invoke-WebRequest -Uri <Replace with external website> ``` The `www.microsoft.com` requests should succeed, and the other `External Website` requests should fail. This demonstrates that your firewall rules are operating as expected. So now you've verified that the firewall rules are working: * You can resolve DNS names using the configured external DNS server. * You can browse to the one allowed FQDN, but not to any others. ## Clean up resources You can keep your firewall resources for the next tutorial, or if no longer needed, delete the **Test-FW-RG** resource group to delete all firewall-related resources: ```azurecli-interactive az group delete \ -n Test-FW-RG ``` ## Next steps * [Tutorial: Monitor Azure Firewall logs](./firewall-diagnostics.md)
Success! Branch created successfully. Create Pull Request on GitHub
Error: