Skip to content

Commit 3ca1570

Browse files
committed
start firewall cli article
1 parent 410b6cc commit 3ca1570

File tree

1 file changed

+299
-0
lines changed

1 file changed

+299
-0
lines changed

articles/firewall/deploy-cli.md

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
---
2+
title: 'Deploy and configure Azure Firewall using Azure CLI'
3+
description: In this article, you learn how to deploy and configure Azure Firewall using the Azure CLI.
4+
services: firewall
5+
author: vhorne
6+
ms.service: firewall
7+
ms.date: 5/9/2019
8+
ms.author: victorh
9+
#Customer intent: As an administrator new to this service, I want to control outbound network access from resources located in an Azure subnet.
10+
---
11+
12+
# Deploy and configure Azure Firewall using Azure CLI
13+
14+
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.
15+
16+
One way you can control outbound network access from an Azure subnet is with Azure Firewall. With Azure Firewall, you can configure:
17+
18+
* Application rules that define fully qualified domain names (FQDNs) that can be accessed from a subnet.
19+
* Network rules that define source address, protocol, destination port, and destination address.
20+
21+
Network traffic is subjected to the configured firewall rules when you route your network traffic to the firewall as the subnet default gateway.
22+
23+
For this article, you create a simplified single VNet with three subnets for easy deployment. For production deployments, a [hub and spoke model](https://docs.microsoft.com/azure/architecture/reference-architectures/hybrid-networking/hub-spoke) is recommended, where the firewall is in its own VNet. The workload servers are in peered VNets in the same region with one or more subnets.
24+
25+
* **AzureFirewallSubnet** - the firewall is in this subnet.
26+
* **Workload-SN** - the workload server is in this subnet. This subnet's network traffic goes through the firewall.
27+
* **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.
28+
29+
![Tutorial network infrastructure](media/tutorial-firewall-rules-portal/Tutorial_network.png)
30+
31+
In this article, you learn how to:
32+
33+
> [!div class="checklist"]
34+
> * Set up a test network environment
35+
> * Deploy a firewall
36+
> * Create a default route
37+
> * Configure an application rule to allow access to www.google.com
38+
> * Configure a network rule to allow access to external DNS servers
39+
> * Test the firewall
40+
41+
If you prefer, you can complete this procedure using the [Azure portal](tutorial-firewall-deploy-portal.md) or [Azure PowerShell](deploy-ps.md).
42+
43+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
44+
45+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
46+
47+
## Prerequisites
48+
49+
### Azure CLI
50+
51+
If you choose to install and use the CLI locally, run Azure CLI version 2.0.4 or later. To find the version, run **az --version**. For information about installing or upgrading, see [Install Azure CLI]( /cli/azure/install-azure-cli).
52+
53+
## Set up the network
54+
55+
First, create a resource group to contain the resources needed to deploy the firewall. Then create a VNet, subnets, and test servers.
56+
57+
### Create a resource group
58+
59+
The resource group contains all the resources for the deployment.
60+
61+
```azurecli-interactive
62+
az group create --name Test-FW-RG --location eastus
63+
```
64+
65+
### Create a VNet
66+
67+
This virtual network has three subnets.
68+
69+
> [!NOTE]
70+
> The minimum size of the AzureFirewallSubnet subnet is /26.
71+
72+
```azurecli-interactive
73+
az network vnet create \
74+
--name Test-FW-VN \
75+
--resource-group Test-FW-RG \
76+
--location eastus \
77+
--address-prefix 10.0.0.0/16 \
78+
--subnet-name AzureFirewallSubnet \
79+
--subnet-prefix 10.0.1.0/24
80+
az network vnet subnet create \
81+
--name Workload-SN \
82+
--resource-group Test-FW-RG \
83+
--vnet-name Test-FW-VN \
84+
--address-prefix 10.0.2.0/24
85+
az network vnet subnet create \
86+
--name Jump-SN \
87+
--resource-group Test-FW-RG \
88+
--vnet-name Test-FW-VN \
89+
--address-prefix 10.0.3.0/24
90+
```
91+
92+
### Create virtual machines
93+
94+
Now create the jump and workload virtual machines, and place them in the appropriate subnets.
95+
When prompted, type a password for the virtual machine.
96+
97+
Create the Srv-Jump virtual machine.
98+
99+
```azurecli-interactive
100+
az vm create \
101+
--resource-group Test-FW-RG \
102+
--name Srv-Jump \
103+
--location eastus \
104+
--image win2016datacenter \
105+
--vnet-name Test-FW-VN \
106+
--subnet Jump-SN \
107+
--admin-username azureadmin
108+
az vm open-port --port 3389 --resource-group Test-FW-RG --name Srv-Jump
109+
```
110+
111+
Create a workload virtual machine with no public IP address.
112+
When prompted, type a password for the virtual machine.
113+
114+
```azurecli-interactive
115+
az vm create \
116+
--resource-group Test-FW-RG \
117+
--name Srv-Work \
118+
--location eastus \
119+
--image win2016datacenter \
120+
--vnet-name Test-FW-VN \
121+
--subnet Workload-SN \
122+
--public-ip-address "" \
123+
--admin-username azureadmin
124+
```
125+
126+
## Deploy the firewall
127+
128+
Now deploy the firewall into the virtual network.
129+
130+
```azurecli-interactive
131+
az network firewall create \
132+
--name Test-FW01 \
133+
--resource-group Test-FW-RG \
134+
--location eastus
135+
az network public-ip create \
136+
--name fw-pip \
137+
--resource-group Test-FW-RG \
138+
--location eastus \
139+
--allocation-method static \
140+
--sku standard
141+
az network firewall ip-config create \
142+
--firewall-name Test-FW01 \
143+
--name FW-config \
144+
--public-ip-address fw-pip \
145+
--resource-group Test-FW-RG \
146+
--vnet-name Test-FW-VN
147+
az network firewall update \
148+
--name Test-FW01 \
149+
--resource-group Test-FW-RG \
150+
az network public-ip show \
151+
--name fw-pip \
152+
--resource-group Test-FW-RG
153+
fwpipaddr="$(az network public-ip list -g Test-FW-RG --query "[?name=='fw-pip'].ipAddress" --output tsv)"
154+
```
155+
156+
Note the private IP address. You'll use it later when you create the default route.
157+
158+
## Create a default route
159+
160+
Create a table, with BGP route propagation disabled
161+
162+
```azurecli-interactive
163+
az network route-table create \
164+
--name Firewall-rt-table \
165+
--resource-group Test-FW-RG \
166+
--location eastus \
167+
--disable-bgp-route-propagation true
168+
```
169+
170+
Create the route.
171+
172+
```azurecli-interactive
173+
az network route-table route create \
174+
--resource-group Test-FW-RG \
175+
--name DG-Route \
176+
--route-table-name Firewall-rt-table \
177+
--address-prefix 0.0.0.0/0 \
178+
--next-hop-type VirtualAppliance \
179+
--next-hop-ip-address $fwpipaddr
180+
```
181+
182+
Associate the route table to the subnet
183+
184+
```azurecli-interactive
185+
az network vnet subnet update \
186+
-n Workload-SN \
187+
-g Test-FW-RG \
188+
--vnet-name Test-FW-VN \
189+
--address-prefixes 10.0.2.0/24 \
190+
--route-table Firewall-rt-table
191+
```
192+
193+
## Configure an application rule
194+
195+
The application rule allows outbound access to www.google.com.
196+
197+
```azurecli-interactive
198+
az network firewall application-rule create \
199+
--collection-name App-Coll01 \
200+
--firewall-name Test-FW01 \
201+
--name Allow-Google \
202+
--protocols Http=80 Https=443 \
203+
--resource-group Test-FW-RG \
204+
--target-fqdns www.google.com \
205+
--source-addresses 10.0.2.0/24 \
206+
--priority 200 \
207+
--action Allow
208+
```
209+
210+
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).
211+
212+
## Configure a network rule
213+
214+
The network rule allows outbound access to two IP addresses at port 53 (DNS).
215+
216+
```azurecli-interactive
217+
az network firewall network-rule create \
218+
--collection-name RCNet01 \
219+
--destination-addresses 209.244.0.3 209.244.0.4 \
220+
--destination-ports 53 \
221+
--firewall-name Test-FW01 \
222+
--name Allow-DNS \
223+
--protocols UDP \
224+
--resource-group Test-FW-RG \
225+
--source-addresses 10.0.2.0/24 \
226+
--action Allow
227+
```
228+
229+
```azurepowershell
230+
$NetRule1 = New-AzFirewallNetworkRule -Name "Allow-DNS" -Protocol UDP -SourceAddress 10.0.2.0/24 `
231+
-DestinationAddress 209.244.0.3,209.244.0.4 -DestinationPort 53
232+
233+
$NetRuleCollection = New-AzFirewallNetworkRuleCollection -Name RCNet01 -Priority 200 `
234+
-Rule $NetRule1 -ActionType "Allow"
235+
236+
$Azfw.NetworkRuleCollections = $NetRuleCollection
237+
238+
Set-AzFirewall -AzureFirewall $Azfw
239+
```
240+
241+
### Change the primary and secondary DNS address for the **Srv-Work** network interface
242+
243+
For testing purposes in this procedure, configure the server's primary and secondary DNS addresses. This isn't a general Azure Firewall requirement.
244+
245+
```azurepowershell
246+
$NIC.DnsSettings.DnsServers.Add("209.244.0.3")
247+
$NIC.DnsSettings.DnsServers.Add("209.244.0.4")
248+
$NIC | Set-AzNetworkInterface
249+
```
250+
251+
## Test the firewall
252+
253+
Now, test the firewall to confirm that it works as expected.
254+
255+
1. Note the private IP address for the **Srv-Work** virtual machine:
256+
257+
```
258+
$NIC.IpConfigurations.PrivateIpAddress
259+
```
260+
261+
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.
262+
263+
3. On **SRV-Work**, open a PowerShell window and run the following commands:
264+
265+
```
266+
nslookup www.google.com
267+
nslookup www.microsoft.com
268+
```
269+
270+
Both commands should return answers, showing that your DNS queries are getting through the firewall.
271+
272+
1. Run the following commands:
273+
274+
```
275+
Invoke-WebRequest -Uri https://www.google.com
276+
Invoke-WebRequest -Uri https://www.google.com
277+
278+
Invoke-WebRequest -Uri https://www.microsoft.com
279+
Invoke-WebRequest -Uri https://www.microsoft.com
280+
```
281+
282+
The www.google.com requests should succeed, and the www.microsoft.com requests should fail. This demonstrates that your firewall rules are operating as expected.
283+
284+
So now you've verified that the firewall rules are working:
285+
286+
* You can resolve DNS names using the configured external DNS server.
287+
* You can browse to the one allowed FQDN, but not to any others.
288+
289+
## Clean up resources
290+
291+
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:
292+
293+
```azurepowershell
294+
Remove-AzResourceGroup -Name Test-FW-RG
295+
```
296+
297+
## Next steps
298+
299+
* [Tutorial: Monitor Azure Firewall logs](./tutorial-diagnostics.md)

0 commit comments

Comments
 (0)