You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/firewall-manager/secure-cloud-network-powershell.md
+45-43Lines changed: 45 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,40 +28,39 @@ In this tutorial, you learn how to:
28
28
29
29
- If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
30
30
31
-
- PowerShell 7
31
+
- PowerShell 7 or higher
32
32
33
-
This tutorial requires that you run Azure PowerShell locally on PowerShell 7. To install PowerShell 7, see [Migrating from Windows PowerShell 5.1 to PowerShell 7](/powershell/scripting/install/migrating-from-windows-powershell-51-to-powershell-7).
33
+
This tutorial requires that you run Azure PowerShell locally on PowerShell 7 or higher. To install PowerShell 7, see [Migrating from Windows PowerShell 5.1 to PowerShell 7](/powershell/scripting/install/migrating-from-windows-powershell-51-to-powershell-7).
34
34
35
35
- "Az.Network" module version must be 4.17.0 or higher.
36
36
37
37
## Sign in to Azure
38
38
39
-
```azurepowershell
39
+
```azurepowershell-interactive
40
40
Connect-AzAccount
41
41
Select-AzSubscription -Subscription "<sub name>"
42
42
```
43
43
44
44
## Initial Virtual WAN deployment
45
+
To begin, you need to set variables and create the resource group, the virtual WAN instance, and the virtual hub:
45
46
46
-
As a first step, you need to set some variables and create the resource group, the virtual WAN instance, and the virtual hub:
47
-
48
-
```azurepowershell
47
+
```azurepowershell-interactive
49
48
# Variable definition
50
49
$RG = "vwan-rg"
51
50
$Location = "westeurope"
52
51
$VwanName = "vwan"
53
52
$HubName = "hub1"
54
53
$FirewallTier = "Standard" # or "Premium"
55
54
56
-
# Create Resource Group, Virtual WAN and Virtual Hub
55
+
# Create Resource Group, Virtual WAN and Virtual Hub using the New-AzVirtualWan and New-AzVirtualHub cmdlets
Create two virtual networks and connect them to the hub as spokes:
61
+
-Create two virtual networks and connect them to the hub as spokes using the `New-AzVirtualHubVnetConnection` cmdlet. The virtual networks are created with the address prefixes `10.1.1.0/24` and `10.1.2.0/24`.
At this point, you have a fully functional Virtual WAN providing any-to-any connectivity. To enhance it with security, you need to deploy an Azure Firewall to each Virtual Hub. Firewall Policies can be used to efficiently manage the virtual WAN Azure Firewall instance. So a firewall policy is created as well in this example:
72
+
At this stage, your Virtual WAN is fully operational and provides any-to-any connectivity. To secure this environment, deploy an Azure Firewall in each Virtual Hub. You can centrally manage these firewalls using Firewall Policies.
74
73
75
-
```azurepowershell
74
+
In this example, you'll also create a firewall policy to manage the Azure Firewall instance in the Virtual WAN hub using the `New-AzFirewallPolicy` cmdlet. The Azure Firewall will be deployed in the hub using the `New-AzFirewall` cmdlet.
> The following Firewall creation command does **not** use availability zones. If you want to use this feature, an additional parameter **-Zone** is required. An example is provided in the upgrade section at the end of this article.
90
91
91
-
Enabling logging from the Azure Firewall to Azure Monitor is optional, but in this example you use the Firewall logs to prove that traffic is traversing the firewall:
92
+
Enabling logging from Azure Firewall to Azure Monitor is optional. In this example, you use firewall logs to verify that traffic is passing through the firewall. First, create a Log Analytics workspace to store the logs. Then, use the `Set-AzDiagnosticSetting` cmdlet to configure diagnostic settings and send the logs to the workspace.
92
93
93
-
```azurepowershell
94
+
```azurepowershell-interactive
94
95
# Optionally, enable logging of Azure Firewall to Azure Monitor
@@ -109,9 +110,11 @@ Now you have an Azure Firewall in the hub, but you still need to modify routing
109
110
110
111
111
112
112
-
Start with the first step, to configure your virtual network connections to propagate to the `None` Route Table:
113
+
Begin by configuring your virtual network connections to propagate to the `None` Route Table. This step ensures that the virtual networks do not learn each other's address prefixes, preventing direct communication between them. As a result, all inter-virtual network traffic must pass through the Azure Firewall.
113
114
114
-
```azurepowershell
115
+
To do this, use the `Get-AzVhubRouteTable` cmdlet to retrieve the `None` Route Table, and then update each virtual network connection's routing configuration with the `Update-AzVirtualHubVnetConnection` cmdlet.
116
+
117
+
```azurepowershell-interactive
115
118
# Configure Virtual Network connections in hub to propagate to None
116
119
$VnetRoutingConfig = $Spoke1Connection.RoutingConfiguration # We take $Spoke1Connection as baseline for the future vnet config, all vnets will have an identical config
Now you can continue with the second step, to add the static routes to the `Default` route table. In this example, you apply the default configuration that Azure Firewall Manager would generate when securing connectivity in a Virtual WAN, but you can change the list of prefixes in the static route to fit your specific requirements:
131
+
Next, proceed to the second step: adding static routes to the `Default` route table. The following example uses the default configuration that Azure Firewall Manager applies when securing connectivity in a Virtual WAN. You can customize the list of prefixes in the static route as needed by using the `New-AzVHubRoute` cmdlet. In this example, all traffic is routed through the Azure Firewall, which is the recommended default.
If you are using non-RFC1918 prefixes in your Virtual WAN such as 40.0.0.0/24 in your Virtual Network or on-premises, add an additional route in the defaultRouteTable after routing intent configuration completes. Make sure you name this route as **private_traffic**. If the route is named otherwise, the desired configuration will apply but it will not be reflected in Azure Portal.
157
+
If your Virtual WAN uses non-RFC1918 address prefixes (for example, `40.0.0.0/24` in a virtual network or on-premises), you should add an extra route to the `defaultRouteTable` after completing the routing intent configuration. Name this route **private_traffic**. If you use a different name, the route will work as expected, but the configuration will not be reflected in the Azure Portal.
Now you have a fully operational secure hub. To test connectivity, you need one virtual machine in each spoke virtual network connected to the hub:
180
+
Now that your secure hub is fully operational, you can test connectivity by deploying a virtual machine in each spoke virtual network connected to the hub:
The default configuration in the firewall policy is to drop everything. So you need to configure some rules. Start with DNAT rules, so that the test virtual machines are accessible over the Firewall's public IP address:
210
+
By default, the firewall policy blocks all traffic. To allow access to your test virtual machines, you must configure DNAT (Destination Network Address Translation) rules. These rules will enable you to connect to the VMs through the Azure Firewall's public IP address:
210
211
211
-
```azurepowershell
212
+
```azurepowershell-interactive
212
213
# Adding DNAT rules for virtual machines in the spokes
Now you can configure some example rules. Define a network rule that allows SSH traffic, plus an application rule that allows Internet access to the Fully Qualified Domain Name `ifconfig.co`. This URL returns the source IP address it sees in the HTTP request:
226
+
Next, configure example rules for your firewall policy. First, create a network rule to allow SSH traffic between the virtual networks. Then, add an application rule to permit Internet access only to the Fully Qualified Domain Name (FQDN) `ifconfig.co`, which returns the source IP address seen in the HTTP request:
Before actually sending any traffic, you can inspect the effective routes of the virtual machines. They should contain the prefixes learned from the Virtual WAN (`0.0.0.0/0`plus RFC1918), but not the prefix of the other spoke:
240
+
Before sending any traffic, check the effective routes for each virtual machine. The route tables should show the prefixes learned from the Virtual WAN (`0.0.0.0/0`and RFC1918 ranges), but should not include the address prefix of the other spoke virtual network.
240
241
241
-
```azurepowershell
242
+
```azurepowershell-interactive
242
243
# Check effective routes in the VM NIC in spoke 1
243
244
# Note that 10.1.2.0/24 (the prefix for spoke2) should not appear
244
245
Get-AzEffectiveRouteTable -ResourceGroupName $RG -NetworkInterfaceName $NIC1.Name | ft
Get-AzEffectiveRouteTable -ResourceGroupName $RG -NetworkInterfaceName $NIC2.Name | ft
248
249
```
249
250
250
-
Now generate traffic from one Virtual Machine to the other, and verify that it's dropped in the Azure Firewall. In the following SSH commands you need to accept the virtual machines fingerprints, and provide the password that you defined when you created the virtual machines. In this example, you're going to send five ICMP echo request packets from the virtual machine in spoke1 to spoke2, plus a TCP connection attempt on port 22 using the Linux utility `nc` (with the `-vz` flags it just sends a connection request and shows the result). You should see the ping failing, and the TCP connection attempt on port 22 succeeding, since it's allowed by the network rule you configured previously:
251
+
Generate traffic from one virtual machine to the other and verify that it is filtered by Azure Firewall. Use SSH to connect to the virtual machines—accept the SSH fingerprint and enter the password you set during VM creation. In this example, you will:
251
252
252
-
```azurepowershell
253
+
- Send five ICMP echo requests (pings) from the VM in spoke1 to the VM in spoke2.
254
+
- Attempt a TCP connection on port 22 using the `nc` (netcat) utility with the `-vz` flags, which checks connectivity without sending data.
255
+
256
+
You should observe that the ping requests fail (blocked by the firewall), while the TCP connection on port 22 succeeds, as allowed by the previously configured network rule.
257
+
258
+
```azurepowershell-interactive
253
259
# Connect to one VM and ping the other. It should not work, because the firewall should drop the traffic, since no rule for ICMP is configured
You can also verify Internet traffic. HTTP requests via the utility `curl` to the FQDN you allowed in the firewall policy (`ifconfig.co`) should work, but HTTP requests to any other destination should fail (in this example you test with `bing.com`):
265
+
You can also test Internet access through the firewall. HTTP requests using the `curl`utility to the allowed FQDN (`ifconfig.co`) should succeed, while requests to other destinations (such as `bing.com`) should be blocked by the firewall policy:
260
266
261
-
```azurepowershell
267
+
```azurepowershell-interactive
262
268
# This HTTP request should succeed, since it is allowed in an app rule in the AzFW, and return the public IP of the FW
The easiest way to verify the packets are dropped by the firewall is to check the logs. Since you configured the Azure Firewall to send logs to Azure Monitor, you can use the Kusto Query Language to retrieve the relevant logs from Azure Monitor:
274
+
To confirm that the firewall is dropping packets as expected, review the logs sent to Azure Monitor. Since Azure Firewall is configured to send diagnostic logs to Azure Monitor, you can use Kusto Query Language (KQL) to query and analyze the relevant log entries:
269
275
270
276
> [!NOTE]
271
277
> It can take around 1 minute for the logs to appear to be sent to Azure Monitor
@@ -314,9 +320,7 @@ TimeGenerated Protocol SourceIP SourcePort TargetIP Tar
314
320
If you want to see the logs for the application rules (describing allowed and denied HTTP connections) or change the way that the logs are displayed, you can try with other KQL queries. You can find some examples in [Azure Monitor logs for Azure Firewall](../firewall/firewall-workbook.md).
315
321
316
322
317
-
## Clean up resources
318
-
319
-
To delete the test environment, you can remove the resource group with all contained objects:
323
+
To clean up the test environment, delete the resource group and all associated resources by using the `Remove-AzResourceGroup` cmdlet. This will remove the Virtual WAN, Virtual Hub, Azure Firewall, and any other resources created during this tutorial.
320
324
321
325
```azurepowershell
322
326
# Delete resource group and all contained resources
## Deploy a new Azure Firewall with availability zones to an existing hub
327
331
328
-
The previous procedure uses Azure PowerShell to create a **new** Azure Virtual WAN Hub, and then immediately converts it to a Secured Hub using Azure Firewall.
329
-
A similar approach can be applied to an **existing** Azure Virtual WAN Hub. Firewall Manager can be also used for the conversion, but it isn't possible to deploy Azure Firewall across availability zones without a script-based approach.
330
-
You can use the following code snippet to convert an existing Azure Virtual WAN Hub to a Secured Hub, using an Azure Firewall deployed across all three availability zones.
332
+
The previous steps showed how to use Azure PowerShell to create a **new** Azure Virtual WAN Hub and secure it with Azure Firewall. You can also secure an **existing** Azure Virtual WAN Hub using a similar script-based approach. While Firewall Manager can convert a hub to a Secured Hub, it does not support deploying Azure Firewall across availability zones through the portal. To deploy Azure Firewall in all three availability zones, use the following PowerShell script to convert your existing Virtual WAN Hub to a Secured Hub.
331
333
332
334
> [!NOTE]
333
335
> This procedure deploys a new Azure Firewall. You can't upgrade an existing Azure Firewall without availability zones to one with availability zones. You must first delete the existing Azure Firewall in the hub and create it again using this procedure.
334
336
335
-
```azurepowershell
337
+
```azurepowershell-interactive
336
338
# Variable definition
337
339
$RG = "vwan-rg"
338
340
$Location = "westeurope"
@@ -364,7 +366,7 @@ After you run this script, availability zones should appear in the secured hub p
After the Azure Firewall is deployed, a configuration procedure must be completed as described in the previous *Deploy Azure Firewall and configure custom routing* section.
369
+
After deploying Azure Firewall, you must complete the configuration steps outlined in the earlier **Deploy Azure Firewall and configure custom routing** section to ensure proper routing and security.
0 commit comments