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
description: Configure Azure firewall and user-defined routes for Azure Container Instances workloads that use the firewall's public IP address for ingress and egress
4
4
ms.topic: article
5
-
ms.date: 07/16/2020
5
+
ms.date: 05/03/2022
6
6
---
7
7
8
8
# Configure a single public IP address for outbound and inbound traffic to a container group
@@ -11,127 +11,80 @@ Setting up a [container group](container-instances-container-groups.md) with an
11
11
12
12
This article provides steps to configure a container group in a [virtual network](container-instances-virtual-network-concepts.md) integrated with [Azure Firewall](../firewall/overview.md). By setting up a user-defined route to the container group and firewall rules, you can route and identify traffic to and from the container group. Container group ingress and egress use the public IP address of the firewall. A single egress IP address can be used by multiple container groups deployed in the virtual network's subnet delegated to Azure Container Instances.
13
13
14
-
In this article you use the Azure CLI to create the resources for this scenario:
14
+
In this article, you use the Azure CLI to create the resources for this scenario:
15
15
16
-
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
16
+
* Container groups deployed on a delegated subnet [in the virtual network](container-instances-vnet.md)
17
17
* An Azure firewall deployed in the network with a static public IP address
18
18
* A user-defined route on the container groups' subnet
19
19
* A NAT rule for firewall ingress and an application rule for egress
20
20
21
21
You then validate ingress and egress from example container groups through the firewall.
In a typical case, you might already have an Azure virtual network in which to deploy a container group. For demonstration purposes, the following commands create a virtual network and subnet when the container group is created. The subnet is delegated to Azure Container Instances.
The container group runs a small web app from the `aci-helloworld` image. As shown in other articles in the documentation, this image packages a small web app written in Node.js that serves a static HTML page.
If you need one, first create an Azure resource group with the [az group create][az-group-create] command. For example:
29
+
> [!NOTE]
30
+
> To download the complete script, go to [full script](https://github.com/Azure-Samples/azure-cli-samples/blob/master/container-instances/egress-ip-address.sh).
30
31
31
-
```azurecli
32
-
az group create --name myResourceGroup --location eastus
33
-
```
32
+
## Get started
34
33
35
-
To simplify the following command examples, use an environment variable for the resource group's name:
34
+
This tutorial makes use of a randomized variable. If you are using an existing resource group, modify the value of this variable appropriately.
**Azure resource group**: If you don't have an Azure resource group already, create a resource group with the [az group create][az-group-create] command. Modify the location value as appropriate.
In a typical case, you might already have an Azure virtual network in which to deploy a container group. For demonstration purposes, the following commands create a virtual network and subnet when the container group is created. The subnet is delegated to Azure Container Instances.
45
+
46
+
The container group runs a small web app from the `aci-helloworld` image. As shown in other articles in the documentation, this image packages a small web app written in Node.js that serves a static HTML page.
40
47
41
48
Create the container group with the [az container create][az-container-create] command:
> Adjust the value of `--subnet address-prefix` for the IP address space you need in your subnet. The smallest supported subnet is /29, which provides eight IP addresses. Some IP addresses are reserved for use by Azure.
56
54
57
55
For use in a later step, get the private IP address of the container group by running the [az container show][az-container-show] command:
58
56
59
-
```azurecli
60
-
ACI_PRIVATE_IP="$(az container show --name appcontainer \
In the following sections, use the Azure CLI to deploy an Azure firewall in the virtual network. For background, see [Tutorial: Deploy and configure Azure Firewall using the Azure portal](../firewall/deploy-cli.md).
68
62
69
63
First, use the [az network vnet subnet create][az-network-vnet-subnet-create] to add a subnet named AzureFirewallSubnet for the firewall. AzureFirewallSubnet is the *required* name of this subnet.
Get the firewall's private IP address using the [az network firewall ip-config list][az-network-firewall-ip-config-list] command. This private IP address is used in a later command.
FW_PRIVATE_IP="$(az network firewall ip-config list \
123
-
--resource-group $RESOURCE_GROUP_NAME \
124
-
--firewall-name myFirewall \
125
-
--query "[].privateIpAddress" --output tsv)"
126
-
```
127
85
Get the firewall's public IP address using the [az network public-ip show][az-network-public-ip-show] command. This public IP address is used in a later command.
@@ -141,97 +94,49 @@ Define a use-defined route on the ACI subnet, to divert traffic to the Azure fir
141
94
142
95
First, run the following [az network route-table create][az-network-route-table-create] command to create the route table. Create the route table in the same region as the virtual network.
Run [az network-route-table route create][az-network-route-table-route-create] to create a route in the route table. To route traffic to the firewall, set the next hop type to `VirtualAppliance`, and pass the firewall's private IP address as the next hop address.
Run the [az network vnet subnet update][az-network-vnet-subnet-update] command to associate the route table with the subnet delegated to Azure Container Instances.
By default, Azure Firewall denies (blocks) inbound and outbound traffic.
113
+
By default, Azure Firewall denies (blocks) inbound and outbound traffic.
182
114
183
115
### Configure NAT rule on firewall to ACI subnet
184
116
185
117
Create a [NAT rule](../firewall/rule-processing.md) on the firewall to translate and filter inbound internet traffic to the application container you started previously in the network. For details, see [Filter inbound Internet traffic with Azure Firewall DNAT](../firewall/tutorial-firewall-dnat.md)
186
118
187
119
Create a NAT rule and collection by using the [az network firewall nat-rule create][az-network-firewall-nat-rule-create] command:
Add NAT rules as needed to filter traffic to other IP addresses in the subnet. For example, other container groups in the subnet could expose IP addresses for inbound traffic, or other internal IP addresses could be assigned to the container group after a restart.
206
124
207
125
### Create outbound application rule on the firewall
208
126
209
127
Run the following [az network firewall application-rule create][az-network-firewall-application-rule-create] command to create an outbound rule on the firewall. This sample rule allows access from the subnet delegated to Azure Container Instances to the FQDN `checkip.dyndns.org`. HTTP access to the site is used in a later step to confirm the egress IP address from Azure Container Instances.
## Test container group access through the firewall
225
132
226
133
The following sections verify that the subnet delegated to Azure Container Instances is properly configured behind the Azure firewall. The previous steps routed both incoming traffic to the subnet and outgoing traffic from the subnet through the firewall.
227
134
228
135
### Test ingress to a container group
229
136
230
-
Test inbound access to the *appcontainer* running in the virtual network by browsing to the firewall's public IP address. Previously, you stored the public IP address in variable $FW_PUBLIC_IP:
137
+
Test inbound access to the `appcontainer` running in the virtual network by browsing to the firewall's public IP address. Previously, you stored the public IP address in variable $FW_PUBLIC_IP:
@@ -245,19 +150,9 @@ If the NAT rule on the firewall is configured properly, you see the following wh
245
150
246
151
### Test egress from a container group
247
152
248
-
249
153
Deploy the following sample container into the virtual network. When it runs, it sends a single HTTP request to `http://checkip.dyndns.org`, which displays the IP address of the sender (the egress IP address). If the application rule on the firewall is configured properly, the firewall's public IP address is returned.
View the container logs to confirm the IP address is the same as the public IP address of the firewall.
263
158
@@ -273,14 +168,20 @@ Output is similar to:
273
168
<html><head><title>Current IP Check</title></head><body>Current IP Address: 52.142.18.133</body></html>
274
169
```
275
170
171
+
## Clean up resources
172
+
173
+
When no longer needed, you can use [az group delete](/cli/azure/group) to remove the resource group and all related resources as follows. The `--no-wait` parameter returns control to the prompt without waiting for the operation to complete. The `--yes` parameter confirms that you wish to delete the resources without an additional prompt to do so.
174
+
175
+
```azurecli-interactive
176
+
az group delete --name $resourceGroup --yes --no-wait
177
+
```
178
+
276
179
## Next steps
277
180
278
181
In this article, you set up container groups in a virtual network behind an Azure firewall. You configured a user-defined route and NAT and application rules on the firewall. By using this configuration, you set up a single, static IP address for ingress and egress from Azure Container Instances.
279
182
280
183
For more information about managing traffic and protecting Azure resources, see the [Azure Firewall](../firewall/index.yml) documentation.
0 commit comments